From 2a971289649e510cda4c7b095b10583f69d2eb92 Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Fri, 8 Dec 2023 20:32:35 +0000 Subject: [PATCH] revert octo --- src/widgets/octoprint/component.jsx | 132 +++++++++++++--------------- src/widgets/octoprint/proxy.js | 68 -------------- src/widgets/octoprint/widget.js | 28 +++--- 3 files changed, 74 insertions(+), 154 deletions(-) delete mode 100644 src/widgets/octoprint/proxy.js diff --git a/src/widgets/octoprint/component.jsx b/src/widgets/octoprint/component.jsx index d2f0be7d..38f17ade 100644 --- a/src/widgets/octoprint/component.jsx +++ b/src/widgets/octoprint/component.jsx @@ -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 ( + + + + ); + } -// if (printerStatsError && jobStats) { -// return ( -// -// -// -// ); -// } + if (printerStatsError) { + return ; + } -// if (printerStatsError) { -// let msg -// try { -// msg = JSON.parse(Buffer.from(printerStatsError.resultData.data).toString()).error; -// } catch (error) { -// msg = 'Octoprint Not Found' -// } -// return ( -// -// -// -// ); -// } + if (jobStatsError) { + return ; + } -// // if (jobStatsError) { -// // return ; -// // } + 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 ( + + + + ); + } -// if (!printerStats || !state || !tempTool || !tempBed) { -// return ( -// -// -// -// ); -// } + 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 ( + + + + + + + ); + } -// if (!jobStats || !completion) { -// return ( -// -// -// -// -// -// -// ); -// } + return ( + + + + + + + ); + } -// return ( -// -// -// -// -// -// -// ); -// } - -// return ( -// -// -// -// -// -// ); -// } + return ( + + + + + + ); +} \ No newline at end of file diff --git a/src/widgets/octoprint/proxy.js b/src/widgets/octoprint/proxy.js deleted file mode 100644 index d1437fab..00000000 --- a/src/widgets/octoprint/proxy.js +++ /dev/null @@ -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); - -// } \ No newline at end of file diff --git a/src/widgets/octoprint/widget.js b/src/widgets/octoprint/widget.js index 6dc83095..24b5fde7 100644 --- a/src/widgets/octoprint/widget.js +++ b/src/widgets/octoprint/widget.js @@ -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; \ No newline at end of file