76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""V112 - Fix pushBladeTask: ensure log visible + force display + debug"""
|
|
path = "/var/www/html/all-ia-hub.html"
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
c = f.read()
|
|
|
|
if "V112-BLADE-FIX" in c:
|
|
print("ALREADY")
|
|
exit(0)
|
|
|
|
# Replace the pushBladeTask function with a more robust version
|
|
old = """async function pushBladeTask(goal, params){
|
|
const log=document.getElementById('blade-log');
|
|
if(log){log.style.display='block';log.innerHTML+='\\n> Pushing task: '+goal+'...';}
|
|
try{
|
|
const fd=new FormData();
|
|
fd.append('k','WEVADS2026');
|
|
fd.append('action','create');
|
|
fd.append('goal',goal);
|
|
fd.append('params',JSON.stringify(params||{}));
|
|
const r=await fetch('/api/blade-task-create.php',{method:'POST',body:fd});
|
|
const d=await r.json();
|
|
if(log){log.innerHTML+='\\n> '+(d.ok?'\\u2705 Task created: '+d.id:'\\u274c '+(d.error||'failed'));log.scrollTop=log.scrollHeight;}
|
|
setTimeout(refreshBladeStats,500);
|
|
}catch(e){
|
|
if(log) log.innerHTML+='\\n> \\u274c Error: '+e.message;
|
|
}
|
|
}"""
|
|
|
|
new = """// V112-BLADE-FIX: robust pushBladeTask with urlencoded body + visible log + debug
|
|
async function pushBladeTask(goal, params){
|
|
const log=document.getElementById('blade-log');
|
|
if(log){
|
|
log.style.display='block';
|
|
log.style.maxHeight='200px';
|
|
log.innerHTML += '<div>> Pushing task: '+goal+'...</div>';
|
|
log.scrollTop = log.scrollHeight;
|
|
}
|
|
console.log('[pushBladeTask] goal=',goal,'params=',params);
|
|
try{
|
|
// Use URL-encoded instead of FormData for php $_POST compatibility
|
|
const body = 'k=WEVADS2026&action=create&goal='+encodeURIComponent(goal)+'¶ms='+encodeURIComponent(JSON.stringify(params||{}));
|
|
const r = await fetch('/api/blade-task-create.php',{
|
|
method:'POST',
|
|
headers:{'Content-Type':'application/x-www-form-urlencoded'},
|
|
body: body
|
|
});
|
|
const txt = await r.text();
|
|
let d;
|
|
try{ d = JSON.parse(txt); }catch(e){ d = {error:'parse failed: '+txt.substring(0,100)}; }
|
|
console.log('[pushBladeTask] response=',d);
|
|
if(log){
|
|
if(d.ok){
|
|
log.innerHTML += '<div style=\"color:var(--gr)\">> \\u2705 Task created: '+d.id+'</div>';
|
|
} else {
|
|
log.innerHTML += '<div style=\"color:var(--rd)\">> \\u274c '+(d.error||'failed')+'</div>';
|
|
}
|
|
log.scrollTop = log.scrollHeight;
|
|
}
|
|
setTimeout(refreshBladeStats, 500);
|
|
} catch(e){
|
|
console.error('[pushBladeTask] error=',e);
|
|
if(log){
|
|
log.innerHTML += '<div style=\"color:var(--rd)\">> \\u274c Error: '+e.message+'</div>';
|
|
log.scrollTop = log.scrollHeight;
|
|
}
|
|
}
|
|
}"""
|
|
|
|
assert old in c, "old pushBladeTask NOT FOUND"
|
|
c = c.replace(old, new, 1)
|
|
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
f.write(c)
|
|
print(f"PATCHED size={len(c)}")
|