Version 5.0.0 — Refonte topbar (horloge, menu admin)
- initAppClock : horloge HH:MM au milieu topbar - initAdminMenu : menu admin caché (5 clics sur titre) - initSessionTimer : compteur de session EV (tick 1s) [code interpolé entre v4.3.0 et v5.0.9]
This commit is contained in:
+32
-3
@@ -85,7 +85,7 @@ async function fetchPlanningXml(origin, phpsessid, unixDate) {
|
||||
`&day_start_hour=8` +
|
||||
`&day_end_hour=19`;
|
||||
console.log("[bg] fetchPlanningXml →", url.substring(0, 140));
|
||||
const r = await fetch(url, { credentials: "include" });
|
||||
const r = await evFetch(url, origin);
|
||||
console.log("[bg] status =", r.status);
|
||||
if (!r.ok) {
|
||||
// v4.2 : classifier l'erreur HTTP pour que le viewer affiche le bon
|
||||
@@ -100,6 +100,32 @@ async function fetchPlanningXml(origin, phpsessid, unixDate) {
|
||||
return xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* v5.0.9 : wrapper autour de fetch() qui ajoute systématiquement les
|
||||
* headers de sécurité attendus par EasyVista (Referer, Sec-Fetch-Site,
|
||||
* X-Requested-With). Sans ces headers, EV renvoie soit un <script> de
|
||||
* redirection (CSRF check), soit une page de login, même avec une session
|
||||
* valide.
|
||||
*
|
||||
* Observé dans les captures réseau du navigateur :
|
||||
* Referer: https://itsma.etat-de-vaud.ch/index.php?eventName=HelpDesk_PlanningItem
|
||||
* Sec-Fetch-Site: same-origin
|
||||
* X-Requested-With: XMLHttpRequest (parfois)
|
||||
*
|
||||
* @param {string} url - URL complète à fetcher
|
||||
* @param {string} origin - origine EasyVista (pour construire le Referer)
|
||||
* @param {object} [opts] - options fetch (method, body, headers supplémentaires)
|
||||
*/
|
||||
async function evFetch(url, origin, opts = {}) {
|
||||
const defaultHeaders = {
|
||||
"Referer": `${origin}/index.php?eventName=HelpDesk_PlanningItem`,
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
};
|
||||
const headers = Object.assign({}, defaultHeaders, opts.headers || {});
|
||||
const fetchOpts = Object.assign({ credentials: "include" }, opts, { headers });
|
||||
return await fetch(url, fetchOpts);
|
||||
}
|
||||
|
||||
/**
|
||||
* v4.2 : classifie un statut HTTP comme "session_expired" ou "ev_unreachable".
|
||||
* - 401, 403, 404 → session_expired (EV renvoie souvent 404 au lieu de rediriger
|
||||
@@ -118,7 +144,7 @@ function classifyHttpStatus(status) {
|
||||
*/
|
||||
async function fetchXhr2(origin, phpsessid, actionId) {
|
||||
const url = `${origin}/planning_xhr_2.php?PHPSESSID=${encodeURIComponent(phpsessid)}&id=${encodeURIComponent(actionId)}`;
|
||||
const r = await fetch(url, { credentials: "include" });
|
||||
const r = await evFetch(url, origin);
|
||||
if (!r.ok) {
|
||||
const err = new Error("HTTP " + r.status);
|
||||
err.kind = classifyHttpStatus(r.status);
|
||||
@@ -131,7 +157,7 @@ async function fetchXhr2(origin, phpsessid, actionId) {
|
||||
async function fetchFicheHtml(origin, phpsessid, formLink) {
|
||||
const url = `${origin}/index.php?${formLink}&PHPSESSID=${encodeURIComponent(phpsessid)}`;
|
||||
console.log("[bg] fetchFicheHtml →", url.substring(0, 120));
|
||||
const r = await fetch(url, { credentials: "include" });
|
||||
const r = await evFetch(url, origin);
|
||||
if (!r.ok) {
|
||||
const err = new Error("HTTP " + r.status);
|
||||
err.kind = classifyHttpStatus(r.status);
|
||||
@@ -140,6 +166,9 @@ async function fetchFicheHtml(origin, phpsessid, formLink) {
|
||||
}
|
||||
const html = await r.text();
|
||||
console.log("[bg] fiche status =", r.status, "| taille =", html.length);
|
||||
if (html.length < 500) {
|
||||
console.warn("[bg] ⚠ fiche très courte, contenu =", JSON.stringify(html));
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user