This commit is contained in:
PhilReact 2025-03-16 22:42:28 +02:00 committed by Nicola Benaglia
parent 63f05e4c99
commit c516c36425
3 changed files with 62 additions and 11 deletions

View File

@ -19,6 +19,7 @@ import {
Input, Input,
styled, styled,
Switch, Switch,
TextField,
Typography, Typography,
} from "@mui/material"; } from "@mui/material";
import Logo1Dark from "../assets/svgs/Logo1Dark.svg"; import Logo1Dark from "../assets/svgs/Logo1Dark.svg";
@ -77,6 +78,8 @@ export const NotAuthenticated = ({
//add and edit states //add and edit states
const [url, setUrl] = React.useState("https://"); const [url, setUrl] = React.useState("https://");
const [customApikey, setCustomApiKey] = React.useState(""); const [customApikey, setCustomApiKey] = React.useState("");
const [showSelectApiKey, setShowSelectApiKey] = useState(false)
const [enteredApiKey, setEnteredApiKey] = useState('')
const [customNodeToSaveIndex, setCustomNodeToSaveIndex] = const [customNodeToSaveIndex, setCustomNodeToSaveIndex] =
React.useState(null); React.useState(null);
const { showTutorial, hasSeenGettingStarted } = useContext(GlobalContext); const { showTutorial, hasSeenGettingStarted } = useContext(GlobalContext);
@ -86,6 +89,7 @@ export const NotAuthenticated = ({
const hasLocalNodeRef = useRef(null); const hasLocalNodeRef = useRef(null);
const isLocal = cleanUrl(currentNode?.url) === "127.0.0.1:12391"; const isLocal = cleanUrl(currentNode?.url) === "127.0.0.1:12391";
const handleFileChangeApiKey = (event) => { const handleFileChangeApiKey = (event) => {
setShowSelectApiKey(false)
const file = event.target.files[0]; // Get the selected file const file = event.target.files[0]; // Get the selected file
if (file) { if (file) {
const reader = new FileReader(); const reader = new FileReader();
@ -250,6 +254,57 @@ export const NotAuthenticated = ({
apikey: importedApiKeyRef.current || key?.apikey, apikey: importedApiKeyRef.current || key?.apikey,
url: currentNodeRef.current?.url, 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) { } else if (currentNodeRef.current) {
payload = currentNodeRef.current; payload = currentNodeRef.current;
} }
@ -603,14 +658,8 @@ export const NotAuthenticated = ({
</Box> </Box>
{currentNode?.url === "http://127.0.0.1:12391" && ( {currentNode?.url === "http://127.0.0.1:12391" && (
<> <>
<Button size="small" variant="contained" component="label"> <Button onClick={()=> setShowSelectApiKey(true)} size="small" variant="contained" component="label">
{apiKey ? "Change " : "Import "} apiKey.txt {apiKey ? "Change " : "Import "} apikey
<input
type="file"
accept=".txt"
hidden
onChange={handleFileChangeApiKey} // File input handler
/>
</Button> </Button>
<Typography <Typography
sx={{ sx={{

View File

@ -35,7 +35,8 @@ const AppViewerContainer = React.forwardRef(({ app, isSelected, hide, isDevMode,
</> </>
} }
style={{ style={{
display: (!isSelected || hide) && 'none', position: (!isSelected || hide) && 'absolute',
left: (!isSelected || hide) && '10000000px',
height: customHeight ? customHeight : !isMobile ? '100vh' : `calc(${rootHeight} - 60px - 45px)`, height: customHeight ? customHeight : !isMobile ? '100vh' : `calc(${rootHeight} - 60px - 45px)`,
border: 'none', border: 'none',
width: '100%', width: '100%',

View File

@ -216,8 +216,9 @@ export const AppsDevMode = ({ mode, setMode, show , myName, goToHome, setDesktop
return ( return (
<AppsParent <AppsParent
sx={{ sx={{
display: !show && "none", flexDirection: 'row' ,
flexDirection: 'row' position: !show && 'absolute',
left: !show && '10000000px',
}} }}
> >