2021-10-19 18:32:37 +00:00
|
|
|
|
2021-10-20 10:20:14 +00:00
|
|
|
window.ToolIsFollow = false;
|
|
|
|
|
|
|
|
async function FileGet(follower=false){
|
|
|
|
let f = ''
|
|
|
|
if (Active == 'ConfigUI') {
|
|
|
|
if (follower) f = '?f=true'
|
|
|
|
const res = await fetch('/api/conf'+f);
|
|
|
|
const body = await res.text();
|
2021-10-20 15:51:39 +00:00
|
|
|
if(!res.ok){
|
|
|
|
handleError(res)
|
|
|
|
return
|
|
|
|
}
|
2021-10-20 10:20:14 +00:00
|
|
|
editor.session.setValue(body);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (follower) f = '&f=true'
|
|
|
|
const res = await fetch('/api/file?name=' + Active + f);
|
|
|
|
const body = await res.json();
|
2021-10-20 15:51:39 +00:00
|
|
|
if(!res.ok){
|
|
|
|
handleError(res)
|
|
|
|
return
|
|
|
|
}
|
2021-10-20 10:20:14 +00:00
|
|
|
editor.session.setValue(body.data);
|
2021-10-19 18:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 10:20:14 +00:00
|
|
|
async function FileSave(){
|
|
|
|
if (Active == 'ConfigUI') {
|
|
|
|
const res = await fetch('/api/conf', {
|
|
|
|
method: 'POST',
|
|
|
|
body: editor.getValue(),
|
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
})
|
|
|
|
})
|
2021-10-20 14:02:10 +00:00
|
|
|
if (res.ok) window.location.reload();
|
2021-10-20 15:51:39 +00:00
|
|
|
else handleError(res)
|
2021-10-20 10:20:14 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
const res = await fetch('/api/file', {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({"name":Active,"data":editor.getValue()}),
|
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
})
|
|
|
|
})
|
2021-10-20 15:51:39 +00:00
|
|
|
if(!res.ok) handleError(res)
|
2021-10-20 10:20:14 +00:00
|
|
|
}
|
2021-10-19 18:32:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 10:20:14 +00:00
|
|
|
async function FileApply(){
|
|
|
|
if (Active == 'ConfigUI') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const res = await fetch('/api/apply?name='+ Active, {
|
|
|
|
method: 'POST',
|
|
|
|
})
|
2021-10-20 15:51:39 +00:00
|
|
|
if(!res.ok){
|
|
|
|
handleError(res)
|
|
|
|
return
|
|
|
|
}
|
2021-10-20 10:20:14 +00:00
|
|
|
const result = await res.text()
|
|
|
|
result_editor.session.setValue(result)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 15:51:39 +00:00
|
|
|
async function handleError(res){
|
|
|
|
const msg = await res.text()
|
|
|
|
ShowError(msg)
|
|
|
|
}
|
|
|
|
|
2021-10-20 10:20:14 +00:00
|
|
|
// starting point
|
2021-10-19 18:32:37 +00:00
|
|
|
(function(){
|
2021-10-20 10:20:14 +00:00
|
|
|
// setup ace editor
|
2021-10-19 18:32:37 +00:00
|
|
|
setEditor()
|
2021-10-20 10:20:14 +00:00
|
|
|
|
|
|
|
// setup result code block
|
|
|
|
setResult()
|
|
|
|
|
|
|
|
// for follow mode
|
|
|
|
setInterval((async ()=>{
|
|
|
|
if (ToolIsFollow){
|
|
|
|
await FileGet(true)
|
|
|
|
editor.gotoLine(editor.session.getLength());
|
|
|
|
}
|
|
|
|
}), 1000)
|
2021-10-19 18:32:37 +00:00
|
|
|
}())
|