Add functionality to encode, decode and share redirects.
This commit is contained in:
parent
bb806cb561
commit
87e4a28315
|
@ -19,6 +19,7 @@
|
||||||
"@holllo/migration-helper": "^0.1.3",
|
"@holllo/migration-helper": "^0.1.3",
|
||||||
"@holllo/preact-components": "^0.2.3",
|
"@holllo/preact-components": "^0.2.3",
|
||||||
"htm": "^3.1.1",
|
"htm": "^3.1.1",
|
||||||
|
"js-base64": "^3.7.3",
|
||||||
"modern-normalize": "^1.1.0",
|
"modern-normalize": "^1.1.0",
|
||||||
"preact": "^10.11.0",
|
"preact": "^10.11.0",
|
||||||
"webextension-polyfill": "^0.10.0"
|
"webextension-polyfill": "^0.10.0"
|
||||||
|
|
1183
pnpm-lock.yaml
1183
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue