Cache-bust icon img src with timestamp; no-store on 404 to prevent browser caching misses

This commit is contained in:
KarnerF committed 2026-08-30 15:18:17 +02:00
1 parent 3abb58a6b0
commit 0f1c403d41
1 file changed
+4 -4
+4 -4
View File
@@ -1797,10 +1797,10 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
"var ba=img.mounted"
"?'<button type=\"button\" data-i=\"'+i+'\" onclick=\"_smUnmountThis(this)\" style=\"background:transparent;border:1px solid #f87171;border-radius:4px;color:#f87171;padding:3px 10px;cursor:pointer;font-size:.75rem;\">Unmount</button>'"
":'<button type=\"button\" data-i=\"'+i+'\" onclick=\"_smMountThis(this)\" style=\"background:transparent;border:1px solid var(--accent);border-radius:4px;color:var(--accent);padding:3px 10px;cursor:pointer;font-size:.75rem;white-space:nowrap;\">Mount</button>';"
/* /api/icon/{tid} has no query string - safe in img src */
/* add timestamp to img src to bypass any browser 404 cache */
"var ic=tid"
"?'<div style=\"position:relative;width:48px;height:48px;border-radius:8px;overflow:hidden;background:#1e2a42;flex-shrink:0;\">'"
"+'<img src=\"/api/icon/'+tid+'\" style=\"position:absolute;top:0;left:0;width:100%%;height:100%%;object-fit:cover;\" onerror=\"this.remove()\">'"
"+'<img src=\"/api/icon/'+tid+'?t='+Date.now()+'\" style=\"position:absolute;top:0;left:0;width:100%%;height:100%%;object-fit:cover;\" onerror=\"this.remove()\">'"
"+'<span style=\"position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font-size:.55rem;color:#64748b;font-family:monospace;\">'+tid.substring(0,4)+'</span></div>'"
":'<div style=\"width:48px;height:48px;border-radius:8px;background:#1e2a42;flex-shrink:0;\"></div>';"
"h+='<div style=\"display:flex;align-items:center;gap:10px;padding:8px 4px;border-bottom:1px solid var(--border);\">'+ic;"
@@ -2976,11 +2976,11 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
}free(ibuf);
}fclose(sf);
}
mg_http_reply(c,404,"","");return;
mg_http_reply(c,404,"Cache-Control: no-store\r\n","");return;
#undef SMG_IC2
}
fseek(fi,0,SEEK_END);long sz2=ftell(fi);fseek(fi,0,SEEK_SET);
if(sz2<=0||sz2>524288){fclose(fi);mg_http_reply(c,404,"","");return;}
if(sz2<=0||sz2>524288){fclose(fi);mg_http_reply(c,404,"Cache-Control: no-store\r\n","");return;}
char *buf2=malloc(sz2);if(!buf2){fclose(fi);mg_http_reply(c,500,"","");return;}
fread(buf2,1,sz2,fi);fclose(fi);
mg_http_reply(c,200,"Content-Type: image/png\r\nCache-Control: max-age=86400\r\n","%.*s",(int)sz2,buf2);