diff options
| author | marios8543 <marios8543@gmail.com> | 2024-02-23 22:22:10 +0200 |
|---|---|---|
| committer | marios8543 <marios8543@gmail.com> | 2024-02-23 22:22:10 +0200 |
| commit | 6b7f842233534a11ae3878d5fe843761dda7692a (patch) | |
| tree | f707419475e13d6d7288d3fa72ffd03a24d42ae8 | |
| parent | 6b5f7c8642062906ecb36d905e52d0fcc6172783 (diff) | |
| download | decky-loader-marios8543/log-viewer.tar.gz decky-loader-marios8543/log-viewer.zip | |
Add log uploadingmarios8543/log-viewer
| -rw-r--r-- | backend/locales/en-US.json | 7 | ||||
| -rw-r--r-- | backend/src/utilities.py | 7 | ||||
| -rw-r--r-- | frontend/src/components/logviewer/LogList.tsx | 2 | ||||
| -rw-r--r-- | frontend/src/components/logviewer/LogViewModal.tsx | 21 |
4 files changed, 30 insertions, 7 deletions
diff --git a/backend/locales/en-US.json b/backend/locales/en-US.json index ca18f7da..ac6d9bda 100644 --- a/backend/locales/en-US.json +++ b/backend/locales/en-US.json @@ -266,5 +266,12 @@ }, "Testing": { "download": "Download" + }, + "LogViewer": { + "viewLog": "View Log", + "uploadLog": "Upload Log", + "textError": "Error loading text", + "uploadConfirm": "Are you sure you want to upload this log ?", + "uploadDisclaimer": "Depending on how this plugin is written, this log might contain confidential information. Are you sure you want to continue ? If unsure, ask the plugin developer." } } diff --git a/backend/src/utilities.py b/backend/src/utilities.py index 92715645..5dea0e94 100644 --- a/backend/src/utilities.py +++ b/backend/src/utilities.py @@ -396,4 +396,9 @@ class Utilities: return log_file.read() async def upload_log(self, plugin_name: str, log_name: str): - raise RuntimeError("Not Implemented")
\ No newline at end of file + text = await self.get_plugin_log_text(plugin_name, log_name) + async with ClientSession() as web: + res = await web.put("https://lp.deckbrew.xyz", data=text) + res.raise_for_status() + upload_id = (await res.json())["id"] + return f"https://lp.deckbrew.xyz/{upload_id}"
\ No newline at end of file diff --git a/frontend/src/components/logviewer/LogList.tsx b/frontend/src/components/logviewer/LogList.tsx index b536fd02..01aae45f 100644 --- a/frontend/src/components/logviewer/LogList.tsx +++ b/frontend/src/components/logviewer/LogList.tsx @@ -24,7 +24,7 @@ const LogList: FC<{ plugin: string }> = ({ plugin }) => { {logList.map((log_file) => ( <DialogButton style={{ marginBottom: "0.5rem" }} - onOKActionDescription={t("LogViewer.viewLog", "View Log")} + onOKActionDescription={t("LogViewer.viewLog")} onOKButton={() => showModal( <LogViewModal name={log_file} plugin={plugin}></LogViewModal>, diff --git a/frontend/src/components/logviewer/LogViewModal.tsx b/frontend/src/components/logviewer/LogViewModal.tsx index beda50a3..111717f6 100644 --- a/frontend/src/components/logviewer/LogViewModal.tsx +++ b/frontend/src/components/logviewer/LogViewModal.tsx @@ -1,6 +1,7 @@ -import { Focusable } from "decky-frontend-lib"; +import { ConfirmModal, Focusable, showModal } from "decky-frontend-lib"; import { VFC, useEffect, useState } from "react"; import { ScrollableWindowRelative } from "./ScrollableWindow"; +import { t } from "i18next"; interface LogFileProps { plugin: string; @@ -8,14 +9,24 @@ interface LogFileProps { closeModal?: () => void; } +const uploadConfirmation = (name: string, plugin: string) => { + const confirmModal = <ConfirmModal onOK={() => { + window.DeckyPluginLoader.callServerMethod("upload_log", { plugin_name: plugin, log_name: name }).then((res) => { + console.log(res) + showModal(<ConfirmModal><h2>{res.result}</h2></ConfirmModal>) + }) + }} strTitle={t("LogViewer.uploadConfirm")}>{t("LogViewer.uploadDisclaimer")}</ConfirmModal> + showModal(confirmModal); +} + const LogViewModal: VFC<LogFileProps> = ({ name, plugin, closeModal }) => { - const [logText, setLogText] = useState("Loading text...."); + const [logText, setLogText] = useState(""); useEffect(() => { window.DeckyPluginLoader.callServerMethod("get_plugin_log_text", { plugin_name: plugin, log_name: name, }).then((text) => { - setLogText(text.result || "Error loading text"); + setLogText(text.result || t("LogViewer.textError")); }); }, []); @@ -30,8 +41,8 @@ const LogViewModal: VFC<LogFileProps> = ({ name, plugin, closeModal }) => { left: 0, right: 0, }} - onSecondaryActionDescription={"Upload Log"} - onSecondaryButton={() => console.log("Uploading...")} + onSecondaryActionDescription={t("LogViewer.uploadLog")} + onSecondaryButton={() => uploadConfirmation(name, plugin)} > <ScrollableWindowRelative alwaysFocus={true} onCancel={closeModal}> <div style={{ whiteSpace: "pre-wrap", padding: "12px 0" }}> |
