Add functionality to encode, decode and share redirects.

This commit is contained in:
Bauke 2022-11-23 14:13:17 +01:00
parent bb806cb561
commit 87e4a28315
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 1175 additions and 37 deletions

View File

@ -19,6 +19,7 @@
"@holllo/migration-helper": "^0.1.3",
"@holllo/preact-components": "^0.2.3",
"htm": "^3.1.1",
"js-base64": "^3.7.3",
"modern-normalize": "^1.1.0",
"preact": "^10.11.0",
"webextension-polyfill": "^0.10.0"

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
import {Base64} from 'js-base64';
import {RedirectParameters} from '../redirect/exports.js';
export const fragmentPrefix = '#json=';
export function decodeBase64<T>(base64: string): T {
return JSON.parse(Base64.decode(base64)) as T;
}
export function encodeBase64(source: any): string {
return Base64.encode(JSON.stringify(source), true);
}
export function share(redirect: RedirectParameters): string {
const url = new URL('https://holllo.org/re-nav/share/');
const encoded = encodeBase64({
matcherType: redirect.matcherType,
matcherValue: redirect.matcherValue,
redirectType: redirect.redirectType,
redirectValue: redirect.redirectValue,
});
url.hash = `${fragmentPrefix}${encoded}`;
return url.href;
}