From 667029f2c69f31317391ea193ff94be68d8b2f3e Mon Sep 17 00:00:00 2001 From: PhilReact Date: Sun, 16 Mar 2025 22:42:28 +0200 Subject: [PATCH] fixes --- src/ExtStates/NotAuthenticated.tsx | 154 +++++++++++++++++++-- src/components/Apps/AppViewerContainer.tsx | 3 +- src/components/Apps/AppsDesktop.tsx | 3 +- src/components/Apps/AppsDevMode.tsx | 5 +- 4 files changed, 153 insertions(+), 12 deletions(-) diff --git a/src/ExtStates/NotAuthenticated.tsx b/src/ExtStates/NotAuthenticated.tsx index 89c3406..8c2ae6e 100644 --- a/src/ExtStates/NotAuthenticated.tsx +++ b/src/ExtStates/NotAuthenticated.tsx @@ -14,6 +14,7 @@ import { Input, styled, Switch, + TextField, Typography, } from "@mui/material"; import Logo1 from "../assets/svgs/Logo1.svg"; @@ -76,6 +77,8 @@ export const NotAuthenticated = ({ //add and edit states const [url, setUrl] = React.useState("https://"); const [customApikey, setCustomApiKey] = React.useState(""); + const [showSelectApiKey, setShowSelectApiKey] = useState(false) + const [enteredApiKey, setEnteredApiKey] = useState('') const [customNodeToSaveIndex, setCustomNodeToSaveIndex] = React.useState(null); const { showTutorial, hasSeenGettingStarted } = useContext(GlobalContext); @@ -85,6 +88,7 @@ export const NotAuthenticated = ({ const hasLocalNodeRef = useRef(null); const isLocal = cleanUrl(currentNode?.url) === "127.0.0.1:12391"; const handleFileChangeApiKey = (event) => { + setShowSelectApiKey(false) const file = event.target.files[0]; // Get the selected file if (file) { const reader = new FileReader(); @@ -249,6 +253,57 @@ export const NotAuthenticated = ({ apikey: importedApiKeyRef.current || key?.apikey, url: currentNodeRef.current?.url, }; + if(!payload?.apikey){ + try { + const generateUrl = "http://127.0.0.1:12391/admin/apikey/generate"; + const generateRes = await fetch(generateUrl, { + method: "POST", + }) + let res; + try { + res = await generateRes.clone().json(); + } catch (e) { + res = await generateRes.text(); + } + if (res != null && !res.error && res.length >= 8) { + payload = { + apikey: res, + url: currentNodeRef.current?.url, + }; + + setImportedApiKey(res); // Store the file content in the state + + setCustomNodes((prev)=> { + const copyPrev = [...prev] + const findLocalIndex = copyPrev?.findIndex((item)=> item?.url === 'http://127.0.0.1:12391') + if(findLocalIndex === -1){ + copyPrev.unshift({ + url: "http://127.0.0.1:12391", + apikey: res + }) + } else { + copyPrev[findLocalIndex] = { + url: "http://127.0.0.1:12391", + apikey: res + } + } + window + .sendMessage("setCustomNodes", copyPrev) + .catch((error) => { + console.error( + "Failed to set custom nodes:", + error.message || "An error occurred" + ); + }); + return copyPrev + }) + + + } + } catch (error) { + console.error(error) + } + } } else if (currentNodeRef.current) { payload = currentNodeRef.current; } @@ -573,14 +628,8 @@ export const NotAuthenticated = ({ {currentNode?.url === "http://127.0.0.1:12391" && ( <> - )} + + {showSelectApiKey && ( + + {"Enter apikey"} + + + setEnteredApiKey(e.target.value)}/> + + + + + + + + + + + + + )} { showTutorial('create-account', true) }} sx={{ diff --git a/src/components/Apps/AppViewerContainer.tsx b/src/components/Apps/AppViewerContainer.tsx index f258848..9da90c4 100644 --- a/src/components/Apps/AppViewerContainer.tsx +++ b/src/components/Apps/AppViewerContainer.tsx @@ -35,7 +35,8 @@ const AppViewerContainer = React.forwardRef(({ app, isSelected, hide, isDevMode, } style={{ - display: (!isSelected || hide) && 'none', + position: (!isSelected || hide) && 'absolute', + left: (!isSelected || hide) && '10000000px', height: customHeight ? customHeight : !isMobile ? '100vh' : `calc(${rootHeight} - 60px - 45px)`, border: 'none', width: '100%', diff --git a/src/components/Apps/AppsDesktop.tsx b/src/components/Apps/AppsDesktop.tsx index 20a3d54..10f0bd3 100644 --- a/src/components/Apps/AppsDesktop.tsx +++ b/src/components/Apps/AppsDesktop.tsx @@ -313,7 +313,8 @@ export const AppsDesktop = ({ mode, setMode, show , myName, goToHome, setDesktop return ( diff --git a/src/components/Apps/AppsDevMode.tsx b/src/components/Apps/AppsDevMode.tsx index 7bc7d4f..d569741 100644 --- a/src/components/Apps/AppsDevMode.tsx +++ b/src/components/Apps/AppsDevMode.tsx @@ -216,8 +216,9 @@ export const AppsDevMode = ({ mode, setMode, show , myName, goToHome, setDesktop return (