JAYNESTV commited on
Commit
ac29e23
·
verified ·
1 Parent(s): 108ec79

Upload index.js

Browse files
Files changed (1) hide show
  1. index.js +28 -12
index.js CHANGED
@@ -536,25 +536,41 @@ app.get('/api/content/channels', (req, res) => {
536
  // kwa "fast", masaa 24 kwa "slow"). Hii ndiyo pia inayoiamsha Space
537
  // ikiwa imelala (HF Space "kulala" kunatatuliwa moja kwa moja na
538
  // request yoyote ya HTTP inayoifikia).
539
- app.get('/refresh', async (req, res) => {
 
 
 
 
 
 
540
  if (req.query.key !== REFRESH_SECRET) {
541
  return res.status(403).json({ success: false, error: 'Funguo si sahihi' });
542
  }
543
 
544
  const tier = req.query.tier || 'all';
545
- const response = { success: true, tier };
546
 
547
- try {
548
- if (tier === 'fast' || tier === 'all') {
549
- response.fast = await runFastRefresh();
550
- }
551
- if (tier === 'slow' || tier === 'all') {
552
- response.slow = await runSlowRefresh();
553
- }
554
- res.json(response);
555
- } catch (err) {
556
- res.status(500).json({ success: false, error: err.message });
557
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
558
  });
559
 
560
  app.get('/status', (req, res) => {
 
536
  // kwa "fast", masaa 24 kwa "slow"). Hii ndiyo pia inayoiamsha Space
537
  // ikiwa imelala (HF Space "kulala" kunatatuliwa moja kwa moja na
538
  // request yoyote ya HTTP inayoifikia).
539
+ //
540
+ // MUHIMU: refresh ya channels kadhaa kwa Puppeteer inachukua muda
541
+ // mrefu kuliko timeout ya cron-job.org (kawaida sekunde 30). Kwa
542
+ // hiyo endpoint hii INARUDISHA JIBU MARA MOJA (haisubiri refresh
543
+ // ikamilike), na refresh inaendelea NYUMA (background). Tumia
544
+ // GET /status kuona hali/matokeo ya refresh ya mwisho.
545
+ app.get('/refresh', (req, res) => {
546
  if (req.query.key !== REFRESH_SECRET) {
547
  return res.status(403).json({ success: false, error: 'Funguo si sahihi' });
548
  }
549
 
550
  const tier = req.query.tier || 'all';
551
+ const started = [];
552
 
553
+ if ((tier === 'fast' || tier === 'all') && !isRefreshingFast) {
554
+ started.push('fast');
555
+ runFastRefresh().catch((e) => console.error('fast refresh error:', e.message));
556
+ }
557
+ if ((tier === 'slow' || tier === 'all') && !isRefreshingSlow) {
558
+ started.push('slow');
559
+ runSlowRefresh().catch((e) => console.error('slow refresh error:', e.message));
 
 
 
560
  }
561
+
562
+ // Jibu la HARAKA — halisubiri refresh ikamilike kabisa
563
+ res.json({
564
+ success: true,
565
+ tier,
566
+ message: started.length
567
+ ? `Refresh imeanza nyuma (background) kwa: ${started.join(', ')}. Tumia GET /status kuona matokeo.`
568
+ : 'Refresh tayari inaendelea (au haikuombwa) — angalia /status.',
569
+ already_running: {
570
+ fast: isRefreshingFast,
571
+ slow: isRefreshingSlow,
572
+ },
573
+ });
574
  });
575
 
576
  app.get('/status', (req, res) => {