Files
html/api/ambre-v10-san.php
2026-04-22 03:40:02 +02:00

65 lines
3.2 KiB
PHP

<?php
header("Content-Type: application/json");
$path = "/var/www/html/wevia.html";
$c = @file_get_contents($path);
$orig = strlen($c);
// Add sanitize step in the V10 render setTimeout
$old = 'setTimeout(function(){
try {
if (window.mermaid && typeof window.mermaid.run === "function") {
window.mermaid.run({ nodes: [document.getElementById(uniqId)] });
}';
$new = 'setTimeout(function(){
try {
var target = document.getElementById(uniqId);
if (!target) return;
// Sanitize mermaid code (strip accents, fix common LLM mistakes)
var clean = mcode
.replace(/[àâä]/g, "a").replace(/[éèêë]/g, "e").replace(/[îï]/g, "i")
.replace(/[ôö]/g, "o").replace(/[ùûü]/g, "u").replace(/ç/g, "c")
.replace(/[ÀÂÄ]/g, "A").replace(/[ÉÈÊË]/g, "E").replace(/[ÎÏ]/g, "I")
.replace(/[ÔÖ]/g, "O").replace(/[ÙÛÜ]/g, "U").replace(/Ç/g, "C")
.trim();
// Use mermaid.render for SVG direct return (bypass font-size:0 CSS issue)
if (window.mermaid && typeof window.mermaid.render === "function") {
window.mermaid.render("svg-" + uniqId, clean).then(function(result){
if (result && result.svg) {
target.innerHTML = result.svg;
target.className = "mermaid-rendered";
target.removeAttribute("data-processed");
// Force SVG to reasonable size
var svg = target.querySelector("svg");
if (svg) {
svg.style.maxWidth = "100%";
svg.style.height = "auto";
svg.style.minHeight = "180px";
svg.removeAttribute("width");
svg.style.width = "100%";
}
}
}).catch(function(err){
console.warn("mermaid render err", err);
target.innerHTML = "<pre style=\"font-size:12px;padding:10px;background:#f5f5f5;border-radius:6px\">" + clean.replace(/</g,"&lt;") + "</pre>";
});
} else if (window.mermaid && typeof window.mermaid.run === "function") {
target.className = "mermaid";
target.textContent = clean;
window.mermaid.run({ nodes: [target] });
}';
if (strpos($c, $old) === false) {
echo json_encode(["error"=>"pattern not found"]);
exit;
}
$c = str_replace($old, $new, $c);
$backup = "/opt/wevads/vault/wevia.html.GOLD-" . date("Ymd-His") . "-v10-sanitize";
@copy($path, $backup);
$wrote = @file_put_contents($path, $c);
echo json_encode([
"delta" => strlen($c) - $orig,
"wrote" => $wrote,
]);