diff --git a/worker/video-server-enhanced.js b/worker/video-server-enhanced.js index e1bdaad..56d0d81 100644 --- a/worker/video-server-enhanced.js +++ b/worker/video-server-enhanced.js @@ -347,8 +347,15 @@ async function handlePublicList(bucket, kv, corsHeaders) { }) ); - // Filter to only shareable videos - const shareableVideos = videos.filter(v => v.visibility === 'shareable'); + // Filter to only shareable videos and exclude small/test files + const validVideoExtensions = ['.mp4', '.mkv', '.mov', '.avi', '.webm', '.flv', '.wmv']; + const shareableVideos = videos.filter(v => { + if (v.visibility !== 'shareable') return false; + if (v.name.startsWith('live/')) return false; + if (v.size < 1024) return false; // Exclude files smaller than 1KB + const ext = v.name.substring(v.name.lastIndexOf('.')).toLowerCase(); + return validVideoExtensions.includes(ext); + }); return new Response(JSON.stringify({ count: shareableVideos.length, videos: shareableVideos }), { headers: { 'Content-Type': 'application/json', ...corsHeaders } @@ -502,7 +509,7 @@ async function handlePublicGallery(bucket, kv, corsHeaders) { // Filter to only shareable videos AND exclude HLS live stream files const validVideoExtensions = ['.mp4', '.mkv', '.mov', '.avi', '.webm', '.flv', '.wmv']; - const shareableVideos = videos.filter(v => { + const candidateVideos = videos.filter(v => { // Must be shareable if (v.visibility !== 'shareable') return false; @@ -511,9 +518,28 @@ async function handlePublicGallery(bucket, kv, corsHeaders) { // Only include actual video files (not HLS chunks) const ext = v.key.substring(v.key.lastIndexOf('.')).toLowerCase(); + + // Filter out test files and files that are too small to be real videos (< 1KB) + if (v.size < 1024) return false; + return validVideoExtensions.includes(ext); }); + // Verify each video actually exists and is accessible by trying to read first byte + const shareableVideos = []; + for (const video of candidateVideos) { + try { + // Try to actually fetch the first 1 byte to verify the video exists + const testObject = await bucket.get(video.key, { range: { offset: 0, length: 1 } }); + if (testObject && testObject.body) { + shareableVideos.push(video); + } + } catch (e) { + // Video doesn't exist or isn't accessible, skip it + console.log(`Skipping inaccessible video: ${video.key}`); + } + } + const videoItems = shareableVideos .map(obj => { const sizeInMB = (obj.size / (1024 * 1024)).toFixed(2); @@ -522,8 +548,8 @@ async function handlePublicGallery(bucket, kv, corsHeaders) { return `
-
-
`;