Synology diskstation widget: code cleanup

This commit is contained in:
Benoit 2023-01-03 14:20:53 +01:00
parent 46b98dbe67
commit 2401312869

View File

@ -77,28 +77,23 @@ export default async function synologyProxyHandler(req, res) {
let usedVolume = 0;
if (status !== 200) {
return res.status(status).set("Content-Type", contentType).send(data);
} else {
const json=JSON.parse(data.toString());
if (json?.success !== true) {
return res.status(401).json({ error: "Error getting volume stats" });
} else {
usedVolume = 100 * parseFloat(json.data.vol_info[0].used_size) / parseFloat(json.data.vol_info[0].total_size);
}
}
let uptime = "Unknown";
let json=JSON.parse(data.toString());
if (json?.success !== true) {
return res.status(401).json({ error: "Error getting volume stats" });
}
usedVolume = 100 * parseFloat(json.data.vol_info[0].used_size) / parseFloat(json.data.vol_info[0].total_size);
const healthUrl = `${widget.url}/webapi/${path}?api=${api}&version=${maxVersion}&method=info&_sid=${sid}`;
[status, contentType, data] = await httpProxy(healthUrl);
if (status !== 200) {
return res.status(status).set("Content-Type", contentType).send(data);
} else {
const json=JSON.parse(data.toString());
if (json?.success !== true) {
return res.status(401).json({ error: "Error getting uptime" });
} else {
uptime = formatUptime(json.data.up_time);
}
}
json=JSON.parse(data.toString());
if (json?.success !== true) {
return res.status(401).json({ error: "Error getting uptime" });
}
const uptime = formatUptime(json.data.up_time);
const resdata = {
uptime,