this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Enhance link processing to track active links and enforce delays for FurAffinity links

+15 -7
+15 -7
bot/telegrambot/commands/linkHandler.js
··· 258 258 this.queue = []; 259 259 this.activeCount = 0; 260 260 this.furaffinityActive = false; 261 + this.activeLinks = []; // Track currently processing links 261 262 } 262 263 263 264 enqueue(item) { ··· 267 268 268 269 next() { 269 270 if (this.queue.length === 0) return; 270 - // Check for FurAffinity link at the front 271 + // Check if any active link is a FurAffinity link 272 + const faActive = this.activeLinks.some(link => link && /^https?:\/\/(www\.)?furaffinity\.net\//i.test(link.url)); 273 + // Check for FurAffinity link in the queue 271 274 const faIndex = this.queue.findIndex(item => /^https?:\/\/(www\.)?furaffinity\.net\//i.test(item.url)); 272 - if (faIndex !== -1 && !this.furaffinityActive && this.activeCount < this.concurrency) { 273 - // Process only one FurAffinity link at a time 275 + // Only allow one FA link in activeLinks at a time 276 + if (faIndex !== -1 && !faActive && !this.furaffinityActive && this.activeCount < this.concurrency) { 274 277 const [item] = this.queue.splice(faIndex, 1); 275 278 this.furaffinityActive = true; 276 279 this.activeCount++; 280 + this.activeLinks.push(item); 277 281 console.log(`[AsyncLinkQueue] Processing FurAffinity link: ${item.url} (10s delay before next FA link allowed)`); 278 282 this.processFn(item) 279 283 .catch(() => {}) 280 284 .finally(() => { 281 285 this.activeCount--; 286 + this.activeLinks = this.activeLinks.filter(l => l !== item); 282 287 setTimeout(() => { 283 288 this.furaffinityActive = false; 284 289 console.log('[AsyncLinkQueue] FurAffinity delay complete, next link can be processed.'); 285 290 this.next(); 286 - }, 10000); // 10s enforced delay after FA link 291 + }, 10000); 287 292 }); 288 - return; 293 + // Do not return; allow non-FA links to fill other slots 289 294 } 290 - // Otherwise, process up to concurrency for non-FA links 295 + // Process up to concurrency for non-FA links (but never process a FA link if one is active) 291 296 while (this.activeCount < this.concurrency) { 297 + // Only pick non-FA links if a FA link is already active or in cooldown 292 298 const idx = this.queue.findIndex(item => !/^https?:\/\/(www\.)?furaffinity\.net\//i.test(item.url)); 293 299 if (idx === -1) break; 294 300 const [item] = this.queue.splice(idx, 1); 295 301 this.activeCount++; 302 + this.activeLinks.push(item); 296 303 this.processFn(item) 297 304 .catch(() => {}) 298 305 .finally(() => { 299 306 this.activeCount--; 300 - setTimeout(() => this.next(), 4000); // 4s cooldown for non-FurAffinity links 307 + this.activeLinks = this.activeLinks.filter(l => l !== item); 308 + setTimeout(() => this.next(), 4000); 301 309 }); 302 310 } 303 311 }