mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-14 16:23:43 +08:00
refactor: Remove video verification logic and related properties from search and display components
This commit is contained in:
@@ -73,7 +73,6 @@ export async function POST(request: NextRequest) {
|
||||
type: 'videos',
|
||||
videos: videos.map((video: any) => ({
|
||||
...video,
|
||||
isVerifying: true, // Mark for verification
|
||||
sourceDisplayName: getSourceDisplayName(source.id),
|
||||
})),
|
||||
source: source.id,
|
||||
|
||||
@@ -15,7 +15,6 @@ interface Video {
|
||||
source: string;
|
||||
sourceName?: string;
|
||||
isNew?: boolean;
|
||||
isVerifying?: boolean;
|
||||
}
|
||||
|
||||
interface VideoGridProps {
|
||||
@@ -70,15 +69,6 @@ export function VideoGrid({ videos, className = '' }: VideoGridProps) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Verifying Badge - Top Right */}
|
||||
{video.isVerifying && (
|
||||
<div className="absolute top-2 right-2 z-10">
|
||||
<Badge variant="secondary" className="text-xs backdrop-blur-md bg-yellow-500/90 text-white animate-pulse">
|
||||
验证中
|
||||
</Badge>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Overlay */}
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300">
|
||||
<div className="absolute bottom-0 left-0 right-0 p-3">
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import { useState, useRef, useCallback } from 'react';
|
||||
import { getSourceName, SOURCE_IDS } from '@/lib/utils/source-names';
|
||||
import { checkVideoAvailability } from '@/lib/utils/source-checker';
|
||||
import { calculateRelevanceScore } from '@/lib/utils/search';
|
||||
|
||||
interface Video {
|
||||
@@ -15,7 +14,6 @@ interface Video {
|
||||
source: string;
|
||||
sourceName?: string;
|
||||
isNew?: boolean;
|
||||
isVerifying?: boolean;
|
||||
vod_play_url?: string;
|
||||
vod_actor?: string;
|
||||
vod_director?: string;
|
||||
@@ -47,106 +45,6 @@ export function useParallelSearch(
|
||||
const currentQueryRef = useRef<string>('');
|
||||
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
const verificationQueueRef = useRef<Video[]>([]);
|
||||
const verifyingCountRef = useRef(0);
|
||||
const allVideosReceivedRef = useRef(false);
|
||||
const MAX_CONCURRENT_VERIFICATIONS = 15;
|
||||
|
||||
/**
|
||||
* Process verification queue
|
||||
* Verifies videos in parallel with a max concurrency limit
|
||||
*/
|
||||
const processVerificationQueue = useCallback(async () => {
|
||||
while (verificationQueueRef.current.length > 0 && verifyingCountRef.current < MAX_CONCURRENT_VERIFICATIONS) {
|
||||
const video = verificationQueueRef.current.shift();
|
||||
if (!video) continue;
|
||||
|
||||
verifyingCountRef.current++;
|
||||
|
||||
// Verify in background
|
||||
checkVideoAvailability(video)
|
||||
.then((isValid) => {
|
||||
verifyingCountRef.current--;
|
||||
|
||||
setResults((prev) => {
|
||||
if (isValid) {
|
||||
// Remove verifying badge, maintain sort order
|
||||
const updated = prev.map((v) =>
|
||||
v.vod_id === video.vod_id && v.source === video.source
|
||||
? { ...v, isVerifying: false }
|
||||
: v
|
||||
);
|
||||
// Re-sort by relevance to maintain order
|
||||
return updated.sort((a, b) => (b.relevanceScore || 0) - (a.relevanceScore || 0));
|
||||
} else {
|
||||
// Remove invalid video
|
||||
const removedVideo = prev.find(
|
||||
(v) => v.vod_id === video.vod_id && v.source === video.source
|
||||
);
|
||||
|
||||
if (removedVideo && allVideosReceivedRef.current) {
|
||||
// Update source count when removing video after search is complete
|
||||
setAvailableSources((sources) =>
|
||||
sources.map((s) =>
|
||||
s.id === removedVideo.source
|
||||
? { ...s, count: Math.max(0, s.count - 1) }
|
||||
: s
|
||||
).filter(s => s.count > 0)
|
||||
);
|
||||
}
|
||||
|
||||
const filtered = prev.filter(
|
||||
(v) => !(v.vod_id === video.vod_id && v.source === video.source)
|
||||
);
|
||||
// Maintain sort order
|
||||
return filtered.sort((a, b) => (b.relevanceScore || 0) - (a.relevanceScore || 0));
|
||||
}
|
||||
});
|
||||
|
||||
// Continue processing queue
|
||||
processVerificationQueue();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Verification error:', error);
|
||||
verifyingCountRef.current--;
|
||||
|
||||
// Remove video on error
|
||||
setResults((prev) => {
|
||||
const removedVideo = prev.find(
|
||||
(v) => v.vod_id === video.vod_id && v.source === video.source
|
||||
);
|
||||
|
||||
if (removedVideo && allVideosReceivedRef.current) {
|
||||
// Update source count when removing video
|
||||
setAvailableSources((sources) =>
|
||||
sources.map((s) =>
|
||||
s.id === removedVideo.source
|
||||
? { ...s, count: Math.max(0, s.count - 1) }
|
||||
: s
|
||||
).filter(s => s.count > 0)
|
||||
);
|
||||
}
|
||||
|
||||
const filtered = prev.filter(
|
||||
(v) => !(v.vod_id === video.vod_id && v.source === video.source)
|
||||
);
|
||||
// Maintain sort order
|
||||
return filtered.sort((a, b) => (b.relevanceScore || 0) - (a.relevanceScore || 0));
|
||||
});
|
||||
|
||||
// Continue processing queue
|
||||
processVerificationQueue();
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Add videos to verification queue
|
||||
*/
|
||||
const queueVideosForVerification = useCallback((videos: Video[]) => {
|
||||
verificationQueueRef.current.push(...videos);
|
||||
processVerificationQueue();
|
||||
}, [processVerificationQueue]);
|
||||
|
||||
/**
|
||||
* Perform parallel search with streaming results
|
||||
@@ -167,9 +65,6 @@ export function useParallelSearch(
|
||||
setCompletedSources(0);
|
||||
setTotalSources(0);
|
||||
setTotalVideosFound(0);
|
||||
verificationQueueRef.current = [];
|
||||
verifyingCountRef.current = 0;
|
||||
allVideosReceivedRef.current = false;
|
||||
currentQueryRef.current = searchQuery.trim();
|
||||
|
||||
// Update URL
|
||||
@@ -216,7 +111,6 @@ export function useParallelSearch(
|
||||
...video,
|
||||
sourceName: video.sourceDisplayName || getSourceName(video.source),
|
||||
isNew: true,
|
||||
isVerifying: true, // All videos start as verifying
|
||||
relevanceScore: calculateRelevanceScore(video, currentQuery),
|
||||
}));
|
||||
|
||||
@@ -229,9 +123,6 @@ export function useParallelSearch(
|
||||
return combined.sort((a, b) => (b.relevanceScore || 0) - (a.relevanceScore || 0));
|
||||
});
|
||||
|
||||
// Queue videos for verification
|
||||
queueVideosForVerification(newVideos);
|
||||
|
||||
// Update source stats
|
||||
if (!sourcesMap.has(data.source)) {
|
||||
sourcesMap.set(data.source, {
|
||||
@@ -246,7 +137,6 @@ export function useParallelSearch(
|
||||
}
|
||||
else if (data.type === 'complete') {
|
||||
setLoading(false);
|
||||
allVideosReceivedRef.current = true;
|
||||
|
||||
console.log(`[useParallelSearch] Search complete: ${data.totalVideosFound} videos found`);
|
||||
console.log(`[useParallelSearch] Sources with videos: ${sourcesMap.size}`);
|
||||
@@ -286,7 +176,7 @@ export function useParallelSearch(
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
}, [loading, onUrlUpdate, onCacheUpdate, queueVideosForVerification]);
|
||||
}, [loading, onUrlUpdate, onCacheUpdate]);
|
||||
|
||||
/**
|
||||
* Reset search state
|
||||
@@ -301,9 +191,6 @@ export function useParallelSearch(
|
||||
setCompletedSources(0);
|
||||
setTotalSources(0);
|
||||
setTotalVideosFound(0);
|
||||
verificationQueueRef.current = [];
|
||||
verifyingCountRef.current = 0;
|
||||
allVideosReceivedRef.current = false;
|
||||
currentQueryRef.current = '';
|
||||
}, []);
|
||||
|
||||
@@ -315,7 +202,6 @@ export function useParallelSearch(
|
||||
setResults(cachedResults);
|
||||
setAvailableSources(cachedSources);
|
||||
setTotalVideosFound(cachedResults.length);
|
||||
allVideosReceivedRef.current = true;
|
||||
}, []);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user