this repo has no description
0
fork

Configure Feed

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

feat: Add /recache command to handle media recaching and improve image processing

+61 -2
+1
.gitignore
··· 9 9 queue/queue.json 10 10 queue/queue.json.backup 11 11 cache/ 12 + alert-state.json 12 13 13 14 # Dependencies 14 15 node_modules/
+3 -1
bot/telegrambot/commandRegistry.js
··· 13 13 const AnnouncementsCommand = require('./commands/announcements'); 14 14 const StatusCommand = require('./commands/status'); 15 15 const LinkHandler = require('./commands/linkHandler'); 16 + const RecacheCommand = require('./commands/recache'); 16 17 17 18 // Helper imports 18 19 const AuthHelper = require('./helpers/authHelper'); ··· 49 50 new UpdateCommand(bot, this.authHelper), 50 51 new AnnounceCommand(bot, this.authHelper, announcements), 51 52 new AnnouncementsCommand(bot, this.authHelper, announcements), 52 - new StatusCommand(bot, this.authHelper, queueMonitor) 53 + new StatusCommand(bot, this.authHelper, queueMonitor), 54 + new RecacheCommand(bot, this.authHelper) 53 55 ]; 54 56 55 57 // Initialize link handler
+2 -1
bot/telegrambot/commands/index.js
··· 12 12 UpdateCommand: require('./update'), 13 13 AnnounceCommand: require('./announce'), 14 14 AnnouncementsCommand: require('./announcements'), 15 - LinkHandler: require('./linkHandler') 15 + LinkHandler: require('./linkHandler'), 16 + RecacheCommand: require('./recache') 16 17 };
+55
bot/telegrambot/commands/recache.js
··· 1 + const queueManager = require('../../../queue/queueManager'); 2 + const mediaCache = require('../../../utils/mediaCache'); 3 + 4 + /** 5 + * /recache command handler 6 + */ 7 + class RecacheCommand { 8 + constructor(bot, authHelper) { 9 + this.bot = bot; 10 + this.authHelper = authHelper; 11 + } 12 + 13 + register() { 14 + this.bot.onText(/\/recache/, async (msg) => { 15 + const chatId = msg.chat.id; 16 + if (!this.authHelper.isAuthorized(msg.from.id)) { 17 + this.bot.sendMessage(chatId, 'You are not authorized to use this command.'); 18 + return; 19 + } 20 + this.bot.sendMessage(chatId, 'Recaching missing images and files. This may take a while...'); 21 + try { 22 + const queue = await queueManager.getQueue(); 23 + let recachedCount = 0; 24 + for (let i = 0; i < queue.length; i++) { 25 + const item = queue[i]; 26 + // Support both single and multiple images 27 + const urls = []; 28 + if (item.sourceImgUrl) urls.push(item.sourceImgUrl); 29 + if (Array.isArray(item.originalImageUrls)) urls.push(...item.originalImageUrls); 30 + if (item.downloadUrl && !urls.includes(item.downloadUrl)) urls.push(item.downloadUrl); 31 + if (item.originalImageUrl && !urls.includes(item.originalImageUrl)) urls.push(item.originalImageUrl); 32 + // Remove duplicates 33 + const uniqueUrls = [...new Set(urls.filter(Boolean))]; 34 + for (const url of uniqueUrls) { 35 + try { 36 + const result = await mediaCache.processMediaUrl(url, item.isVideo); 37 + // Optionally update imageUrl/imageUrls if missing or invalid 38 + // (not overwriting if already present and valid) 39 + // Could add logic here if needed 40 + recachedCount++; 41 + } catch (err) { 42 + // Log but continue 43 + console.error(`Failed to recache for queue item: ${item.title || item.id} (${url}):`, err.message); 44 + } 45 + } 46 + } 47 + this.bot.sendMessage(chatId, `Recache complete. Processed ${queue.length} queue items. Attempted to recache ${recachedCount} files.`); 48 + } catch (error) { 49 + this.bot.sendMessage(chatId, `Error during recache: ${error.message}`); 50 + } 51 + }); 52 + } 53 + } 54 + 55 + module.exports = RecacheCommand;