feat: generate authenticated url (#1471)

* refactor: extract info component

* feat: generate authenticated url

* refactor: add companion select

* refactor: ensure behaviour across environments
This commit is contained in:
Carlos Valente
2025-01-26 16:51:28 +01:00
committed by GitHub
parent d34280c03d
commit 0f57689750
19 changed files with 305 additions and 44 deletions
@@ -8,6 +8,8 @@ import { getLastLoadedProject } from '../../services/app-state-service/AppStateS
import { runtimeService } from '../../services/runtime-service/RuntimeService.js';
import { getNetworkInterfaces } from '../../utils/network.js';
import { getTimezoneLabel } from '../../utils/time.js';
import { password } from '../../externals.js';
import { hashPassword } from '../../utils/hash.js';
const startedAt = new Date();
@@ -46,3 +48,20 @@ export async function getInfo(): Promise<GetInfo> {
publicDir: publicDir.root,
};
}
export const hasPassword = Boolean(password);
export const hashedPassword = hasPassword ? hashPassword(password as string) : undefined;
/**
* Generates a pre-authenticated URL by injecting a token in the URL params
*/
export function generateAuthenticatedUrl(baseUrl: string, path: string, lock: boolean, authenticate: boolean): URL {
const url = new URL(path, baseUrl);
if (authenticate && hashedPassword) {
url.searchParams.append('token', hashedPassword);
}
if (lock) {
url.searchParams.append('locked', 'true');
}
return url;
}