From d23d49d7c361509aaac5a9c41b1398dae8bac1d2 Mon Sep 17 00:00:00 2001 From: Louis Mazin Date: Thu, 16 Apr 2026 17:53:07 +0200 Subject: [PATCH] test --- index.js | 8 +++++--- src/pterodactyl/displayer.js | 31 ++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 23960b8..dbd87a1 100644 --- a/index.js +++ b/index.js @@ -56,9 +56,11 @@ client.once('clientReady', async () => { }); client.on(Events.InteractionCreate, async interaction => { - if (interaction.isStringSelectMenu()) { - await handlePinboardSelection(interaction); - return; + if (interaction.isStringSelectMenu() || interaction.isButton()) { + const handled = await handlePinboardSelection(interaction); + if (handled) { + return; + } } if (!interaction.isChatInputCommand()) return; diff --git a/src/pterodactyl/displayer.js b/src/pterodactyl/displayer.js index 2b91805..8b91eb8 100644 --- a/src/pterodactyl/displayer.js +++ b/src/pterodactyl/displayer.js @@ -13,6 +13,7 @@ const preloadedImagesByUrl = new Map(); const warmedMessageIds = new Set(); const warmingMessageIds = new Set(); let lastKnownStatus = null; +let imageRefreshKey = Date.now(); const getCacheBustValue = () => { const bucketSeconds = Number.parseInt(process.env.PINBOARD_CACHE_BUST_SECONDS || '60', 10); @@ -29,6 +30,15 @@ const toCacheBustedUrl = (url) => { return `${url}${separator}cb=${getCacheBustValue()}`; }; +const toRefreshKeyedUrl = (url, refreshKey) => { + if (!refreshKey) { + return url; + } + + const separator = url.includes('?') ? '&' : '?'; + return `${url}${separator}rk=${refreshKey}`; +}; + const readPinboardRawFromEnvFile = () => { try { const envPath = path.join(process.cwd(), '.env'); @@ -195,7 +205,8 @@ const runVisualWarmup = async (message, status, pinboardItems, initialIndex) => const payload = buildPanelPayload(status, message.id, pinboardItems, { useAttachmentForSelected: false, disableCacheBustForSelected: true, - includeFiles: false + includeFiles: false, + refreshKey: imageRefreshKey }); await message.edit(payload); await waitMs(delayMs); @@ -205,7 +216,8 @@ const runVisualWarmup = async (message, status, pinboardItems, initialIndex) => const restoredPayload = buildPanelPayload(status, message.id, pinboardItems, { useAttachmentForSelected: false, disableCacheBustForSelected: true, - includeFiles: false + includeFiles: false, + refreshKey: imageRefreshKey }); await message.edit(restoredPayload); @@ -221,10 +233,11 @@ const runVisualWarmup = async (message, status, pinboardItems, initialIndex) => const buildSelectedImageEmbed = (item, imageReference, options = {}) => { const useAttachment = options.useAttachment !== false; const disableCacheBust = options.disableCacheBust === true; + const refreshKey = options.refreshKey || null; const imageUrl = useAttachment && imageReference?.attachmentName ? `attachment://${imageReference.attachmentName}` - : (disableCacheBust ? item.url : toCacheBustedUrl(item.url)); + : toRefreshKeyedUrl(disableCacheBust ? item.url : toCacheBustedUrl(item.url), refreshKey); return new EmbedBuilder() .setColor('#f59e0b') @@ -329,7 +342,8 @@ const buildPanelPayload = (status, messageId, pinboardItems = null, options = {} const cachedImage = preloadedImagesByUrl.get(selectedItem.url); const selectedImageEmbed = buildSelectedImageEmbed(selectedItem, cachedImage, { useAttachment: options.useAttachmentForSelected, - disableCacheBust: options.disableCacheBustForSelected + disableCacheBust: options.disableCacheBustForSelected, + refreshKey: options.refreshKey }); const selectorRow = buildImageSelectorRow(items, currentIndex); const navigationRow = buildImageNavigationRow(items, currentIndex); @@ -383,6 +397,7 @@ const update = async (client) => { } const pinboardItems = parsePinboardImageItems().slice(0, 25); + imageRefreshKey = Date.now(); const [status] = await Promise.all([ getMinecraftStatus(), preloadPinboardImages(pinboardItems) @@ -391,9 +406,10 @@ const update = async (client) => { const { message } = await resolvePanelMessage(client, channelId, messageId); const payload = buildPanelPayload(status, message.id, pinboardItems, { - useAttachmentForSelected: true, + useAttachmentForSelected: false, disableCacheBustForSelected: false, - includeFiles: true + includeFiles: false, + refreshKey: imageRefreshKey }); await message.edit(payload); @@ -443,7 +459,8 @@ const handlePinboardSelection = async (interaction) => { const payload = buildPanelPayload(status, interaction.message.id, pinboardItems, { useAttachmentForSelected: false, disableCacheBustForSelected: true, - includeFiles: false + includeFiles: false, + refreshKey: imageRefreshKey }); await interaction.update(payload); return true;