Ensure video titles and metadata reflect database edits
Update video fetching logic to merge database edits with CDN content, fixing issues with displayed titles and ensuring data consistency across the platform. 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/DVlzRoR
This commit is contained in:
+50
-5
@@ -220,13 +220,13 @@ class VideoSyncService {
|
||||
console.log('📅 Scheduled video sync every 5 minutes for optimal performance');
|
||||
}
|
||||
|
||||
getVideos(limit: number = 20, offset: number = 0, search?: string) {
|
||||
let filteredVideos = this.cache.videos;
|
||||
async getVideos(limit: number = 20, offset: number = 0, search?: string) {
|
||||
let filteredVideos = await this.mergeWithDatabaseEdits(this.cache.videos);
|
||||
|
||||
// Fast client-side search
|
||||
if (search && search.length >= 2) {
|
||||
const searchLower = search.toLowerCase();
|
||||
filteredVideos = this.cache.videos.filter(video =>
|
||||
filteredVideos = filteredVideos.filter(video =>
|
||||
video.title.toLowerCase().includes(searchLower) ||
|
||||
video.description?.toLowerCase().includes(searchLower)
|
||||
);
|
||||
@@ -242,15 +242,60 @@ class VideoSyncService {
|
||||
};
|
||||
}
|
||||
|
||||
private async mergeWithDatabaseEdits(bunnyVideos: any[]) {
|
||||
try {
|
||||
// Fetch all edited videos from database
|
||||
const dbVideos = await db.select().from(videos);
|
||||
const dbVideoMap = new Map(dbVideos.map(v => [v.id, v]));
|
||||
|
||||
// Merge Bunny.net data with database edits
|
||||
return bunnyVideos.map(bunnyVideo => {
|
||||
const dbVideo = dbVideoMap.get(bunnyVideo.id);
|
||||
if (dbVideo) {
|
||||
// Database has edited version - use edited metadata but keep Bunny.net URLs
|
||||
return {
|
||||
...bunnyVideo,
|
||||
title: dbVideo.title,
|
||||
description: dbVideo.description,
|
||||
category: dbVideo.category,
|
||||
tags: dbVideo.tags || [],
|
||||
customThumbnailUrl: dbVideo.customThumbnailUrl,
|
||||
isPublic: dbVideo.isPublic,
|
||||
updatedAt: dbVideo.updatedAt
|
||||
};
|
||||
}
|
||||
return bunnyVideo; // No database edits - use original Bunny.net data
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('Failed to merge database edits, using Bunny.net data only:', error);
|
||||
return bunnyVideos;
|
||||
}
|
||||
}
|
||||
|
||||
async getVideo(id: string) {
|
||||
// First try cache
|
||||
const cachedVideo = this.cache.videos.find(v => v.id === id);
|
||||
if (cachedVideo) {
|
||||
return cachedVideo;
|
||||
// Merge with database edits
|
||||
const mergedVideos = await this.mergeWithDatabaseEdits([cachedVideo]);
|
||||
return mergedVideos[0];
|
||||
}
|
||||
|
||||
// Fallback to direct API call
|
||||
return await this.bunnyService.getVideo(id);
|
||||
const bunnyVideo = await this.bunnyService.getVideo(id);
|
||||
if (bunnyVideo) {
|
||||
const mergedVideos = await this.mergeWithDatabaseEdits([bunnyVideo]);
|
||||
return mergedVideos[0];
|
||||
}
|
||||
return bunnyVideo;
|
||||
}
|
||||
|
||||
forceVideoRefresh(videoId: string) {
|
||||
console.log(`🔄 Forcing refresh for video ${videoId}`);
|
||||
// Remove video from cache to force fresh fetch
|
||||
this.cache.videos = this.cache.videos.filter(v => v.id !== videoId);
|
||||
// Mark cache as needing update
|
||||
this.cache.lastUpdate = 0;
|
||||
}
|
||||
|
||||
getCacheStats() {
|
||||
|
||||
Reference in New Issue
Block a user