refactor(storage): 将 storage 工具类导出名重命名为 storageUtil

- 将 utils/chromeStorage.ts 中的 storage 导出重命名为 storageUtil
- 更新 RoutePersistence.tsx 中的导入和引用以使用新名称
- 优化 recordUtils.tsx 中 chrome.downloads 的链式调用格式

使工具类的命名更加清晰,避免与全局 storage 概念混淆
This commit is contained in:
雨霖铃
2026-02-27 16:12:52 +08:00
parent 6d2b553ca4
commit f0bb1b21ab
3 changed files with 11 additions and 9 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
import { useLocation, useNavigate } from 'react-router-dom'; import { useLocation, useNavigate } from 'react-router-dom';
import { storage } from '@/utils/chromeStorage'; import { storageUtil } from '@/utils/chromeStorage';
const RoutePersistence = () => { const RoutePersistence = () => {
const location = useLocation(); const location = useLocation();
@@ -13,7 +13,7 @@ const RoutePersistence = () => {
if (isRestored.current) return; if (isRestored.current) return;
try { try {
const lastRoute = await storage.get('app/lastRoute'); const lastRoute = await storageUtil.get('app/lastRoute');
if (lastRoute && lastRoute !== '/' && location.pathname === '/') { if (lastRoute && lastRoute !== '/' && location.pathname === '/') {
navigate(lastRoute, { replace: true }); navigate(lastRoute, { replace: true });
@@ -32,7 +32,7 @@ const RoutePersistence = () => {
useEffect(() => { useEffect(() => {
const saveRoute = async () => { const saveRoute = async () => {
if (!isRestored.current) return; if (!isRestored.current) return;
await storage.set('app/lastRoute', location.pathname); await storageUtil.set('app/lastRoute', location.pathname);
console.log('保存路由', location.pathname); console.log('保存路由', location.pathname);
}; };
+1 -1
View File
@@ -40,4 +40,4 @@ class StorageUtils {
} }
} }
export const storage = new StorageUtils(); export const storageUtil = new StorageUtils();
+4 -2
View File
@@ -55,11 +55,13 @@ export const downloadHtmlInBackground = (events: unknown[]) => {
const blob = new Blob([htmlContent], { type: 'text/html' }); const blob = new Blob([htmlContent], { type: 'text/html' });
const reader = new FileReader(); const reader = new FileReader();
reader.onload = () => { reader.onload = () => {
chrome.downloads.download({ chrome.downloads
.download({
url: reader.result as string, url: reader.result as string,
filename: `replay-${Date.now()}.html`, filename: `replay-${Date.now()}.html`,
saveAs: true, saveAs: true,
}).then(r => console.log(r)); })
.then((r) => console.log(r));
}; };
reader.readAsDataURL(blob); reader.readAsDataURL(blob);
}; };