photo_server_json_flutter_c.../public/js/data.js
2026-03-05 17:07:30 +01:00

84 lines
1.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ===============================
// FETCH DELLE FOTO
// ===============================
async function loadPhotos() {
console.log("Inizio fetch:", window.PHOTOS_URL);
let res;
try {
res = await fetch(window.PHOTOS_URL, {
headers: {
"Authorization": "Bearer " + window.token
}
});
} catch (e) {
console.error("Errore fetch:", e);
return;
}
const text = await res.text();
if (!res.ok) {
console.error(`HTTP ${res.status} ${res.statusText} body:`, text.slice(0, 200));
return;
}
try {
const parsed = JSON.parse(text);
if (!Array.isArray(parsed)) {
console.error("La risposta non è un array:", parsed);
return;
}
window.photosData = parsed;
console.log("JSON parse OK, numero foto:", parsed.length);
} catch (e) {
console.error("Errore nel parse JSON:", e);
return;
}
refreshGallery();
}
async function loadPhotos1() {
console.log("Inizio fetch:", window.BASE_URL + "/photos");
let res;
try {
res = await fetch(`${window.BASE_URL}/photos`, {
headers: {
"Authorization": "Bearer " + window.token
}
});
} catch (e) {
console.error("Errore fetch:", e);
return;
}
const text = await res.text();
if (!res.ok) {
console.error(`HTTP ${res.status} ${res.statusText} body:`, text.slice(0, 200));
return;
}
try {
const parsed = JSON.parse(text);
if (!Array.isArray(parsed)) {
console.error("La risposta non è un array:", parsed);
return;
}
window.photosData = parsed;
console.log("JSON parse OK, numero foto:", parsed.length);
} catch (e) {
console.error("Errore nel parse JSON:", e);
return;
}
refreshGallery();
}