fix: QuotaExceededError on user pictures load

This commit is contained in:
imperosol
2026-05-06 12:39:27 +02:00
parent 200f71a762
commit d123e5e35b
+17 -2
View File
@@ -35,8 +35,23 @@ document.addEventListener("alpine:init", () => {
// biome-ignore lint/style/useNamingConvention: from python api
query: { users_identified: [config.userId] },
} as PicturesFetchPicturesData);
localStorage.setItem(localStorageInvalidationKey, config.nbPictures.toString());
localStorage.setItem(localStorageKey, JSON.stringify(pictures));
try {
localStorage.setItem(localStorageInvalidationKey, config.nbPictures.toString());
localStorage.setItem(localStorageKey, JSON.stringify(pictures));
} catch {
// an exception is raised if the localstorage is entirely filled
// so just delete all cached user pictures.
// A cache hit is not worth the page breaking.
Object.keys(localStorage)
.filter(
(key) =>
key.startsWith("user") &&
(key.endsWith("Pictures") || key.endsWith("PicturesNumber")),
)
.forEach((key) => {
localStorage.removeItem(key);
});
}
return pictures;
},