Spaces:
Sleeping
Sleeping
Nathan commited on
Commit ·
cd4f86d
1
Parent(s): 092070c
Fix: Settings saving and stats loading for multi-channel users
Browse files293 unmodified lines29429529629729829930067 unmodified lines368369370371372373374375376377378379380381382293 unmodified lines// --- Dashboard API ---app.get('/api/stats', authenticateToken, async (req, res) => {const { data: channel } = await db.from('channels').select('niche, preferred_hours, custom_client_id, custom_client_secret, total_views, subscribers').eq('user_id', req.userId).single();const { count: videosGenerated } = await db.from('activity').select('*', { count: 'exact', head: true }).eq('user_id', req.userId).eq('type', 'VIDEO_PUBLISHED');res.json({67 unmodified linesapp.post('/api/settings', authenticateToken, async (req, res) => {const { niche, preferred_hours, custom_client_id, custom_client_secret } = req.body;try {const { error } = await db.from('channels').upsert({user_id: req.userId,niche,preferred_hours,custom_client_id,custom_client_secret}, { onConflict: 'user_id' });if (error) {console.error('❌ Supabase Upsert Error:', error);throw error;}res.json({ success: true });293 unmodified lines29429529629729829930030167 unmodified lines369370371372373374375376377378379380381382383384293 unmodified lines// --- Dashboard API ---app.get('/api/stats', authenticateToken, async (req, res) => {// Use limit(1) instead of single() to avoid crash with multiple channelsconst { data: channel } = await db.from('channels').select('niche, preferred_hours, custom_client_id, custom_client_secret, total_views, subscribers').eq('user_id', req.userId).limit(1).maybeSingle();const { count: videosGenerated } = await db.from('activity').select('*', { count: 'exact', head: true }).eq('user_id', req.userId).eq('type', 'VIDEO_PUBLISHED');res.json({67 unmodified linesapp.post('/api/settings', authenticateToken, async (req, res) => {const { niche, preferred_hours, custom_client_id, custom_client_secret } = req.body;try {// Update ALL channels for this user with these settingsconst { error } = await db.from('channels').update({niche,preferred_hours,custom_client_id,custom_client_secret}).eq('user_id', req.userId);if (error) {console.error('❌ Supabase Update Error:', error);throw error;}res.json({ success: true });
server.js+7-5