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
This commit is contained in:
parent
c5dd773a8b
commit
a6accad407
@ -360,20 +360,31 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
|
||||
// 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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user