photo_server_json_flutter_c.../public/js/api.js
2026-03-23 12:31:01 +01:00

27 lines
717 B
JavaScript

// js/api.js
async function apiGet(url) {
return fetch(url, {
headers: { "Authorization": "Bearer " + localStorage.getItem("token") }
}).then(r => r.json());
}
async function getAllPhotos() {
return apiGet(`${BASE_URL}/photos`);
}
async function getPhotoById(id) {
const payload = parseJwt(localStorage.getItem("token"));
const user = payload.name || "Common";
const url = `${BASE_URL}/photos/byIds?id=${encodeURIComponent(id)}&user=${encodeURIComponent(user)}`;
console.log("🔍 [getPhotoById] URL:", url);
return apiGet(url);
}
async function getChanges(since, user) {
return apiGet(`${BASE_URL}/photos/changes?since=${encodeURIComponent(since)}&user=${encodeURIComponent(user)}`);
}