mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-07-15 21:03:47 +00:00
fix: resolve backend build errors, preserve sudo file read buffers, and format code (#798)
* fix: resolve backend TypeScript build errors and preserve sudo file read buffers * style: format code * fix: ssh2 ESM import failure --------- Co-authored-by: LukeGus <bugattiguy527@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+55
-34
@@ -563,12 +563,21 @@ async function clearElectronJwtCookiesAtStartup() {
|
||||
function getBackendPaths() {
|
||||
if (isDev) {
|
||||
const backendDir = path.join(appRoot, "dist", "backend", "backend");
|
||||
return { entryPath: path.join(backendDir, "starter.js"), backendCwd: backendDir };
|
||||
return {
|
||||
entryPath: path.join(backendDir, "starter.js"),
|
||||
backendCwd: backendDir,
|
||||
};
|
||||
}
|
||||
// fork() does not go through Electron's asar redirector — use the unpacked path
|
||||
const unpackedRoot = appRoot.replace(/app\.asar(?!\.unpacked)/, "app.asar.unpacked");
|
||||
const unpackedRoot = appRoot.replace(
|
||||
/app\.asar(?!\.unpacked)/,
|
||||
"app.asar.unpacked",
|
||||
);
|
||||
const backendDir = path.join(unpackedRoot, "dist", "backend", "backend");
|
||||
return { entryPath: path.join(backendDir, "starter.js"), backendCwd: backendDir };
|
||||
return {
|
||||
entryPath: path.join(backendDir, "starter.js"),
|
||||
backendCwd: backendDir,
|
||||
};
|
||||
}
|
||||
|
||||
function getBackendDataDir() {
|
||||
@@ -606,9 +615,10 @@ function startBackendServer() {
|
||||
logToFile(" backendCwd exists:", fs.existsSync(backendCwd));
|
||||
|
||||
backendProcess = fork(entryPath, [], {
|
||||
cwd: fs.existsSync(backendCwd) && fs.statSync(backendCwd).isDirectory()
|
||||
? backendCwd
|
||||
: dataDir,
|
||||
cwd:
|
||||
fs.existsSync(backendCwd) && fs.statSync(backendCwd).isDirectory()
|
||||
? backendCwd
|
||||
: dataDir,
|
||||
env: {
|
||||
...process.env,
|
||||
DATA_DIR: dataDir,
|
||||
@@ -1089,40 +1099,51 @@ ipcMain.handle("get-embedded-server-status", () => {
|
||||
});
|
||||
|
||||
// OIDC System Browser Authentication (RFC 8252)
|
||||
ipcMain.handle("oidc-system-browser-auth", async (_event, authUrl, callbackPort) => {
|
||||
const http = require("http");
|
||||
ipcMain.handle(
|
||||
"oidc-system-browser-auth",
|
||||
async (_event, authUrl, callbackPort) => {
|
||||
const http = require("http");
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = http.createServer((req, res) => {
|
||||
const url = new URL(req.url, `http://localhost:${callbackPort}`);
|
||||
if (url.pathname === "/oidc-callback") {
|
||||
const success = url.searchParams.get("success");
|
||||
const error = url.searchParams.get("error");
|
||||
const token = url.searchParams.get("token");
|
||||
return new Promise((resolve, reject) => {
|
||||
const server = http.createServer((req, res) => {
|
||||
const url = new URL(req.url, `http://localhost:${callbackPort}`);
|
||||
if (url.pathname === "/oidc-callback") {
|
||||
const success = url.searchParams.get("success");
|
||||
const error = url.searchParams.get("error");
|
||||
const token = url.searchParams.get("token");
|
||||
|
||||
res.writeHead(200, { "Content-Type": "text/html" });
|
||||
res.end(`<html><body><h2>${success === "true" ? "Authentication successful!" : "Authentication failed."}</h2><p>You can close this tab and return to Termix.</p><script>window.close()</script></body></html>`);
|
||||
res.writeHead(200, { "Content-Type": "text/html" });
|
||||
res.end(
|
||||
`<html><body><h2>${success === "true" ? "Authentication successful!" : "Authentication failed."}</h2><p>You can close this tab and return to Termix.</p><script>window.close()</script></body></html>`,
|
||||
);
|
||||
|
||||
server.close();
|
||||
if (success === "true") {
|
||||
resolve({ success: true, token });
|
||||
} else {
|
||||
resolve({ success: false, error: error || "Authentication failed" });
|
||||
server.close();
|
||||
if (success === "true") {
|
||||
resolve({ success: true, token });
|
||||
} else {
|
||||
resolve({
|
||||
success: false,
|
||||
error: error || "Authentication failed",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(callbackPort, "127.0.0.1", () => {
|
||||
shell.openExternal(authUrl);
|
||||
});
|
||||
server.listen(callbackPort, "127.0.0.1", () => {
|
||||
shell.openExternal(authUrl);
|
||||
});
|
||||
|
||||
// Timeout after 5 minutes
|
||||
setTimeout(() => {
|
||||
server.close();
|
||||
reject(new Error("OIDC authentication timed out"));
|
||||
}, 5 * 60 * 1000);
|
||||
});
|
||||
});
|
||||
// Timeout after 5 minutes
|
||||
setTimeout(
|
||||
() => {
|
||||
server.close();
|
||||
reject(new Error("OIDC authentication timed out"));
|
||||
},
|
||||
5 * 60 * 1000,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
ipcMain.handle("get-server-config", () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user