refactor: remove unused variables and imports, and internalize module-specific functions and interfaces.

This commit is contained in:
kuekhaoyang
2025-11-29 12:55:46 +08:00
parent cad70dfb92
commit 76ca595a98
6 changed files with 4 additions and 12 deletions
+1 -1
View File
@@ -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<Set<string>>(new Set());
const pathname = usePathname();
+1 -1
View File
@@ -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<string, CacheMetadata>();
-1
View File
@@ -21,7 +21,6 @@ export async function parseHLSManifest(src: string): Promise<Segment[]> {
const lines = manifestText.split('\n');
const segments: Segment[] = [];
const baseUrl = src.substring(0, src.lastIndexOf('/') + 1);
let currentSegmentDuration = 0;
let currentStartTime = 0;
+1 -2
View File
@@ -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;
}
});
-3
View File
@@ -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<Uint8Array>;
@@ -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) {
+1 -4
View File
@@ -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();
}
};