Spaces:
Sleeping
Sleeping
Nathan commited on
Commit ·
428e88d
1
Parent(s): 93ce8de
Fix: Self-healing database logic for missing channels
Browse files331 unmodified lines332333334335335336337338339340341342343344345346347348349350351331 unmodified lines try { const { data: channels, error: chanError } = await db.from('channels').select('token, channel_id, channel_name, total_views, subscribers').eq('user_id', req.userId); if (chanError) throw chanError; if (!channels || channels.length === 0) return res.json({ connected: false, channels: [] });
// SELF-HEALING: If no channel exists, create one! if (!channels || channels.length === 0) { console.log(`🔧 [API/YouTube] Auto-creating placeholder for user ${req.userId}`); const { data: newChan, error: initError } = await db.from('channels').insert([{ user_id: req.userId, is_active: false, niche: 'Facts', preferred_hours: ['10:00'] }]).select(); if (initError) throw initError; return res.json({ connected: false, channels: newChan, message: 'Placeholder created' }); }
// Fetch keys from Users table const { data: user, error: userError } = await db.from('users').select('custom_client_id, custom_client_secret').eq('id', req.userId).single();server.js+14-1