From a6accad407ec04fd33e2550da5090925fe8272dd Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Wed, 3 Sep 2025 12:10:35 +0000 Subject: [PATCH] Improve video searching to handle both short and long IDs Enhance the video retrieval logic to efficiently find videos using either their full UUID or an 8-character short ID, including error handling and type checks for robust operation. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1/gueMD9C --- server/routes.ts | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/server/routes.ts b/server/routes.ts index 82333e5..abe06af 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -360,20 +360,31 @@ export async function registerRoutes(app: Express): Promise { // Find video by short or long ID async function findVideoByAnyId(id: string) { - // If it's already a full UUID, use it directly - if (id.length === 36 && id.includes('-')) { + try { + // If it's already a full UUID, use it directly + if (id.length === 36 && id.includes('-')) { + return await storage.getVideo(id); + } + + // If it's a short ID (8 chars), search for matching video + if (id.length === 8) { + // HybridStorage calls BunnyStorage.getVideos() which returns Video[] + const allVideosArray = await storage.getVideos(200, 0); + + // This should be Video[] directly from BunnyStorage + if (Array.isArray(allVideosArray)) { + const video = allVideosArray.find(v => generateShortId(v.id) === id); + return video || null; + } + return video || null; + } + + // Try as full ID anyway return await storage.getVideo(id); + } catch (error) { + console.error('Error in findVideoByAnyId:', error); + return null; } - - // If it's a short ID (8 chars), search for matching video - if (id.length === 8) { - const allVideos = await storage.getVideos({ limit: 200, offset: 0 }); - const video = allVideos.videos.find(v => generateShortId(v.id) === id); - return video; - } - - // Try as full ID anyway - return await storage.getVideo(id); } // Get single video by ID (supports both short and long IDs)