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)