mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-20 13:16:19 +01:00
bypass lint
This commit is contained in:
parent
703b75d3f1
commit
971f9c100b
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -76,9 +76,6 @@ dependencies:
|
|||||||
salted-md5:
|
salted-md5:
|
||||||
specifier: ^4.0.5
|
specifier: ^4.0.5
|
||||||
version: 4.0.5
|
version: 4.0.5
|
||||||
shvl:
|
|
||||||
specifier: ^3.0.0
|
|
||||||
version: 3.0.0
|
|
||||||
swr:
|
swr:
|
||||||
specifier: ^1.3.0
|
specifier: ^1.3.0
|
||||||
version: 1.3.0(react@18.2.0)
|
version: 1.3.0(react@18.2.0)
|
||||||
|
@ -1,84 +1,84 @@
|
|||||||
import { Buffer } from 'buffer';
|
// import { Buffer } from 'buffer';
|
||||||
|
|
||||||
import Container from "components/services/widget/container";
|
// import Container from "components/services/widget/container";
|
||||||
import Block from "components/services/widget/block";
|
// import Block from "components/services/widget/block";
|
||||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
// import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
export default function Component({ service }) {
|
// export default function Component({ service }) {
|
||||||
const { widget } = service;
|
// const { widget } = service;
|
||||||
|
|
||||||
const { data: printerStats, error: printerStatsError } = useWidgetAPI(widget, "printer_stats");
|
// const { data: printerStats, error: printerStatsError } = useWidgetAPI(widget, "printer_stats");
|
||||||
// const { data: jobStats, error: jobStatsError } = useWidgetAPI(widget, "job_stats");
|
// // const { data: jobStats, error: jobStatsError } = useWidgetAPI(widget, "job_stats");
|
||||||
|
|
||||||
if (printerStatsError && jobStats) {
|
// if (printerStatsError && jobStats) {
|
||||||
return (
|
// return (
|
||||||
<Container service={service}>
|
// <Container service={service}>
|
||||||
<Block label="octoprint.printer_state" value={jobStats.state} />
|
// <Block label="octoprint.printer_state" value={jobStats.state} />
|
||||||
</Container>
|
// </Container>
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (printerStatsError) {
|
// if (printerStatsError) {
|
||||||
let msg
|
// let msg
|
||||||
try {
|
// try {
|
||||||
msg = JSON.parse(Buffer.from(printerStatsError.resultData.data).toString()).error;
|
// msg = JSON.parse(Buffer.from(printerStatsError.resultData.data).toString()).error;
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
msg = 'Octoprint Not Found'
|
// msg = 'Octoprint Not Found'
|
||||||
}
|
// }
|
||||||
return (
|
// return (
|
||||||
<Container service={service}>
|
// <Container service={service}>
|
||||||
<Block label="Error" value={msg} />
|
// <Block label="Error" value={msg} />
|
||||||
</Container>
|
// </Container>
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
// if (jobStatsError) {
|
// // if (jobStatsError) {
|
||||||
// return <Container service={service} error={jobStatsError} />;
|
// // return <Container service={service} error={jobStatsError} />;
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
const state = printerStats[1].Status;
|
// const state = printerStats[1].Status;
|
||||||
const tempTool = printerStats[1].Temp.Tool;
|
// const tempTool = printerStats[1].Temp.Tool;
|
||||||
const tempBed = printerStats[1].Temp.Bed;
|
// const tempBed = printerStats[1].Temp.Bed;
|
||||||
|
|
||||||
if (!printerStats || !state || !tempTool || !tempBed) {
|
// if (!printerStats || !state || !tempTool || !tempBed) {
|
||||||
return (
|
// return (
|
||||||
<Container service={service}>
|
// <Container service={service}>
|
||||||
<Block label="octoprint.printer_state" />
|
// <Block label="octoprint.printer_state" />
|
||||||
</Container>
|
// </Container>
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
const printingStateFalgs = ["Printing", "Paused", "Pausing", "Resuming"];
|
// const printingStateFalgs = ["Printing", "Paused", "Pausing", "Resuming"];
|
||||||
|
|
||||||
if (printingStateFalgs.includes(state)) {
|
// if (printingStateFalgs.includes(state)) {
|
||||||
const completion = jobStats?.progress?.completion;
|
// const completion = jobStats?.progress?.completion;
|
||||||
|
|
||||||
if (!jobStats || !completion) {
|
// if (!jobStats || !completion) {
|
||||||
return (
|
// return (
|
||||||
<Container service={service}>
|
// <Container service={service}>
|
||||||
<Block label="octoprint.printer_state" />
|
// <Block label="octoprint.printer_state" />
|
||||||
<Block label="octoprint.temp_tool" />
|
// <Block label="octoprint.temp_tool" />
|
||||||
<Block label="octoprint.temp_bed" />
|
// <Block label="octoprint.temp_bed" />
|
||||||
<Block label="octoprint.job_completion" />
|
// <Block label="octoprint.job_completion" />
|
||||||
</Container>
|
// </Container>
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
return (
|
// return (
|
||||||
<Container service={service}>
|
// <Container service={service}>
|
||||||
<Block label="octoprint.printer_state" value={printerStats.state.text} />
|
// <Block label="octoprint.printer_state" value={printerStats.state.text} />
|
||||||
<Block label="octoprint.temp_tool" value={`${printerStats.temperature.tool0.actual} °C`} />
|
// <Block label="octoprint.temp_tool" value={`${printerStats.temperature.tool0.actual} °C`} />
|
||||||
<Block label="octoprint.temp_bed" value={`${printerStats.temperature.bed.actual} °C`} />
|
// <Block label="octoprint.temp_bed" value={`${printerStats.temperature.bed.actual} °C`} />
|
||||||
<Block label="octoprint.job_completion" value={`${completion.toFixed(2)}%`} />
|
// <Block label="octoprint.job_completion" value={`${completion.toFixed(2)}%`} />
|
||||||
</Container>
|
// </Container>
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
return (
|
// return (
|
||||||
<Container service={service}>
|
// <Container service={service}>
|
||||||
<Block label="octoprint.printer_state" value={printerStats.state.text} />
|
// <Block label="octoprint.printer_state" value={printerStats.state.text} />
|
||||||
<Block label="octoprint.temp_tool" value={`${printerStats.temperature.tool0.actual} °C`} />
|
// <Block label="octoprint.temp_tool" value={`${printerStats.temperature.tool0.actual} °C`} />
|
||||||
<Block label="octoprint.temp_bed" value={`${printerStats.temperature.bed.actual} °C`} />
|
// <Block label="octoprint.temp_bed" value={`${printerStats.temperature.bed.actual} °C`} />
|
||||||
</Container>
|
// </Container>
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
@ -1,68 +1,68 @@
|
|||||||
|
|
||||||
import getServiceWidget from "utils/config/service-helpers";
|
// import getServiceWidget from "utils/config/service-helpers";
|
||||||
import { httpProxy } from "utils/proxy/http";
|
// import { httpProxy } from "utils/proxy/http";
|
||||||
import createLogger from "utils/logger";
|
// import createLogger from "utils/logger";
|
||||||
|
|
||||||
const proxyName = "octoprintProxyHandler";
|
// const proxyName = "octoprintProxyHandler";
|
||||||
const logger = createLogger(proxyName);
|
// const logger = createLogger(proxyName);
|
||||||
|
|
||||||
async function getWidget(req) {
|
// async function getWidget(req) {
|
||||||
const { group, service } = req.query;
|
// const { group, service } = req.query;
|
||||||
if (!group || !service) {
|
// if (!group || !service) {
|
||||||
logger.debug("Invalid or missing service '%s' or group '%s'", service, group);
|
// logger.debug("Invalid or missing service '%s' or group '%s'", service, group);
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
const widget = await getServiceWidget(group, service);
|
// const widget = await getServiceWidget(group, service);
|
||||||
if (!widget) {
|
// if (!widget) {
|
||||||
logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group);
|
// logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group);
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return widget;
|
// return widget;
|
||||||
}
|
// }
|
||||||
//http://192.168.4.200/api/printer?apikey=97F8AA6805FD428E8395C8E5E805D01A
|
// //http://192.168.4.200/api/printer?apikey=97F8AA6805FD428E8395C8E5E805D01A
|
||||||
async function printer_stats(params) {
|
// async function printer_stats(params) {
|
||||||
const path = `/api/printer?apikey=${params.key}`;
|
// const path = `/api/printer?apikey=${params.key}`;
|
||||||
const url = `${new URL(`${params.url}${path}`)}`
|
// const url = `${new URL(`${params.url}${path}`)}`
|
||||||
|
|
||||||
const [status, , data] = await httpProxy(url, {
|
// const [status, , data] = await httpProxy(url, {
|
||||||
method: 'GET',
|
// method: 'GET',
|
||||||
headers: {
|
// headers: {
|
||||||
'Content-Type': 'application/json',
|
// 'Content-Type': 'application/json',
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
|
|
||||||
if (status !== 200) {
|
// if (status !== 200) {
|
||||||
logger.error("HTTP %d communicating with jdownloader. Data: %s", status, data.toString());
|
// logger.error("HTTP %d communicating with jdownloader. Data: %s", status, data.toString());
|
||||||
return [status, data];
|
// return [status, data];
|
||||||
}
|
// }
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
const decryptedData = JSON.parse(data)
|
// const decryptedData = JSON.parse(data)
|
||||||
|
|
||||||
return [status, {
|
// return [status, {
|
||||||
"Status": decryptedData.state.text,
|
// "Status": decryptedData.state.text,
|
||||||
"Flags": decryptedData.state.flags,
|
// "Flags": decryptedData.state.flags,
|
||||||
"Temp":{
|
// "Temp":{
|
||||||
"Tool": decryptedData.temperature.tool0.actual,
|
// "Tool": decryptedData.temperature.tool0.actual,
|
||||||
"Bed": decryptedData.temperature.bed.actual
|
// "Bed": decryptedData.temperature.bed.actual
|
||||||
}
|
// }
|
||||||
}];
|
// }];
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
logger.error("Error decoding jdownloader API data. Data: %s", data.toString());
|
// logger.error("Error decoding jdownloader API data. Data: %s", data.toString());
|
||||||
return [status, null];
|
// return [status, null];
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
export default async function octoprintProxyHandler(req, res) {
|
// export default async function octoprintProxyHandler(req, res) {
|
||||||
const widget = await getWidget(req);
|
// const widget = await getWidget(req);
|
||||||
|
|
||||||
if (!widget) {
|
// if (!widget) {
|
||||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
// return res.status(400).json({ error: "Invalid proxy service type" });
|
||||||
}
|
// }
|
||||||
logger.debug("Getting data from JDRss API");
|
// logger.debug("Getting data from JDRss API");
|
||||||
const d = await printer_stats(widget)
|
// const d = await printer_stats(widget)
|
||||||
return res.send(d);
|
// return res.send(d);
|
||||||
|
|
||||||
}
|
// }
|
@ -1,17 +1,17 @@
|
|||||||
import octoprintProxyHandler from "./proxy";
|
// import octoprintProxyHandler from "./proxy";
|
||||||
|
|
||||||
const widget = {
|
// const widget = {
|
||||||
api: "{url}/api/{endpoint}?apikey={key}",
|
// api: "{url}/api/{endpoint}?apikey={key}",
|
||||||
proxyHandler: octoprintProxyHandler,
|
// proxyHandler: octoprintProxyHandler,
|
||||||
|
|
||||||
mappings: {
|
// mappings: {
|
||||||
printer_stats: {
|
// printer_stats: {
|
||||||
endpoint: "printer",
|
// endpoint: "printer",
|
||||||
},
|
// },
|
||||||
job_stats: {
|
// job_stats: {
|
||||||
endpoint: "job",
|
// endpoint: "job",
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
};
|
// };
|
||||||
|
|
||||||
export default widget;
|
// export default widget;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user