Improve storage logic to support hybrid and CDN options
Refactor storage initialization to prioritize hybrid (Bunny.net + Database) storage, then Bunny.net only, falling back to Database or Memory storage. Remove debug logs from NetflixGrid component. 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/d05DGZF
This commit is contained in:
parent
06185bf445
commit
dec09b7b2f
@ -37,11 +37,7 @@ export default function NetflixGrid({ videos, isLoading }: NetflixGridProps) {
|
|||||||
|
|
||||||
// Memoize categories to avoid recalculation on every render
|
// Memoize categories to avoid recalculation on every render
|
||||||
const categories = useMemo((): VideoCategory[] => {
|
const categories = useMemo((): VideoCategory[] => {
|
||||||
console.log("NetflixGrid received videos:", videos.length, videos.slice(0, 2)); // Debug log
|
if (!videos.length) return [];
|
||||||
if (!videos.length) {
|
|
||||||
console.log("No videos to display"); // Debug log
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort by views for top content
|
// Sort by views for top content
|
||||||
const sortedByViews = [...videos].sort((a, b) => (b.views || 0) - (a.views || 0));
|
const sortedByViews = [...videos].sort((a, b) => (b.views || 0) - (a.views || 0));
|
||||||
|
|||||||
@ -1154,18 +1154,38 @@ let storage: IStorage;
|
|||||||
const hasDatabase = process.env.DATABASE_URL;
|
const hasDatabase = process.env.DATABASE_URL;
|
||||||
const hasBunnyConfig = process.env.BUNNY_API_KEY && process.env.BUNNY_LIBRARY_ID && process.env.BUNNY_HOSTNAME;
|
const hasBunnyConfig = process.env.BUNNY_API_KEY && process.env.BUNNY_LIBRARY_ID && process.env.BUNNY_HOSTNAME;
|
||||||
|
|
||||||
// Force PostgreSQL database storage
|
// Use hybrid storage when both Bunny.net and Database are available
|
||||||
if (hasDatabase) {
|
if (hasBunnyConfig && hasDatabase) {
|
||||||
|
try {
|
||||||
|
storage = new HybridStorage();
|
||||||
|
console.log('✅ Using Hybrid storage (Bunny.net for videos + Database for users)');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Failed to initialize Hybrid storage:', error);
|
||||||
|
console.log('📁 Falling back to memory storage');
|
||||||
|
storage = new MemStorage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Prioritize Bunny.net storage for video content only
|
||||||
|
else if (hasBunnyConfig) {
|
||||||
|
try {
|
||||||
|
storage = new BunnyStorage();
|
||||||
|
console.log('✅ Using Bunny.net storage with library ID:', process.env.BUNNY_LIBRARY_ID);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Failed to initialize Bunny.net storage:', error);
|
||||||
|
console.log('📁 Falling back to memory storage');
|
||||||
|
storage = new MemStorage();
|
||||||
|
}
|
||||||
|
} else if (hasDatabase) {
|
||||||
try {
|
try {
|
||||||
storage = new DatabaseStorage();
|
storage = new DatabaseStorage();
|
||||||
console.log('✅ Using PostgreSQL database storage ONLY');
|
console.log('✅ Using PostgreSQL database storage');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Failed to initialize database storage:', error);
|
console.error('❌ Failed to initialize database storage:', error);
|
||||||
console.log('📁 Falling back to memory storage');
|
console.log('📁 Falling back to memory storage');
|
||||||
storage = new MemStorage();
|
storage = new MemStorage();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('📁 Using memory storage (no database config found)');
|
console.log('📁 Using memory storage (no database or Bunny.net config found)');
|
||||||
storage = new MemStorage();
|
storage = new MemStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user