Update WebUI design
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>go2rtc - Config</title>
|
||||
<script src="https://unpkg.com/ace-builds@1.33.1/src-min/ace.js"></script>
|
||||
<style>
|
||||
html, body, #config {
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script src="main.js"></script>
|
||||
|
||||
<main>
|
||||
<div>
|
||||
<button id="save">Save & Restart</button>
|
||||
</div>
|
||||
</main>
|
||||
<div id="config"></div>
|
||||
|
||||
<script>
|
||||
/* global ace */
|
||||
ace.config.set('basePath', 'https://unpkg.com/ace-builds@1.33.1/src-min/');
|
||||
const editor = ace.edit('config', {
|
||||
mode: 'ace/mode/yaml',
|
||||
});
|
||||
|
||||
let dump;
|
||||
|
||||
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');
|
||||
dump = editor.getValue();
|
||||
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>
|
||||
Reference in New Issue
Block a user