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";
|
||||
// import Block from "components/services/widget/block";
|
||||
// import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
export default function Component({ service }) {
|
||||
const { widget } = service;
|
||||
|
||||
// export default function Component({ service }) {
|
||||
// const { widget } = service;
|
||||
const { data: printerStats, error: printerStatsError } = useWidgetAPI(widget, "printer_stats");
|
||||
const { data: jobStats, error: jobStatsError } = useWidgetAPI(widget, "job_stats");
|
||||
|
||||
// const { data: printerStats, error: printerStatsError } = useWidgetAPI(widget, "printer_stats");
|
||||
// // const { data: jobStats, error: jobStatsError } = useWidgetAPI(widget, "job_stats");
|
||||
if (printerStatsError && jobStats) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="octoprint.printer_state" value={jobStats.state} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
// if (printerStatsError && jobStats) {
|
||||
// return (
|
||||
// <Container service={service}>
|
||||
// <Block label="octoprint.printer_state" value={jobStats.state} />
|
||||
// </Container>
|
||||
// );
|
||||
// }
|
||||
if (printerStatsError) {
|
||||
return <Container service={service} error={printerStatsError} />;
|
||||
}
|
||||
|
||||
// if (printerStatsError) {
|
||||
// let msg
|
||||
// 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) {
|
||||
return <Container service={service} error={jobStatsError} />;
|
||||
}
|
||||
|
||||
// // if (jobStatsError) {
|
||||
// // return <Container service={service} error={jobStatsError} />;
|
||||
// // }
|
||||
const state = printerStats?.state?.text;
|
||||
const tempTool = printerStats?.temperature?.tool0?.actual;
|
||||
const tempBed = printerStats?.temperature?.bed?.actual;
|
||||
|
||||
// const state = printerStats[1].Status;
|
||||
// const tempTool = printerStats[1].Temp.Tool;
|
||||
// const tempBed = printerStats[1].Temp.Bed;
|
||||
if (!printerStats || !state || !tempTool || !tempBed) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="octoprint.printer_state" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
// if (!printerStats || !state || !tempTool || !tempBed) {
|
||||
// return (
|
||||
// <Container service={service}>
|
||||
// <Block label="octoprint.printer_state" />
|
||||
// </Container>
|
||||
// );
|
||||
// }
|
||||
const printingStateFalgs = ["Printing", "Paused", "Pausing", "Resuming"];
|
||||
|
||||
// const printingStateFalgs = ["Printing", "Paused", "Pausing", "Resuming"];
|
||||
if (printingStateFalgs.includes(state)) {
|
||||
const completion = jobStats?.progress?.completion;
|
||||
|
||||
// if (printingStateFalgs.includes(state)) {
|
||||
// const completion = jobStats?.progress?.completion;
|
||||
if (!jobStats || !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 (
|
||||
// <Container service={service}>
|
||||
// <Block label="octoprint.printer_state" />
|
||||
// <Block label="octoprint.temp_tool" />
|
||||
// <Block label="octoprint.temp_bed" />
|
||||
// <Block label="octoprint.job_completion" />
|
||||
// </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`} />
|
||||
<Block label="octoprint.job_completion" value={`${completion.toFixed(2)}%`} />
|
||||
</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`} />
|
||||
// <Block label="octoprint.job_completion" value={`${completion.toFixed(2)}%`} />
|
||||
// </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>
|
||||
// );
|
||||
// }
|
||||
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 = {
|
||||
// api: "{url}/api/{endpoint}?apikey={key}",
|
||||
// proxyHandler: octoprintProxyHandler,
|
||||
const widget = {
|
||||
api: "{url}/api/{endpoint}?apikey={key}",
|
||||
proxyHandler: genericProxyHandler,
|
||||
|
||||
// mappings: {
|
||||
// printer_stats: {
|
||||
// endpoint: "printer",
|
||||
// },
|
||||
// job_stats: {
|
||||
// endpoint: "job",
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
mappings: {
|
||||
printer_stats: {
|
||||
endpoint: "printer",
|
||||
},
|
||||
job_stats: {
|
||||
endpoint: "job",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// export default widget;
|
||||
export default widget;
|
Loading…
x
Reference in New Issue
Block a user