From f0bb1b21abe36bce97bd124170d11e3bc48dd787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E9=9C=96=E9=93=83?= Date: Fri, 27 Feb 2026 16:12:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor(storage):=20=E5=B0=86=20storage=20?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=E5=AF=BC=E5=87=BA=E5=90=8D=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E4=B8=BA=20storageUtil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 utils/chromeStorage.ts 中的 storage 导出重命名为 storageUtil - 更新 RoutePersistence.tsx 中的导入和引用以使用新名称 - 优化 recordUtils.tsx 中 chrome.downloads 的链式调用格式 使工具类的命名更加清晰,避免与全局 storage 概念混淆 --- components/RoutePersistence.tsx | 6 +++--- utils/chromeStorage.ts | 2 +- utils/recordUtils.tsx | 12 +++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/components/RoutePersistence.tsx b/components/RoutePersistence.tsx index a765ec9..318282b 100644 --- a/components/RoutePersistence.tsx +++ b/components/RoutePersistence.tsx @@ -1,6 +1,6 @@ import { useEffect, useRef } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; -import { storage } from '@/utils/chromeStorage'; +import { storageUtil } from '@/utils/chromeStorage'; const RoutePersistence = () => { const location = useLocation(); @@ -13,7 +13,7 @@ const RoutePersistence = () => { if (isRestored.current) return; try { - const lastRoute = await storage.get('app/lastRoute'); + const lastRoute = await storageUtil.get('app/lastRoute'); if (lastRoute && lastRoute !== '/' && location.pathname === '/') { navigate(lastRoute, { replace: true }); @@ -32,7 +32,7 @@ const RoutePersistence = () => { useEffect(() => { const saveRoute = async () => { if (!isRestored.current) return; - await storage.set('app/lastRoute', location.pathname); + await storageUtil.set('app/lastRoute', location.pathname); console.log('保存路由', location.pathname); }; diff --git a/utils/chromeStorage.ts b/utils/chromeStorage.ts index be0ce2c..ae1154b 100644 --- a/utils/chromeStorage.ts +++ b/utils/chromeStorage.ts @@ -40,4 +40,4 @@ class StorageUtils { } } -export const storage = new StorageUtils(); +export const storageUtil = new StorageUtils(); diff --git a/utils/recordUtils.tsx b/utils/recordUtils.tsx index b308575..08be169 100644 --- a/utils/recordUtils.tsx +++ b/utils/recordUtils.tsx @@ -55,11 +55,13 @@ export const downloadHtmlInBackground = (events: unknown[]) => { const blob = new Blob([htmlContent], { type: 'text/html' }); const reader = new FileReader(); reader.onload = () => { - chrome.downloads.download({ - url: reader.result as string, - filename: `replay-${Date.now()}.html`, - saveAs: true, - }).then(r => console.log(r)); + chrome.downloads + .download({ + url: reader.result as string, + filename: `replay-${Date.now()}.html`, + saveAs: true, + }) + .then((r) => console.log(r)); }; reader.readAsDataURL(blob); };