mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 21:03:29 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user