Skip to content

Commit

Permalink
fixing the reused cached image when changing from satellite
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibault Camlane committed Aug 6, 2025
1 parent da710c2 commit 5d71dcc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions backend/src/api/slack/controllers/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ const fetch = require("node-fetch");

let cachedImage = null;
let cacheTimestamp = null;
let cacheSat = null;

module.exports = {
fetchImages: async (ctx) => {
const CACHE_DURATION = 60 * 1000; // 1 minute
const now = Date.now();
const { satName } = ctx.request.body;
if (
cachedImage &&
cacheTimestamp &&
now - cacheTimestamp < CACHE_DURATION
now - cacheTimestamp < CACHE_DURATION &&
cacheSat === satName
) {
ctx.body = cachedImage;
return;
}
try {
const { satName } = ctx.request.body;
const message = await fetchImagesFromSlack.fetchImagesFromSlack(satName);
const image = message ? message.files[0] : null;
if (!image.public_url_shared) {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/api/slack/services/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ module.exports = {
console.log("No messages found in the channel.");
return null;
}
console.log(satellite);
for (const message of result.messages) {
if (message.text && message.text.includes(satellite)) {
if (message.text.includes(satellite)) {
if (!image) {
image = message;
break;
Expand Down

0 comments on commit 5d71dcc

Please sign in to comment.