Improve social media sharing with better video linking
Refactor server logic to support finding videos by short or long IDs and update meta tags for social sharing previews. 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:
+21
-28
@@ -20,6 +20,27 @@ import { setupAuth, isAuthenticated, isAdmin } from "./replitAuth";
|
||||
import { ObjectStorageService, ObjectNotFoundError } from "./objectStorage";
|
||||
import { generateVideoDescription, generateBulkDescriptions } from "./aiService";
|
||||
|
||||
// Find video by short or long ID - moved to top level for export
|
||||
export async function findVideoByAnyId(id: string) {
|
||||
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 an 8-character short ID, find by short ID
|
||||
if (id.length === 8) {
|
||||
const allVideos = await storage.getVideos(200, 0);
|
||||
return allVideos.find(v => v.id.replace(/-/g, '').substring(0, 8) === id);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
} catch (error) {
|
||||
console.error(`Error finding video by ID ${id}:`, error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// Extend express session
|
||||
declare module "express-session" {
|
||||
interface SessionData {
|
||||
@@ -358,34 +379,6 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
return longId.replace(/-/g, '').substring(0, 8);
|
||||
}
|
||||
|
||||
// Find video by short or long ID
|
||||
async function findVideoByAnyId(id: string) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Get single video by ID (supports both short and long IDs)
|
||||
app.get("/api/videos/:id", async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user