Fix library refresh behavior

This commit is contained in:
Zac Gaetano 2026-05-25 01:08:38 -04:00
parent 3dad82d992
commit de895dd7f8

View file

@ -120,6 +120,23 @@ function normalizeJob(j) {
};
}
async function refreshAssets() {
const raw = await apiFetch('/assets?limit=500');
const list = Array.isArray(raw) ? raw : (raw.assets || []);
const projectMap = {};
(window.ZAMPP_DATA.PROJECTS || []).forEach(function(p) { projectMap[p.id] = p.name; });
const normalized = list.map(function(a) { return normalizeAsset(a, projectMap); });
window.ZAMPP_DATA.ASSETS = normalized;
if (window.ZAMPP_DATA.PROJECTS && window.ZAMPP_DATA.PROJECTS.length) {
const counts = {};
list.forEach(function(a) { if (a.project_id) counts[a.project_id] = (counts[a.project_id] || 0) + 1; });
window.ZAMPP_DATA.PROJECTS = window.ZAMPP_DATA.PROJECTS.map(function(p) {
return { ...p, assets: counts[p.id] || 0 };
});
}
return normalized;
}
async function loadData() {
const [projectsR, assetsR, recordersR, jobsR, clusterR, usersR, binsR, meR] = await Promise.allSettled([
apiFetch('/projects'),
@ -251,7 +268,7 @@ async function exportSequenceEDL(sequenceId, filename) {
}
window.ZAMPP_API = {
fetch: apiFetch, loadData, fmtDuration, fmtSize, fmtRelative,
fetch: apiFetch, loadData, refreshAssets, fmtDuration, fmtSize, fmtRelative,
getSequences, createSequence, getSequence, updateSequence,
deleteSequence, syncSequenceClips, exportSequenceEDL,
};