mirror of
https://github.com/karl0ss/homepage.git
synced 2025-04-29 12:03:41 +01:00
revert octo
This commit is contained in:
parent
971f9c100b
commit
2a97128964
@ -1,84 +1,72 @@
|
|||||||
// import { Buffer } from 'buffer';
|
import Container from "components/services/widget/container";
|
||||||
|
import Block from "components/services/widget/block";
|
||||||
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
|
||||||
// import Container from "components/services/widget/container";
|
export default function Component({ service }) {
|
||||||
// import Block from "components/services/widget/block";
|
const { widget } = service;
|
||||||
// import useWidgetAPI from "utils/proxy/use-widget-api";
|
|
||||||
|
|
||||||
// export default function Component({ service }) {
|
const { data: printerStats, error: printerStatsError } = useWidgetAPI(widget, "printer_stats");
|
||||||
// const { widget } = service;
|
const { data: jobStats, error: jobStatsError } = useWidgetAPI(widget, "job_stats");
|
||||||
|
|
||||||
// const { data: printerStats, error: printerStatsError } = useWidgetAPI(widget, "printer_stats");
|
if (printerStatsError && jobStats) {
|
||||||
// // const { data: jobStats, error: jobStatsError } = useWidgetAPI(widget, "job_stats");
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="octoprint.printer_state" value={jobStats.state} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// if (printerStatsError && jobStats) {
|
if (printerStatsError) {
|
||||||
// return (
|
return <Container service={service} error={printerStatsError} />;
|
||||||
// <Container service={service}>
|
}
|
||||||
// <Block label="octoprint.printer_state" value={jobStats.state} />
|
|
||||||
// </Container>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (printerStatsError) {
|
if (jobStatsError) {
|
||||||
// let msg
|
return <Container service={service} error={jobStatsError} />;
|
||||||
// try {
|
}
|
||||||
// msg = JSON.parse(Buffer.from(printerStatsError.resultData.data).toString()).error;
|
|
||||||
// } catch (error) {
|
|
||||||
// msg = 'Octoprint Not Found'
|
|
||||||
// }
|
|
||||||
// return (
|
|
||||||
// <Container service={service}>
|
|
||||||
// <Block label="Error" value={msg} />
|
|
||||||
// </Container>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // if (jobStatsError) {
|
const state = printerStats?.state?.text;
|
||||||
// // return <Container service={service} error={jobStatsError} />;
|
const tempTool = printerStats?.temperature?.tool0?.actual;
|
||||||
// // }
|
const tempBed = printerStats?.temperature?.bed?.actual;
|
||||||
|
|
||||||
// const state = printerStats[1].Status;
|
if (!printerStats || !state || !tempTool || !tempBed) {
|
||||||
// const tempTool = printerStats[1].Temp.Tool;
|
return (
|
||||||
// const tempBed = printerStats[1].Temp.Bed;
|
<Container service={service}>
|
||||||
|
<Block label="octoprint.printer_state" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// if (!printerStats || !state || !tempTool || !tempBed) {
|
const printingStateFalgs = ["Printing", "Paused", "Pausing", "Resuming"];
|
||||||
// return (
|
|
||||||
// <Container service={service}>
|
|
||||||
// <Block label="octoprint.printer_state" />
|
|
||||||
// </Container>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const printingStateFalgs = ["Printing", "Paused", "Pausing", "Resuming"];
|
if (printingStateFalgs.includes(state)) {
|
||||||
|
const completion = jobStats?.progress?.completion;
|
||||||
|
|
||||||
// if (printingStateFalgs.includes(state)) {
|
if (!jobStats || !completion) {
|
||||||
// const completion = jobStats?.progress?.completion;
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="octoprint.printer_state" />
|
||||||
|
<Block label="octoprint.temp_tool" />
|
||||||
|
<Block label="octoprint.temp_bed" />
|
||||||
|
<Block label="octoprint.job_completion" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// if (!jobStats || !completion) {
|
return (
|
||||||
// return (
|
<Container service={service}>
|
||||||
// <Container service={service}>
|
<Block label="octoprint.printer_state" value={printerStats.state.text} />
|
||||||
// <Block label="octoprint.printer_state" />
|
<Block label="octoprint.temp_tool" value={`${printerStats.temperature.tool0.actual} °C`} />
|
||||||
// <Block label="octoprint.temp_tool" />
|
<Block label="octoprint.temp_bed" value={`${printerStats.temperature.bed.actual} °C`} />
|
||||||
// <Block label="octoprint.temp_bed" />
|
<Block label="octoprint.job_completion" value={`${completion.toFixed(2)}%`} />
|
||||||
// <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)}%`} />
|
</Container>
|
||||||
// </Container>
|
);
|
||||||
// );
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <Container service={service}>
|
|
||||||
// <Block label="octoprint.printer_state" value={printerStats.state.text} />
|
|
||||||
// <Block label="octoprint.temp_tool" value={`${printerStats.temperature.tool0.actual} °C`} />
|
|
||||||
// <Block label="octoprint.temp_bed" value={`${printerStats.temperature.bed.actual} °C`} />
|
|
||||||
// </Container>
|
|
||||||
// );
|
|
||||||
// }
|
|
@ -1,68 +0,0 @@
|
|||||||
|
|
||||||
// import getServiceWidget from "utils/config/service-helpers";
|
|
||||||
// import { httpProxy } from "utils/proxy/http";
|
|
||||||
// import createLogger from "utils/logger";
|
|
||||||
|
|
||||||
// const proxyName = "octoprintProxyHandler";
|
|
||||||
// const logger = createLogger(proxyName);
|
|
||||||
|
|
||||||
// async function getWidget(req) {
|
|
||||||
// const { group, service } = req.query;
|
|
||||||
// if (!group || !service) {
|
|
||||||
// logger.debug("Invalid or missing service '%s' or group '%s'", service, group);
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// const widget = await getServiceWidget(group, service);
|
|
||||||
// if (!widget) {
|
|
||||||
// logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group);
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return widget;
|
|
||||||
// }
|
|
||||||
// //http://192.168.4.200/api/printer?apikey=97F8AA6805FD428E8395C8E5E805D01A
|
|
||||||
// async function printer_stats(params) {
|
|
||||||
// const path = `/api/printer?apikey=${params.key}`;
|
|
||||||
// const url = `${new URL(`${params.url}${path}`)}`
|
|
||||||
|
|
||||||
// const [status, , data] = await httpProxy(url, {
|
|
||||||
// method: 'GET',
|
|
||||||
// headers: {
|
|
||||||
// 'Content-Type': 'application/json',
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// if (status !== 200) {
|
|
||||||
// logger.error("HTTP %d communicating with jdownloader. Data: %s", status, data.toString());
|
|
||||||
// return [status, data];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// const decryptedData = JSON.parse(data)
|
|
||||||
|
|
||||||
// return [status, {
|
|
||||||
// "Status": decryptedData.state.text,
|
|
||||||
// "Flags": decryptedData.state.flags,
|
|
||||||
// "Temp":{
|
|
||||||
// "Tool": decryptedData.temperature.tool0.actual,
|
|
||||||
// "Bed": decryptedData.temperature.bed.actual
|
|
||||||
// }
|
|
||||||
// }];
|
|
||||||
// } catch (e) {
|
|
||||||
// logger.error("Error decoding jdownloader API data. Data: %s", data.toString());
|
|
||||||
// return [status, null];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export default async function octoprintProxyHandler(req, res) {
|
|
||||||
// const widget = await getWidget(req);
|
|
||||||
|
|
||||||
// if (!widget) {
|
|
||||||
// return res.status(400).json({ error: "Invalid proxy service type" });
|
|
||||||
// }
|
|
||||||
// logger.debug("Getting data from JDRss API");
|
|
||||||
// const d = await printer_stats(widget)
|
|
||||||
// return res.send(d);
|
|
||||||
|
|
||||||
// }
|
|
@ -1,17 +1,17 @@
|
|||||||
// import octoprintProxyHandler from "./proxy";
|
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||||
|
|
||||||
// const widget = {
|
const widget = {
|
||||||
// api: "{url}/api/{endpoint}?apikey={key}",
|
api: "{url}/api/{endpoint}?apikey={key}",
|
||||||
// proxyHandler: octoprintProxyHandler,
|
proxyHandler: genericProxyHandler,
|
||||||
|
|
||||||
// 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