Files
html/api/ambre-sse-fix.php
2026-04-22 02:30:04 +02:00

52 lines
1.7 KiB
PHP

<?php
header("Content-Type: application/json");
$path = "/var/www/html/js/wevia-sse-override.js";
if (!file_exists($path)) {
// Try alternate location
$alt = "/var/www/html/wevia-sse-override.js";
if (file_exists($alt)) $path = $alt;
}
$content = @file_get_contents($path);
if (!$content) { echo json_encode(["error"=>"file not found", "path"=>$path]); exit; }
$orig_size = strlen($content);
// The bug: regex literal /\n/g split by an actual newline
// Replace with proper string-based approach
$old = "last.innerHTML = fullText.replace(/\n/g, '<br>');";
$new = "last.innerHTML = fullText.split(String.fromCharCode(10)).join('<br>');";
$pos = strpos($content, $old);
if ($pos === false) {
// Try alternate without leading spaces
$old2 = "fullText.replace(/\n/g, '<br>');";
$new2 = "fullText.split(String.fromCharCode(10)).join('<br>');";
if (strpos($content, $old2) !== false) {
$new_content = str_replace($old2, $new2, $content);
} else {
echo json_encode(["error"=>"pattern not found", "path"=>$path, "size"=>$orig_size, "snippet_around_47" => substr($content, 1800, 400)]);
exit;
}
} else {
$new_content = str_replace($old, $new, $content);
}
// Backup + write
$backup = "/opt/wevads/vault/wevia-sse-override.js.GOLD-" . date("Ymd-His");
@copy($path, $backup);
$wrote = @file_put_contents($path, $new_content);
// Lint
$lint = @shell_exec("node --check $path 2>&1");
echo json_encode([
"path" => $path,
"orig_size" => $orig_size,
"new_size" => strlen($new_content),
"delta" => strlen($new_content) - $orig_size,
"wrote" => $wrote,
"backup" => basename($backup),
"lint" => trim($lint) ?: "OK",
]);