refactor: clean up unused code and simplify imports
- Remove unused imports and variables across 35 files - Simplify component logic and remove dead code - Clean up test files by removing unnecessary setup - Streamline CI workflow configuration Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -4,27 +4,15 @@ import { decodeBase64Url, parseJwt } from '@/utils/jwt';
|
||||
describe('jwt utils', () => {
|
||||
describe('decodeBase64Url', () => {
|
||||
it('should decode standard base64url', () => {
|
||||
// "test" -> "dGVzdA"
|
||||
expect(decodeBase64Url('dGVzdA')).toBe('test');
|
||||
});
|
||||
|
||||
it('should handle padding correctly', () => {
|
||||
// "a" -> "YQ" (needs ==)
|
||||
expect(decodeBase64Url('YQ')).toBe('a');
|
||||
// "ab" -> "YWI" (needs =)
|
||||
expect(decodeBase64Url('YWI')).toBe('ab');
|
||||
});
|
||||
|
||||
it('should handle - and _ correctly', () => {
|
||||
// Validating base64url specific chars
|
||||
// standard base64 of binary 0xFF 0xEF is "/+8="
|
||||
// base64url should be "_-8"
|
||||
// Wait, let's use a simpler one.
|
||||
// 0xFB 0xFF -> "+/8=" in base64, "-_8=" in base64url? No.
|
||||
// + -> -
|
||||
// / -> _
|
||||
// let's try to encode something that results in + and /
|
||||
// binary 0xFB 0xFF 0xBE -> "+/++" in base64 -> "-_--" in base64url
|
||||
expect(decodeBase64Url('-_--')).toBeDefined();
|
||||
});
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ describe('useStorageState', () => {
|
||||
await waitFor(() => {
|
||||
// 异步加载后应覆盖为存储值
|
||||
expect(result.current[0]).toBe(false);
|
||||
expect(result.current[2]).toBe(true); // isInitialized
|
||||
expect(result.current[2]).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('useStorageState', () => {
|
||||
const { result } = renderHook(() => useStorageState('qrCode/urlExpanded', true));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current[2]).toBe(true); // isInitialized
|
||||
expect(result.current[2]).toBe(true);
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
@@ -77,7 +77,6 @@ describe('useStorageState', () => {
|
||||
expect(result.current[0]).toBe(false);
|
||||
expect(storageUtil.set).toHaveBeenCalledWith('qrCode/urlExpanded', false);
|
||||
|
||||
// 应同时写入 localStorage 快照
|
||||
expect(localStorage.getItem('snapshot/qrCode/urlExpanded')).toBe(JSON.stringify(false));
|
||||
});
|
||||
|
||||
|
||||
@@ -59,13 +59,9 @@ export async function ensureContentScriptInjected(): Promise<boolean> {
|
||||
const tab = await getActiveTab();
|
||||
if (!tab?.id) return false;
|
||||
|
||||
// 尝试发送一个简单的探测消息
|
||||
try {
|
||||
// 这里可以根据实际情况发送一个简单的 Ping 消息
|
||||
// 目前暂时保留原有注入逻辑,由调用方决定
|
||||
return true;
|
||||
} catch (e) {
|
||||
// 如果报错,说明没注入,执行注入
|
||||
console.log('内容脚本未注入,尝试注入...');
|
||||
console.error('注入内容脚本失败:', e);
|
||||
await chrome.scripting.executeScript({
|
||||
|
||||
@@ -12,9 +12,6 @@ export interface QrCodeParseResult {
|
||||
*/
|
||||
export async function parseQrCodeFromFile(file: File): Promise<QrCodeParseResult> {
|
||||
try {
|
||||
// qr-scanner 的 scanImage 方法支持直接传入 File 对象
|
||||
// 它会自动处理图片加载、Canvas 绘制和解析过程
|
||||
// 并且在支持的浏览器中会优先使用原生的 BarcodeDetector API
|
||||
const result = await QrScanner.scanImage(file, {
|
||||
returnDetailedScanResult: true,
|
||||
});
|
||||
@@ -25,7 +22,6 @@ export async function parseQrCodeFromFile(file: File): Promise<QrCodeParseResult
|
||||
return { success: false, error: '未检测到二维码' };
|
||||
}
|
||||
} catch (err) {
|
||||
// qr-scanner 在未发现二维码时会抛出 "No QR code found"
|
||||
const errorMsg =
|
||||
err === 'No QR code found'
|
||||
? '未检测到二维码'
|
||||
|
||||
@@ -111,8 +111,6 @@ export async function getOriginStorageEstimate(tabId: number): Promise<number> {
|
||||
target: { tabId },
|
||||
func: async () => {
|
||||
try {
|
||||
// 注意:navigator.storage.estimate() 返回的是整个 Origin 的估算值
|
||||
// 包含 IndexedDB, CacheStorage, ServiceWorker 注册等
|
||||
if (navigator.storage && navigator.storage.estimate) {
|
||||
const estimate = await navigator.storage.estimate();
|
||||
return estimate.usage || 0;
|
||||
@@ -138,7 +136,7 @@ export async function getCacheStorageSize(tabId: number): Promise<number> {
|
||||
try {
|
||||
if ('caches' in window) {
|
||||
const keys = await caches.keys();
|
||||
return keys.length; // 对于 CacheStorage,我们先返回缓存库的数量
|
||||
return keys.length;
|
||||
}
|
||||
return 0;
|
||||
} catch {
|
||||
@@ -146,7 +144,6 @@ export async function getCacheStorageSize(tabId: number): Promise<number> {
|
||||
}
|
||||
},
|
||||
});
|
||||
// 由于获取具体字节数较慢,这里返回的是缓存条目的数量标识,UI 上可以特殊处理
|
||||
return (result?.result as number) || 0;
|
||||
} catch (error) {
|
||||
console.error('Failed to get CacheStorage size:', error);
|
||||
|
||||
Reference in New Issue
Block a user