Spaces:
Sleeping
Sleeping
Nathan commited on
Commit ·
092070c
1
Parent(s): b5d186b
Update: Added 2-channel support for Premium/Ultra plans
Browse filesFiles changed (3)
- dashboard/index.html+46-14
- dashboard/plans.html+3-1
- server.js+47-27
227 unmodified lines22822923023123223323423523623723823924024124224 unmodified lines26726826927027127271 unmodified lines34434534634734834935035135235335432 unmodified lines387388389390391392393394395396397398399400401227 unmodified lines</div><div style="margin-top: 30px;"><div id="yt-connect-group"><button id="youtube-btn" class="btn-primary btn-full" style="background: #ef4444;" onclick="connectYouTube()"><i data-lucide="youtube"></i> Connect YouTube Channel</button></div><div id="yt-active-group" style="display: none;"><div id="channel-name" style="text-align: center; margin-bottom: 10px; font-weight: 700; color: var(--success);"></div><div style="text-align: center; font-size: 0.75rem; color: var(--text-dim); background: rgba(255,255,255,0.03); padding: 10px; border-radius: 12px; border: 1px solid var(--glass-border);"><i data-lucide="lock" style="width: 12px; vertical-align: middle;"></i> Connection Permanently Locked</div></div></div>24 unmodified lines<script>let authToken = localStorage.getItem('saas_token');let preferredHours = [];function toggleAuthPass(id) {const el = document.getElementById(id);71 unmodified linesdocument.getElementById('user-plan').innerText = '☢️ GOD MODE';document.getElementById('user-plan').style.background = 'rgba(245, 158, 11, 0.1)';document.getElementById('user-plan').style.color = '#f59e0b';// Hide Plans link for admin/ultraconst navPlans = document.getElementById('nav-plans');if (navPlans) navPlans.remove();} else {if (d.plan === 'premium') {const daysLeft = Math.ceil((new Date(d.expires_at) - new Date()) / (1000 * 60 * 60 * 24));document.getElementById('user-plan').innerText = `💎 PRO CREATOR (${daysLeft} Days Left)`;32 unmodified linesconst ytRes = await fetch('/api/youtube', { headers: { 'Authorization': `Bearer ${authToken}` } });const yt = await ytRes.json();if (yt.connected) {document.getElementById('yt-connect-group').style.display = 'none';document.getElementById('yt-active-group').style.display = 'block';document.getElementById('channel-name').innerText = yt.channel_name || "Channel Connected";document.getElementById('stat-views').innerText = yt.totalViews || 0;document.getElementById('stat-subs').innerText = yt.subscribers || 0;} else {document.getElementById('yt-connect-group').style.display = 'block';document.getElementById('yt-active-group').style.display = 'none';}setInterval(() => {227 unmodified lines22822923023123223323423523623724 unmodified lines26226326426526626726871 unmodified lines34034134234334434534634734834935035135232 unmodified lines385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433227 unmodified lines</div><div style="margin-top: 30px;"><div id="yt-active-group" style="display: none;"><div id="channel-list" style="display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px;"></div><div style="text-align: center; font-size: 0.75rem; color: var(--text-dim); background: rgba(255,255,255,0.03); padding: 10px; border-radius: 12px; border: 1px solid var(--glass-border);"><i data-lucide="lock" style="width: 12px; vertical-align: middle;"></i> Connections Permanently Locked</div></div></div>24 unmodified lines<script>let authToken = localStorage.getItem('saas_token');let preferredHours = [];let userPlan = 'free';function toggleAuthPass(id) {const el = document.getElementById(id);71 unmodified linesdocument.getElementById('user-plan').innerText = '☢️ GOD MODE';document.getElementById('user-plan').style.background = 'rgba(245, 158, 11, 0.1)';document.getElementById('user-plan').style.color = '#f59e0b';userPlan = 'ultra';// Hide Plans link for admin/ultraconst navPlans = document.getElementById('nav-plans');if (navPlans) navPlans.remove();} else {userPlan = d.plan || 'free';if (d.plan === 'premium') {const daysLeft = Math.ceil((new Date(d.expires_at) - new Date()) / (1000 * 60 * 60 * 24));document.getElementById('user-plan').innerText = `💎 PRO CREATOR (${daysLeft} Days Left)`;32 unmodified linesconst ytRes = await fetch('/api/youtube', { headers: { 'Authorization': `Bearer ${authToken}` } });const yt = await ytRes.json();const list = document.getElementById('channel-list');list.innerHTML = '';if (yt.connected && yt.channels && yt.channels.length > 0) {document.getElementById('yt-active-group').style.display = 'block';let totalV = 0, totalS = 0;yt.channels.forEach(c => {totalV += c.totalViews || 0;totalS += c.subscribers || 0;const item = document.createElement('div');item.style.cssText = "display: flex; justify-content: space-between; align-items: center; background: rgba(16, 185, 129, 0.1); border: 1px solid var(--success); padding: 12px 20px; border-radius: 16px;";item.innerHTML = `<div style="font-weight: 700; color: var(--success); display: flex; align-items: center; gap: 8px;"><i data-lucide="youtube" style="width: 16px;"></i> ${c.channel_name}</div><div style="font-size: 0.7rem; color: var(--text-dim);">${c.subscribers.toLocaleString()} Subs</div>`;list.appendChild(item);});document.getElementById('stat-views').innerText = totalV.toLocaleString();document.getElementById('stat-subs').innerText = totalS.toLocaleString();// Show "Add Another" button if limit not reachedconst limit = (userPlan === 'premium' || userPlan === 'ultra') ? 2 : 1;if (yt.count < limit) {const addBtn = document.createElement('button');addBtn.className = "btn-primary btn-full";addBtn.style.marginTop = "15px";addBtn.innerHTML = `<i data-lucide="plus-circle"></i> Connect 2nd Channel`;addBtn.onclick = connectYouTube;list.appendChild(addBtn);}} else {document.getElementById('yt-active-group').style.display = 'block';const connectBtn = document.createElement('button');connectBtn.className = "btn-primary btn-full";connectBtn.style.background = "#ef4444";connectBtn.innerHTML = `<i data-lucide="youtube"></i> Connect YouTube Channel`;connectBtn.onclick = connectYouTube;list.appendChild(connectBtn);}setInterval(() => {
142 unmodified lines14314414514614714811 unmodified lines1601611621631641659 unmodified lines175176177178179180181142 unmodified lines</div><div id="m-text" style="color: var(--text-dim); font-size: 0.8rem; margin-bottom: 20px;">+30 Days of High-Speed Automation</div><ul class="features"><li><i data-lucide="check-circle-2"></i> 5 Videos per Day</li><li><i data-lucide="check-circle-2"></i> Auto-Scheduling Engine</li><li><i data-lucide="check-circle-2"></i> Priority AI Processing</li>11 unmodified lines</div><div id="y-text" style="color: var(--text-dim); font-size: 0.8rem; margin-bottom: 20px;">+365 Days of Global Dominance</div><ul class="features"><li><i data-lucide="check-circle-2"></i> 5 Videos per Day</li><li><i data-lucide="check-circle-2"></i> Priority 24/7 Support</li><li><i data-lucide="check-circle-2"></i> Beta Access to New AI Models</li>9 unmodified lines<div style="color: var(--text-dim); font-size: 0.8rem; margin-bottom: 20px;">Unlimited Power. Zero Limits.</div><ul class="features"><li><i data-lucide="zap" style="color: #f59e0b;"></i> Unlimited Videos Daily</li><li><i data-lucide="zap" style="color: #f59e0b;"></i> No Channel Limits</li><li><i data-lucide="zap" style="color: #f59e0b;"></i> Dedicated Server Core</li></ul><button class="btn-buy" style="background: #f59e0b; cursor: default;">Contact Admin</button>142 unmodified lines14314414514614714814911 unmodified lines1611621631641651661679 unmodified lines177178179180181182183142 unmodified lines</div><div id="m-text" style="color: var(--text-dim); font-size: 0.8rem; margin-bottom: 20px;">+30 Days of High-Speed Automation</div><ul class="features"><li><i data-lucide="check-circle-2"></i> 2 YouTube Channels</li><li><i data-lucide="check-circle-2"></i> 5 Videos per Day</li><li><i data-lucide="check-circle-2"></i> Auto-Scheduling Engine</li><li><i data-lucide="check-circle-2"></i> Priority AI Processing</li>11 unmodified lines</div><div id="y-text" style="color: var(--text-dim); font-size: 0.8rem; margin-bottom: 20px;">+365 Days of Global Dominance</div><ul class="features"><li><i data-lucide="check-circle-2"></i> 2 YouTube Channels</li><li><i data-lucide="check-circle-2"></i> 5 Videos per Day</li><li><i data-lucide="check-circle-2"></i> Priority 24/7 Support</li><li><i data-lucide="check-circle-2"></i> Beta Access to New AI Models</li>9 unmodified lines<div style="color: var(--text-dim); font-size: 0.8rem; margin-bottom: 20px;">Unlimited Power. Zero Limits.</div><ul class="features"><li><i data-lucide="zap" style="color: #f59e0b;"></i> Unlimited Videos Daily</li><li><i data-lucide="zap" style="color: #f59e0b;"></i> 2 YouTube Channels</li><li><i data-lucide="zap" style="color: #f59e0b;"></i> Dedicated Server Core</li></ul><button class="btn-buy" style="background: #f59e0b; cursor: default;">Contact Admin</button>
323 unmodified lines32432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435574 unmodified lines43043143243343443543643743843944044144211 unmodified lines454455456457458459460323 unmodified linesapp.get('/api/youtube', authenticateToken, async (req, res) => {try {const { data: channelData } = await db.from('channels').select('token, channel_id').eq('user_id', req.userId).single();if (!channelData) return res.json({ connected: false });const oauth2Client = await getOAuth2Client();oauth2Client.setCredentials(channelData.token);const youtube = google.youtube({ version: 'v3', auth: oauth2Client });// Target the specific channel_id instead of 'mine'const response = await youtube.channels.list({part: 'statistics',id: channelData.channel_id});if (response.data.items && response.data.items.length > 0) {const stats = response.data.items[0].statistics;res.json({connected: true,channel_name: channelData.channel_name,subscribers: parseInt(stats.subscriberCount),totalViews: parseInt(stats.viewCount)});} else {res.json({ connected: false });}} catch (error) {res.json({ connected: false });}});74 unmodified linesreturn res.send('<h1>🚫 Channel Banned</h1><p>This YouTube channel has been permanently blacklisted from ViralFlow AI.</p>');}// 2. Check if User is already LOCKED to another channelconst { data: current } = await db.from('channels').select('channel_id, is_locked').eq('user_id', userId).single();if (current?.is_locked && current.channel_id !== channel.id) {return res.send('<h1>🔒 Connection Locked</h1><p>Your account is locked to a specific channel. Contact support to change it.</p>');}// 3. Check if this channel is already connected to another userconst { data: existing } = await db.from('channels').select('user_id').eq('channel_id', channel.id)11 unmodified linestoken: tokens,is_active: true,is_locked: true // Lock the connection once successful}, { onConflict: 'user_id' });}res.send('<h1>✅ YouTube Connected!</h1><p>Close this and refresh your dashboard.</p>');} catch (e) {323 unmodified lines32432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636774 unmodified lines44244344444544644744844945045145245345445545645745845946046146211 unmodified lines474475476477478479480323 unmodified linesapp.get('/api/youtube', authenticateToken, async (req, res) => {try {const { data: channels } = await db.from('channels').select('token, channel_id, channel_name, total_views, subscribers').eq('user_id', req.userId);if (!channels || channels.length === 0) return res.json({ connected: false, channels: [] });const results = [];const oauth2Client = await getOAuth2Client();for (const chan of channels) {try {oauth2Client.setCredentials(chan.token);const youtube = google.youtube({ version: 'v3', auth: oauth2Client });const response = await youtube.channels.list({part: 'statistics',id: chan.channel_id});if (response.data.items && response.data.items.length > 0) {const stats = response.data.items[0].statistics;results.push({connected: true,channel_id: chan.channel_id,channel_name: chan.channel_name,subscribers: parseInt(stats.subscriberCount),totalViews: parseInt(stats.viewCount)});}} catch (e) {console.error(`Error fetching stats for ${chan.channel_id}:`, e.message);}}res.json({connected: results.length > 0,channels: results,count: results.length});} catch (error) {res.json({ connected: false, channels: [] });}});74 unmodified linesreturn res.send('<h1>🚫 Channel Banned</h1><p>This YouTube channel has been permanently blacklisted from ViralFlow AI.</p>');}// 2. Multi-Channel Logicconst { data: user } = await db.from('users').select('plan, role').eq('id', userId).single();const { count: currentChannels } = await db.from('channels').select('*', { count: 'exact', head: true }).eq('user_id', userId);const isPaid = user?.plan === 'premium' || user?.plan === 'ultra' || user?.role === 'admin';const limit = isPaid ? 2 : 1;// 3. Check if user already has this specific channelconst { data: hasThisChannel } = await db.from('channels').select('channel_id').eq('user_id', userId).eq('channel_id', channel.id).single();if (!hasThisChannel && currentChannels >= limit) {return res.send(`<h1>❌ Limit Reached</h1><p>Your ${user?.plan} plan allows only ${limit} channel(s). Upgrade to add more.</p>`);}// 4. Check if this channel is already connected to another userconst { data: existing } = await db.from('channels').select('user_id').eq('channel_id', channel.id)11 unmodified linestoken: tokens,is_active: true,is_locked: true // Lock the connection once successful}, { onConflict: 'channel_id' });}res.send('<h1>✅ YouTube Connected!</h1><p>Close this and refresh your dashboard.</p>');} catch (e) {
dashboard/index.html+46-14
dashboard/plans.html+3-1
server.js+47-27