feat(KAN-52): add server selection and isolated native sessions
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
export function normalizeServer(input) {
|
||||
const value = input.trim();
|
||||
if (
|
||||
!/^https:\/\//i.test(value) ||
|
||||
[...value].some(
|
||||
(character) =>
|
||||
character.charCodeAt(0) < 32 ||
|
||||
character.charCodeAt(0) === 127 ||
|
||||
character === '\\',
|
||||
)
|
||||
) {
|
||||
throw new Error('invalidServer');
|
||||
}
|
||||
const url = new URL(value);
|
||||
if (
|
||||
url.protocol !== 'https:' ||
|
||||
!url.hostname ||
|
||||
url.username ||
|
||||
url.password ||
|
||||
value.includes('?') ||
|
||||
value.includes('#')
|
||||
) {
|
||||
throw new Error('invalidServer');
|
||||
}
|
||||
if (!url.pathname.endsWith('/')) {
|
||||
url.pathname += '/';
|
||||
}
|
||||
return url.href;
|
||||
}
|
||||
|
||||
export function needsConfirmation(activeServer, nextServer) {
|
||||
return activeServer !== null && activeServer !== nextServer;
|
||||
}
|
||||
Reference in New Issue
Block a user