Artwork settings: send the UI key through api(), so the panel and refresh work

Every /api call needs X-Frame-UI; the panel's own fetch() got 403s.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
saphidandClaude Opus 5.5 committed 2026-09-28 23:06:04 +10:00
1 parent 8315c7c3aa
commit 060801c674
2 files changed
+60 -11

No files matched your search

+10 -11
View File
@@ -1,15 +1,12 @@
// Uses index.html's api(), which sends the X-Frame-UI key every /api call needs.
(() => {
const get=id=>document.getElementById(id), status=get('steamGridStatus');
async function request(url,body) {
const r=await fetch(url,body===undefined?{}:{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});
const data=await r.json(); if(!r.ok) throw Error(data.error||'Request failed'); return data;
}
function show(data) {
status.textContent=data.environment?'SteamGridDB key is set by an environment variable.':
data.steamgriddb_configured?'SteamGridDB key saved.':'No key configured. Source images and generated art are enabled.';
}
async function save(value) {
try {show(await request('/api/settings/artwork',{steamgriddb_api_key:value}));get('steamGridKey').value='';}
try {show(await api('/api/settings/artwork',{steamgriddb_api_key:value}));get('steamGridKey').value='';}
catch(e) {status.textContent=e.message;}
}
get('saveSteamGridKey').onclick=()=>save(get('steamGridKey').value.trim());
@@ -17,15 +14,17 @@
get('refreshAndroidArt').onclick=async()=>{
const button=get('refreshAndroidArt');button.disabled=true;
try {
const result=await runJob('Refresh Android artwork','android-artwork',()=>request('/api/android',{action:'refresh-art',all:true}));
const result=await runJob('Refresh library artwork','library-artwork',()=>api('/api/android',{action:'refresh-art',all:true}));
if (result) {
const apps=Array.isArray(result.apps)?result.apps:[result.apps];
const failed=apps.filter(a=>a.error);
status.textContent=failed.length?`${failed.length} refresh failed: ${failed.map(a=>a.package+': '+a.error).join('; ')}`:
`Refreshed artwork for ${apps.length} apps.`;
const items=[...(result.apps||[]),...(result.titles||[])];
const failed=items.filter(a=>a.error);
status.textContent=failed.length?`${failed.length} of ${items.length} failed: ${failed.map(a=>(a.package||a.id)+': '+a.error).join('; ')}`:
`Refreshed artwork for ${items.length} apps and titles.`;
if (typeof loadAndroid==='function') loadAndroid();
if (typeof loadTitles==='function') loadTitles();
}
} catch(e) {status.textContent=e.message;}
finally {button.disabled=false;}
};
request('/api/settings/artwork').then(show).catch(e=>{status.textContent=e.message;});
api('/api/settings/artwork').then(show).catch(e=>{status.textContent=e.message;});
})();