From 76ca595a986a4f4969b25465c6564fa8443abb9f Mon Sep 17 00:00:00 2001 From: kuekhaoyang Date: Sat, 29 Nov 2025 12:55:46 +0800 Subject: [PATCH] refactor: remove unused variables and imports, and internalize module-specific functions and interfaces. --- lib/hooks/useHistoryDownloader.ts | 2 +- lib/utils/cacheManager.ts | 2 +- lib/utils/hlsManifestParser.ts | 1 - lib/utils/proxy-utils.ts | 3 +-- lib/utils/search-stream.ts | 3 --- lib/utils/segmentDownloader.ts | 5 +---- 6 files changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/hooks/useHistoryDownloader.ts b/lib/hooks/useHistoryDownloader.ts index 4b07717..e8e6562 100644 --- a/lib/hooks/useHistoryDownloader.ts +++ b/lib/hooks/useHistoryDownloader.ts @@ -11,7 +11,7 @@ import { useHistoryStore } from '@/lib/store/history-store'; import { parseHLSManifest } from '@/lib/utils/hlsManifestParser'; import { downloadSegmentQueue } from '@/lib/utils/segmentDownloader'; -export function useHistoryDownloader() { +function useHistoryDownloader() { const viewingHistory = useHistoryStore((state) => state.viewingHistory); const processedUrlsRef = useRef>(new Set()); const pathname = usePathname(); diff --git a/lib/utils/cacheManager.ts b/lib/utils/cacheManager.ts index bb875aa..0afc469 100644 --- a/lib/utils/cacheManager.ts +++ b/lib/utils/cacheManager.ts @@ -6,7 +6,7 @@ const MAX_CACHE_SIZE_MB = 1000; // 1GB interface CacheMetadata { url: string; videoUrl: string; cachedAt: number; size: number; lastAccessed: number; } -export interface CacheStats { totalEntries: number; totalSizeMB: number; oldestEntry: number; newestEntry: number; } +interface CacheStats { totalEntries: number; totalSizeMB: number; oldestEntry: number; newestEntry: number; } class CacheManager { private metadata = new Map(); diff --git a/lib/utils/hlsManifestParser.ts b/lib/utils/hlsManifestParser.ts index d0c77fb..490f947 100644 --- a/lib/utils/hlsManifestParser.ts +++ b/lib/utils/hlsManifestParser.ts @@ -21,7 +21,6 @@ export async function parseHLSManifest(src: string): Promise { const lines = manifestText.split('\n'); const segments: Segment[] = []; - const baseUrl = src.substring(0, src.lastIndexOf('/') + 1); let currentSegmentDuration = 0; let currentStartTime = 0; diff --git a/lib/utils/proxy-utils.ts b/lib/utils/proxy-utils.ts index cda4a6d..7dcd1a1 100644 --- a/lib/utils/proxy-utils.ts +++ b/lib/utils/proxy-utils.ts @@ -1,4 +1,3 @@ -import { NextRequest } from 'next/server'; export async function processM3u8Content( content: string, @@ -19,7 +18,7 @@ export async function processM3u8Content( const absoluteUrl = new URL(line.trim(), base).toString(); // Wrap in proxy return `${origin}/api/proxy?url=${encodeURIComponent(absoluteUrl)}`; - } catch (e) { + } catch { return line; } }); diff --git a/lib/utils/search-stream.ts b/lib/utils/search-stream.ts index 096dadf..9c14a87 100644 --- a/lib/utils/search-stream.ts +++ b/lib/utils/search-stream.ts @@ -1,7 +1,6 @@ import { Video } from '@/lib/types'; import { getSourceName } from '@/lib/utils/source-names'; import { calculateRelevanceScore, hasMinimumMatch } from '@/lib/utils/search'; -import { binaryInsertVideos } from '@/lib/utils/sorted-insert'; interface StreamHandlerParams { reader: ReadableStreamDefaultReader; @@ -24,14 +23,12 @@ export async function processSearchStream({ }: StreamHandlerParams) { const decoder = new TextDecoder(); let buffer = ''; - let lastProgressTime = Date.now(); let timeoutId: NodeJS.Timeout | null = null; let isCompleted = false; // Auto-complete if no progress for 3 seconds const resetTimeout = () => { if (timeoutId) clearTimeout(timeoutId); - lastProgressTime = Date.now(); timeoutId = setTimeout(() => { if (!isCompleted) { diff --git a/lib/utils/segmentDownloader.ts b/lib/utils/segmentDownloader.ts index 9dd4db0..68e323d 100644 --- a/lib/utils/segmentDownloader.ts +++ b/lib/utils/segmentDownloader.ts @@ -24,7 +24,6 @@ export async function downloadSegmentQueue(options: DownloadQueueOptions): Promi if (!('caches' in window)) return; const cache = await caches.open(CACHE_NAME); - let activeCount = 0; let currentIndex = startIndex; const processNext = async () => { @@ -33,7 +32,6 @@ export async function downloadSegmentQueue(options: DownloadQueueOptions): Promi const segment = segments[currentIndex]; const url = segment.url; currentIndex++; - activeCount++; const timeoutController = new AbortController(); const timeoutId = setTimeout(() => timeoutController.abort(), TIMEOUT_MS); @@ -72,11 +70,10 @@ export async function downloadSegmentQueue(options: DownloadQueueOptions): Promi } } } - } catch (err) { + } catch { // Ignore errors } finally { clearTimeout(timeoutId); - activeCount--; if (!signal.aborted) processNext(); } };