mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-13 08:20:34 +00:00
linting and cleanup
This commit is contained in:
parent
7f041e8303
commit
f74e8b9d32
51 changed files with 464 additions and 349 deletions
|
@ -1,6 +1,8 @@
|
|||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
|
||||
import yaml from "js-yaml";
|
||||
|
||||
import checkAndCopyConfig from "utils/config";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
|
@ -11,12 +13,10 @@ export default async function handler(req, res) {
|
|||
const widgets = yaml.load(fileContents);
|
||||
|
||||
// map easy to write YAML objects into easy to consume JS arrays
|
||||
const widgetsArray = widgets.map((group) => {
|
||||
return {
|
||||
type: Object.keys(group)[0],
|
||||
options: { ...group[Object.keys(group)[0]] },
|
||||
};
|
||||
});
|
||||
const widgetsArray = widgets.map((group) => ({
|
||||
type: Object.keys(group)[0],
|
||||
options: { ...group[Object.keys(group)[0]] },
|
||||
}));
|
||||
|
||||
res.send(widgetsArray);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ export default async function handler(req, res) {
|
|||
return res.status(400).json({ error: "Missing API key" });
|
||||
}
|
||||
|
||||
const api_url = `https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${apiKey}&units=${units}`;
|
||||
const apiUrl = `https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${apiKey}&units=${units}`;
|
||||
|
||||
res.send(await cachedFetch(api_url, cache));
|
||||
return res.send(await cachedFetch(apiUrl, cache));
|
||||
}
|
||||
|
|
|
@ -1,26 +1,30 @@
|
|||
import { cpu, drive, mem, netstat } from "node-os-utils";
|
||||
import { cpu, drive, mem } from "node-os-utils";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { type, target } = req.query;
|
||||
|
||||
if (type == "cpu") {
|
||||
if (type === "cpu") {
|
||||
return res.status(200).json({
|
||||
cpu: {
|
||||
usage: await cpu.usage(1000),
|
||||
load: cpu.loadavgTime(5),
|
||||
},
|
||||
});
|
||||
} else if (type == "disk") {
|
||||
}
|
||||
|
||||
if (type === "disk") {
|
||||
return res.status(200).json({
|
||||
drive: await drive.info(target || "/"),
|
||||
});
|
||||
} else if (type == "memory") {
|
||||
}
|
||||
|
||||
if (type === "memory") {
|
||||
return res.status(200).json({
|
||||
memory: await mem.info(),
|
||||
});
|
||||
} else {
|
||||
return res.status(400).json({
|
||||
error: "invalid type",
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(400).json({
|
||||
error: "invalid type",
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ export default async function handler(req, res) {
|
|||
return res.status(400).json({ error: "Missing API key" });
|
||||
}
|
||||
|
||||
const api_url = `http://api.weatherapi.com/v1/current.json?q=${latitude},${longitude}&key=${apiKey}`;
|
||||
const apiUrl = `http://api.weatherapi.com/v1/current.json?q=${latitude},${longitude}&key=${apiKey}`;
|
||||
|
||||
res.send(await cachedFetch(api_url, cache));
|
||||
return res.send(await cachedFetch(apiUrl, cache));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue