[feature] Add info/config handler

This commit is contained in:
Sergey Konovalov
2025-05-22 17:29:03 +03:00
parent 0ed4ddc2ce
commit 15338bb458
3 changed files with 139 additions and 0 deletions

View File

@ -539,6 +539,40 @@
document.querySelector('.td-link[value=' + value + ']').classList.add('current');
}
function getConfig() {
const baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1);
return fetch(baseUrl + 'config')
.then(response => {
if (!response.ok) throw new Error(`Failed to load: ${response.status}`);
return response.json();
})
.catch(error => {
console.error('Error fetching config:', error);
return null;
});
}
function putConfig(config) {
const baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf('/') + 1);
return fetch(baseUrl + 'config', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(config)
})
.then(response => {
if (!response.ok) throw new Error(`Failed to save: ${response.status}`);
console.log('Configuration saved successfully');
})
.catch(error => {
console.error('Error fetching config:', error);
});
}
function updateConfig() {
getConfig().then(config => {
config.field = 'value';
putConfig(config);
});
}
(function(){
try {
var xhrObj = _createXMLHTTPObject();
@ -557,6 +591,7 @@
fillStatistic(info);
initEvents();
applyMode();
//updateConfig();
} else {
document.getElementById('doc-server-err').classList.remove("hidden");
}