Files
go2rtc/www/editor.html
T

79 lines
2.8 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>go2rtc - File Editor</title>
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1, maximum-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="apple-touch-icon" sizes="180x180" href="https://alexxit.github.io/go2rtc/icons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="https://alexxit.github.io/go2rtc/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="https://alexxit.github.io/go2rtc/icons/favicon-16x16.png">
<link rel="manifest" href="https://alexxit.github.io/go2rtc/icons/site.webmanifest">
<link rel="mask-icon" href="https://alexxit.github.io/go2rtc/icons/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="https://alexxit.github.io/go2rtc/icons/favicon.ico">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-config" content="https://alexxit.github.io/go2rtc/icons/browserconfig.xml">
<script src="https://unpkg.com/ace-builds@1.33.0/src-min/ace.js"></script>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: white;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
}
html, body, #config {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<script src="main.js"></script>
<div>
<button id="save">Save & Restart</button>
</div>
<br>
<div id="config"></div>
<script>
let dump;
ace.config.set('basePath', 'https://unpkg.com/ace-builds@1.33.0/src-min/');
const editor = ace.edit('config', {
mode: 'ace/mode/yaml',
});
document.getElementById('save').addEventListener('click', async () => {
let r = await fetch('api/config', {cache: 'no-cache'});
if (r.ok && dump !== await r.text()) {
alert('Config was changed from another place. Refresh the page and make changes again');
return;
}
r = await fetch('api/config', {method: 'POST', body: editor.getValue()});
if (r.ok) {
alert('OK');
await fetch('api/restart', {method: 'POST'});
} else {
alert(await r.text());
}
});
window.addEventListener('load', async () => {
const r = await fetch('api/config', {cache: 'no-cache'});
if (r.status === 410) {
alert('Config file is not set');
} else if (r.status === 404) {
editor.setValue(''); // config file not exist
} else if (r.ok) {
dump = await r.text();
editor.setValue(dump);
} else {
alert(`Unknown error: ${r.statusText} (${r.status})`);
}
});
</script>
</body>
</html>