mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-13 08:20:34 +00:00
first public source commit
This commit is contained in:
parent
1a4fbb9d42
commit
3914fee775
65 changed files with 4697 additions and 312 deletions
22
src/pages/api/widgets/index.js
Normal file
22
src/pages/api/widgets/index.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
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) {
|
||||
checkAndCopyConfig("widgets.yaml");
|
||||
|
||||
const widgetsYaml = path.join(process.cwd(), "config", "widgets.yaml");
|
||||
const fileContents = await fs.readFile(widgetsYaml, "utf8");
|
||||
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]] },
|
||||
};
|
||||
});
|
||||
|
||||
res.send(widgetsArray);
|
||||
}
|
14
src/pages/api/widgets/resources.js
Normal file
14
src/pages/api/widgets/resources.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { cpu, drive, mem, netstat } from "node-os-utils";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { disk } = req.query;
|
||||
|
||||
res.send({
|
||||
cpu: {
|
||||
usage: await cpu.usage(),
|
||||
load: cpu.loadavgTime(5),
|
||||
},
|
||||
drive: await drive.info(disk || "/"),
|
||||
memory: await mem.info(),
|
||||
});
|
||||
}
|
9
src/pages/api/widgets/weather.js
Normal file
9
src/pages/api/widgets/weather.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
import cachedFetch from "utils/cached-fetch";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { lat, lon, apiKey, duration } = req.query;
|
||||
|
||||
const api_url = `http://api.weatherapi.com/v1/current.json?q=${lat},${lon}&key=${apiKey}`;
|
||||
|
||||
res.send(await cachedFetch(api_url, duration));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue