Fichiers
Théo GastineletClaude Opus 5.5 1228bf47aa fix(beta): API admin limitee a admin.jobrunner.fr, effacement et purge des testeurs, plafonds des captures, deconnexion en POST
- X-Admin seul ne suffit plus : Host doit etre admin.jobrunner.fr (le vhost public transmet les en-tetes du visiteur)
- feedback.tester_id : retours lies au testeur, effaces avec lui (captures comprises)
- codes.py effacer-testeur / purger (simulation par defaut)
- captures : 30/jour/auteur, 500 Mo au total, 5 Go libres minimum
- /__beta/logout en POST avec X-Beta (F5)
- 5 tests ajoutes (30 au total)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 11:45:45 +01:00

150 lignes
10 KiB
JavaScript

/* Couche bêta JobRunner : bandeau, « Donner mon avis », données de démo (bots), libellés SIMULÉ.
Injectée par beta/server.py : le site d'origine n'est pas modifié. */
(function () {
'use strict';
var H = { 'Content-Type': 'application/json', 'X-Beta': '1' };
function el(tag, attrs, html) { var e = document.createElement(tag); for (var k in attrs || {}) e.setAttribute(k, attrs[k]); if (html != null) e.textContent = html; return e; }
// --- Bandeau Bêta ---
var b = el('div', { id: 'jrb-bandeau', role: 'status' });
var badge = el('b', {}, 'BÊTA'); b.appendChild(badge);
b.appendChild(document.createTextNode('Données fictives · paiement SIMULÉ'));
var out = el('a', { href: '#' }, 'Quitter'); b.appendChild(out);
out.addEventListener('click', function (ev) {
ev.preventDefault();
fetch('/__beta/logout', { method: 'POST', headers: { 'X-Beta': '1' }, credentials: 'same-origin' })
.then(function () { location.href = '/__beta/gate'; }, function () { location.href = '/__beta/gate'; });
});
document.body.insertBefore(b, document.body.firstChild);
// --- Garde-fou paiement : aucun appel vers un prestataire de paiement ---
var BLOC = /stripe|stancer|paypal|adyen|checkout|didit/i;
var f0 = window.fetch;
if (f0) window.fetch = function (u) { if (BLOC.test(String(u && u.url || u))) return Promise.reject(new Error('Paiement désactivé en bêta')); return f0.apply(this, arguments); };
// --- Libellés SIMULÉ ---
var tcm = window.triggerCustomModal;
if (typeof tcm === 'function') window.triggerCustomModal = function (msg) {
if (typeof msg === 'string' && /séquestre|débloqu|versé|virement|paiement|pass/i.test(msg) && !/SIMUL/.test(msg)) arguments[0] = msg + ' (SIMULÉ)';
return tcm.apply(this, arguments);
};
function marquer(id, texte) {
var m = document.getElementById(id); if (!m || m.querySelector('.jrb-simule')) return;
var n = el('div', { 'class': 'jrb-simule' }, texte);
var cible = m.firstElementChild || m; cible.insertBefore(n, cible.firstChild);
}
function simules() {
marquer('escrow-confirm-modal', 'SIMULÉ · aucun argent réel · paiement Stancer non branché');
marquer('legal-sheet', 'SIMULÉ · aucun paiement réel ne sera effectué');
}
// --- Données de démo (bots) ---
var vus = {};
function categorie(id) { return ((typeof categoriesData !== "undefined" ? categoriesData : []) || []).filter(function (c) { return c.id === id; })[0] || { id: id, name: id, icon: 'ph-hammer' }; }
function fusion(d) {
var pro = {}; d.profiles.forEach(function (p) { pro[p.id] = p; });
var neuf = false;
var modele = (runners || [])[0] || {};
d.ads.forEach(function (a) {
var k = 'a' + a.id; if (vus[k]) return; var p = pro[a.profile_id]; if (!p) return; vus[k] = 1; neuf = true;
var c = categorie(a.category), nom = p.first + ' ' + p.last_initial + '. (fictif)';
var ref = (runners || []).filter(function (r) { return r.categoryId === a.category; })[0] || modele;
runners.push({
id: 900000 + a.id, name: nom, firstName: p.first, lastName: p.last_initial, fullName: nom, title: a.title,
categoryId: c.id, categoryName: c.name, categoryIcon: c.icon, rating: '4.5', reviews: 0, reviewsList: [],
price: a.price, time: a.unit, passType: 'lite', sellerType: 'particulier', isRecommended: false,
city: p.city, cluster: p.city, department: p.dept, region: p.region, distanceKm: 3, location: p.city + ' (3 km)',
avatar: '/__beta/avatar/' + p.seed + '.svg', jobImage: ref.jobImage, hasShort: false, shortVideo: null, likes: 0,
desc: '[PROFIL FICTIF] ' + a.descr, isDemo: true
});
});
d.convs.forEach(function (cv) {
var p = pro[cv.profile_id]; if (!p) return;
var id = 900000 + cv.id, existante = conversations.filter(function (x) { return x.id === id; })[0];
var nom = p.first + ' ' + p.last_initial + '. (fictif)';
if (!existante) {
existante = { id: id, runnerId: 0, name: nom, avatar: '/__beta/avatar/' + p.seed + '.svg', lastMsg: '', time: "À l'instant",
timestamp: Date.now(), unread: true, messages: [], demoCount: 0, isDemo: true };
if (cv.status === 'proposed') existante.contract = { status: 'proposed', title: cv.title, amount: cv.amount,
runnerAccepted: true, clientAccepted: false, runnerDone: false, clientDone: false };
conversations.unshift(existante); neuf = true;
}
cv.messages.slice(existante.demoCount).forEach(function (m) {
existante.messages.push({ sender: m.sender === 'me' ? 'me' : 'them', text: m.text });
existante.lastMsg = m.text; existante.unread = true; existante.timestamp = Date.now(); neuf = true;
});
existante.demoCount = cv.messages.length;
});
var a = document.getElementById('jrb-activite');
if (a && d.activity.length) { a.textContent = ''; a.appendChild(el('b', {}, 'Activité des bots')); d.activity.slice(0, 4).forEach(function (x) { a.appendChild(el('div', {}, '• ' + x.text)); }); a.className = 'on'; }
if (neuf) rafraichir();
}
function rafraichir() {
try {
if (typeof window.updateHomeRecs === 'function') window.updateHomeRecs();
if (typeof window.displaySearchResults === 'function') window.displaySearchResults(runners, 'Toutes les annonces');
if (typeof window.sortConversations === 'function') window.sortConversations();
if (typeof window.renderMessagesList === 'function') window.renderMessagesList();
if (typeof window.updateMessagesNotification === 'function') window.updateMessagesNotification();
} catch (e) { /* l'application reste utilisable sans la démo */ }
}
function charger() {
if (typeof runners === "undefined" || typeof conversations === "undefined") return;
fetch('/__beta/api/demo', { credentials: 'same-origin' }).then(function (r) { return r.ok ? r.json() : null; }).then(function (d) { if (d) fusion(d); }).catch(function () {});
}
// --- « Donner mon avis » ---
var cap = null;
var btn = el('button', { id: 'jrb-avis-btn', type: 'button' }, 'Donner mon avis');
var fond = el('div', { id: 'jrb-fond' });
var fen = el('div', { id: 'jrb-fen', role: 'dialog', 'aria-modal': 'true', 'aria-labelledby': 'jrb-t' });
fen.innerHTML = '<h2 id="jrb-t">Votre avis</h2><p>Dites-nous ce qu\'il faut garder ou changer sur cette page. Vos retours restent dans la bêta.</p>' +
'<select id="jrb-kind" aria-label="Type de retour"><option value="changer">À changer</option><option value="garder">À garder</option><option value="bug">Problème / bug</option><option value="autre">Autre</option></select>' +
'<textarea id="jrb-txt" maxlength="4000" placeholder="Votre message" aria-label="Votre message"></textarea>' +
'<div class="ligne"><label style="font-size:13px">Capture (facultatif) <input id="jrb-file" type="file" accept="image/png,image/jpeg,image/webp"></label>' +
'<button id="jrb-capt" type="button">Capturer l\'écran</button></div><img id="jrb-vignette" alt="Aperçu de la capture">' +
'<div class="ligne"><button id="jrb-envoyer" type="button">Envoyer</button><button id="jrb-fermer" type="button">Annuler</button></div><div id="jrb-etat" role="status"></div>';
fond.appendChild(fen);
var act = el('div', { id: 'jrb-activite' });
document.body.appendChild(btn); document.body.appendChild(fond); document.body.appendChild(act);
function $(i) { return document.getElementById(i); }
function ouvrir() { fond.className = 'on'; $('jrb-etat').textContent = ''; $('jrb-txt').focus(); }
function fermer() { fond.className = ''; cap = null; $('jrb-vignette').style.display = 'none'; $('jrb-txt').value = ''; $('jrb-file').value = ''; }
btn.onclick = ouvrir; $('jrb-fermer').onclick = fermer;
document.addEventListener('keydown', function (e) { if (e.key === 'Escape' && fond.className) fermer(); });
function reduire(src, cb) {
var im = new Image(); im.onload = function () {
var w = Math.min(1280, im.width), h = Math.round(im.height * w / im.width), c = document.createElement('canvas'); c.width = w; c.height = h;
c.getContext('2d').drawImage(im, 0, 0, w, h); cb(c.toDataURL('image/jpeg', 0.7));
}; im.src = src;
}
function pose(data) { cap = data; var v = $('jrb-vignette'); v.src = data; v.style.display = 'block'; }
$('jrb-file').onchange = function () {
var f = this.files[0]; if (!f) return; var r = new FileReader();
r.onload = function () { reduire(r.result, pose); }; r.readAsDataURL(f);
};
$('jrb-capt').onclick = function () { // capture d'écran navigateur (si pris en charge)
if (!navigator.mediaDevices || !navigator.mediaDevices.getDisplayMedia) { $('jrb-etat').textContent = 'Capture non disponible ici : joignez une image.'; return; }
fond.style.visibility = 'hidden';
navigator.mediaDevices.getDisplayMedia({ video: true, preferCurrentTab: true }).then(function (s) {
var v = document.createElement('video'); v.srcObject = s;
v.onloadedmetadata = function () { v.play().then(function () { setTimeout(function () {
var c = document.createElement('canvas'); c.width = v.videoWidth; c.height = v.videoHeight; c.getContext('2d').drawImage(v, 0, 0);
s.getTracks().forEach(function (t) { t.stop(); }); fond.style.visibility = ''; reduire(c.toDataURL('image/png'), pose); }, 300); }); };
}).catch(function () { fond.style.visibility = ''; $('jrb-etat').textContent = 'Capture annulée.'; });
};
$('jrb-envoyer').onclick = function () {
var t = $('jrb-txt').value.trim(); var st = $('jrb-etat');
if (t.length < 3) { st.textContent = 'Écrivez quelques mots.'; return; }
this.disabled = true; var me = this;
fetch('/__beta/api/feedback', { method: 'POST', headers: H, credentials: 'same-origin', body: JSON.stringify({
text: t, kind: $('jrb-kind').value, page: location.pathname + location.hash, viewport: innerWidth + 'x' + innerHeight, screenshot: cap }) })
.then(function (r) { return r.json().then(function (d) { return [r.ok, d]; }); })
.then(function (x) { me.disabled = false; if (x[0]) { st.textContent = 'Merci ! Retour enregistré.'; setTimeout(fermer, 1200); } else st.textContent = x[1].erreur || 'Échec.'; })
.catch(function () { me.disabled = false; st.textContent = 'Connexion impossible.'; });
};
window.addEventListener('load', function () { simules(); charger(); setInterval(function () { simules(); charger(); }, 20000); });
document.addEventListener('click', function () { setTimeout(simules, 50); }, true);
})();