Mise à jour : dernières modifs

This commit is contained in:
karim hassan
2025-08-24 14:49:43 +00:00
parent e3620c7f42
commit c5f16fe27b
45 changed files with 2426 additions and 552 deletions

View File

@@ -0,0 +1,12 @@
const api = {
base: '',
token: null,
setToken(t){ this.token = t; localStorage.setItem('ss_token', t); },
getToken(){ return this.token || localStorage.getItem('ss_token'); },
headers(){ const h = { 'Content-Type':'application/json' }; const t=this.getToken(); if(t) h['Authorization']='Bearer '+t; return h; },
async get(path){ const r = await fetch('/api'+path, { headers: this.headers() }); if(!r.ok) throw new Error(await r.text()); return r.json(); },
async post(path, body){ const r = await fetch('/api'+path, { method:'POST', headers:this.headers(), body: JSON.stringify(body) }); if(!r.ok) throw new Error(await r.text()); return r.json(); },
async put(path, body){ const r = await fetch('/api'+path, { method:'PUT', headers:this.headers(), body: JSON.stringify(body) }); if(!r.ok) throw new Error(await r.text()); return r.json(); },
async del(path, body){ const r = await fetch('/api'+path, { method:'DELETE', headers:this.headers(), body: JSON.stringify(body) }); if(!r.ok) throw new Error(await r.text()); return r.json(); }
};
window.SSAPI = api;