40 lines
1 KiB
JavaScript
40 lines
1 KiB
JavaScript
// js/api.js
|
|
|
|
async function apiGet(url) {
|
|
return fetch(url, {
|
|
headers: { "Authorization": "Bearer " + localStorage.getItem("token") }
|
|
}).then(r => r.json());
|
|
}
|
|
|
|
async function getAllPhotos1() {
|
|
//const payload = parseJwt(localStorage.getItem("token"));
|
|
//const user = payload.name || "Common";
|
|
|
|
//return apiGet(`${BASE_URL}/photos?user=${encodeURIComponent(user)}`);
|
|
return apiGet(`https://prova.patachina.it/photos?user=Fabio`);
|
|
}
|
|
|
|
async function getAllPhotos(user) {
|
|
|
|
|
|
return apiGet(`${BASE_URL}/photos?user=${encodeURIComponent(user)}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
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)}`);
|
|
}
|