Sasha commited on
Commit
c22c35b
·
1 Parent(s): 426c35b

Fix: only cache successful 2xx responses and validate streams array structure

Browse files
Files changed (1) hide show
  1. server/cache.js +13 -2
server/cache.js CHANGED
@@ -296,8 +296,19 @@ export function cacheMiddleware(ttlSeconds) {
296
  clearTimeout(safetyTimeout);
297
  res.json = originalJson; // Restore
298
 
299
- // Save fresh data
300
- cache.set(cacheKey, body, ttlMs);
 
 
 
 
 
 
 
 
 
 
 
301
 
302
  // Resolve the promise to unblock anyone who was coalesced (waiting)
303
  resolvePending(body);
 
296
  clearTimeout(safetyTimeout);
297
  res.json = originalJson; // Restore
298
 
299
+ // Save fresh data only on successful 2xx responses and check array structure for streams
300
+ if (res.statusCode >= 200 && res.statusCode < 300) {
301
+ let shouldCache = true;
302
+
303
+ // If this is the streams list endpoint, ensure the body is a valid array
304
+ if (req.path === '/api/streams' && !Array.isArray(body)) {
305
+ shouldCache = false;
306
+ }
307
+
308
+ if (shouldCache) {
309
+ cache.set(cacheKey, body, ttlMs);
310
+ }
311
+ }
312
 
313
  // Resolve the promise to unblock anyone who was coalesced (waiting)
314
  resolvePending(body);