upgrade electron and fix apikey not-authenticated

This commit is contained in:
PhilReact 2025-02-24 18:41:50 +02:00
parent 3a0838c11b
commit 7222a082e0
3 changed files with 79 additions and 40 deletions

View File

@ -20,7 +20,7 @@
}, },
"devDependencies": { "devDependencies": {
"@electron/notarize": "^2.5.0", "@electron/notarize": "^2.5.0",
"electron": "^26.2.2", "electron": "^32.3.1",
"electron-builder": "^25.1.8", "electron-builder": "^25.1.8",
"shelljs": "^0.8.5", "shelljs": "^0.8.5",
"typescript": "^5.0.4" "typescript": "^5.0.4"
@ -2624,14 +2624,14 @@
} }
}, },
"node_modules/electron": { "node_modules/electron": {
"version": "26.6.10", "version": "32.3.1",
"resolved": "https://registry.npmjs.org/electron/-/electron-26.6.10.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-32.3.1.tgz",
"integrity": "sha512-pV2SD0RXzAiNRb/2yZrsVmVkBOMrf+DVsPulIgRjlL0+My9BL5spFuhHVMQO9yHl9tFpWtuRpQv0ofM/i9P8xg==", "integrity": "sha512-gjHN9NagNajvllKrTZVwGuCqX1hPF7OI6hkCDFRCbqT5Zr05d17qjDhjyTNBmTca2DpvZIYQMRbqieNCcglVYQ==",
"dev": true, "dev": true,
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"@electron/get": "^2.0.0", "@electron/get": "^2.0.0",
"@types/node": "^18.11.18", "@types/node": "^20.9.0",
"extract-zip": "^2.0.1" "extract-zip": "^2.0.1"
}, },
"bin": { "bin": {
@ -2909,18 +2909,18 @@
} }
}, },
"node_modules/electron/node_modules/@types/node": { "node_modules/electron/node_modules/@types/node": {
"version": "18.19.68", "version": "20.17.19",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.68.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.19.tgz",
"integrity": "sha512-QGtpFH1vB99ZmTa63K4/FU8twThj4fuVSBkGddTp7uIL/cuoLWIUSL2RcOaigBhfR+hg5pgGkBnkoOxrTVBMKw==", "integrity": "sha512-LEwC7o1ifqg/6r2gn9Dns0f1rhK+fPFDoMiceTJ6kWmVk6bgXBI/9IOWfVan4WiAavK9pIVWdX0/e3J+eEUh5A==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"undici-types": "~5.26.4" "undici-types": "~6.19.2"
} }
}, },
"node_modules/electron/node_modules/undici-types": { "node_modules/electron/node_modules/undici-types": {
"version": "5.26.5", "version": "6.19.8",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
"dev": true "dev": true
}, },
"node_modules/elementtree": { "node_modules/elementtree": {

View File

@ -47,7 +47,7 @@
"electron-window-state": "^5.0.3" "electron-window-state": "^5.0.3"
}, },
"devDependencies": { "devDependencies": {
"electron": "^26.2.2", "electron": "^32.3.1",
"electron-builder": "^25.1.8", "electron-builder": "^25.1.8",
"@electron/notarize": "^2.5.0", "@electron/notarize": "^2.5.0",
"typescript": "^5.0.4", "typescript": "^5.0.4",

View File

@ -191,28 +191,45 @@ export const NotAuthenticated = ({
const validateApiKey = useCallback(async (key, fromStartUp) => { const validateApiKey = useCallback(async (key, fromStartUp) => {
try { try {
if(key === "isGateway") return
const isLocalKey = cleanUrl(key?.url) === "127.0.0.1:12391"; const isLocalKey = cleanUrl(key?.url) === "127.0.0.1:12391";
if(fromStartUp && key?.url && key?.apikey && !isLocalKey && !gateways.some(gateway => apiKey?.url?.includes(gateway))){ if (fromStartUp && key?.url && key?.apikey && !isLocalKey && !gateways.some(gateway => key?.url?.includes(gateway))) {
setCurrentNode({ setCurrentNode({
url: key?.url, url: key?.url,
apikey: key?.apikey, apikey: key?.apikey,
}); });
const url = `${key?.url}/lists/testlist?apiKey=${key?.apikey}`;
const response = await fetch(url);
// Assuming the response is in plain text and will be 'true' or 'false'
const data = await response.json();
if (data && !data?.error) { let isValid = false
setIsValidApiKey(true);
setUseLocalNode(true);
return
}
const url = `${key?.url}/admin/settings/localAuthBypassEnabled`;
const response = await fetch(url);
// Assuming the response is in plain text and will be 'true' or 'false'
const data = await response.text();
if(data && data === 'true'){
isValid = true
} else {
const url2 = `${key?.url}/admin/apikey/test?apiKey=${key?.apikey}`;
const response2 = await fetch(url2);
// Assuming the response is in plain text and will be 'true' or 'false'
const data2 = await response2.text();
if (data2 === "true") {
isValid = true
}
}
if (isValid) {
setIsValidApiKey(true);
setUseLocalNode(true);
return
}
} }
if (!currentNodeRef.current) return; if (!currentNodeRef.current) return;
const stillHasLocal = await checkIfUserHasLocalNode() const stillHasLocal = await checkIfUserHasLocalNode()
if (isLocalKey && !stillHasLocal && !fromStartUp) { if (isLocalKey && !stillHasLocal && !fromStartUp) {
throw new Error("Please turn on your local node"); throw new Error("Please turn on your local node");
} }
@ -235,13 +252,29 @@ export const NotAuthenticated = ({
} else if (currentNodeRef.current) { } else if (currentNodeRef.current) {
payload = currentNodeRef.current; payload = currentNodeRef.current;
} }
const url = `${payload?.url}/lists/testlist?apiKey=${payload?.apikey}`; let isValid = false
const url = `${payload?.url}/admin/settings/localAuthBypassEnabled`;
const response = await fetch(url); const response = await fetch(url);
// Assuming the response is in plain text and will be 'true' or 'false' // Assuming the response is in plain text and will be 'true' or 'false'
const data = await response.json(); const data = await response.text();
if(data && data === 'true'){
isValid = true
} else {
const url2 = `${payload?.url}/admin/apikey/test?apiKey=${payload?.apikey}`;
const response2 = await fetch(url2);
// Assuming the response is in plain text and will be 'true' or 'false'
const data2 = await response2.text();
if (data2 === "true") {
isValid = true
}
}
if (data && !data?.error) { if (isValid) {
window window
.sendMessage("setApiKey", payload) .sendMessage("setApiKey", payload)
.then((response) => { .then((response) => {
@ -263,21 +296,24 @@ export const NotAuthenticated = ({
} else { } else {
setIsValidApiKey(false); setIsValidApiKey(false);
setUseLocalNode(false); setUseLocalNode(false);
setInfoSnack({ if(!fromStartUp){
type: "error", setInfoSnack({
message: "Select a valid apikey", type: "error",
}); message: "Select a valid apikey",
setOpenSnack(true); });
setOpenSnack(true);
}
} }
} catch (error) { } catch (error) {
setIsValidApiKey(false); setIsValidApiKey(false);
setUseLocalNode(false); setUseLocalNode(false);
if(fromStartUp){ if (fromStartUp) {
setCurrentNode({ setCurrentNode({
url: "http://127.0.0.1:12391", url: "http://127.0.0.1:12391",
}); });
window window
.sendMessage("setApiKey", null) .sendMessage("setApiKey", "isGateway")
.then((response) => { .then((response) => {
if (response) { if (response) {
setApiKey(null); setApiKey(null);
@ -292,11 +328,13 @@ export const NotAuthenticated = ({
}); });
return return
} }
if(!fromStartUp){
setInfoSnack({ setInfoSnack({
type: "error", type: "error",
message: error?.message || "Select a valid apikey", message: error?.message || "Select a valid apikey",
}); });
setOpenSnack(true); setOpenSnack(true);
}
console.error("Error validating API key:", error); console.error("Error validating API key:", error);
} }
}, []); }, []);
@ -318,7 +356,7 @@ export const NotAuthenticated = ({
url: removeTrailingSlash(url), url: removeTrailingSlash(url),
apikey: customApikey, apikey: customApikey,
}); });
} else if (url && customApikey) { } else if (url) {
nodes.push({ nodes.push({
url: removeTrailingSlash(url), url: removeTrailingSlash(url),
apikey: customApikey, apikey: customApikey,
@ -326,9 +364,7 @@ export const NotAuthenticated = ({
} }
setCustomNodes(nodes); setCustomNodes(nodes);
if(window?.electronAPI?.setAllowedDomains){
window.electronAPI.setAllowedDomains(nodes?.map((node)=> node.url))
}
setCustomNodeToSaveIndex(null); setCustomNodeToSaveIndex(null);
if (!nodes) return; if (!nodes) return;
window window
@ -338,6 +374,9 @@ export const NotAuthenticated = ({
setMode("list"); setMode("list");
setUrl("http://"); setUrl("http://");
setCustomApiKey(""); setCustomApiKey("");
if(window?.electronAPI?.setAllowedDomains){
window.electronAPI.setAllowedDomains(nodes?.map((node) => node.url))
}
// add alert if needed // add alert if needed
} }
}) })
@ -810,7 +849,7 @@ export const NotAuthenticated = ({
<Button <Button
variant="contained" variant="contained"
disabled={!customApikey || !url} disabled={!url}
onClick={() => saveCustomNodes(customNodes)} onClick={() => saveCustomNodes(customNodes)}
autoFocus autoFocus
> >