Create group link previews; don't open Signal links in browser first; allow ephemeral download of previously-error'd pack

This commit is contained in:
Scott Nonnenberg 2021-02-10 14:39:26 -08:00 committed by GitHub
parent f832b018fc
commit e10ae03bb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 338 additions and 33 deletions

View file

@ -23,6 +23,21 @@ export function isSgnlHref(value: string | URL, logger: LoggerType): boolean {
return url !== null && url.protocol === 'sgnl:';
}
export function isSignalHttpsLink(
value: string | URL,
logger: LoggerType
): boolean {
const url = parseUrl(value, logger);
return Boolean(
url &&
!url.username &&
!url.password &&
!url.port &&
url.protocol === 'https:' &&
(url.host === 'signal.group' || url.host === 'signal.art')
);
}
type ParsedSgnlHref =
| { command: null; args: Map<never, never> }
| { command: string; args: Map<string, string>; hash: string | undefined };
@ -48,3 +63,45 @@ export function parseSgnlHref(
hash: url.hash ? url.hash.slice(1) : undefined,
};
}
export function parseSignalHttpsLink(
href: string,
logger: LoggerType
): ParsedSgnlHref {
const url = parseUrl(href, logger);
if (!url || !isSignalHttpsLink(url, logger)) {
return { command: null, args: new Map<never, never>() };
}
if (url.host === 'signal.art') {
const hash = url.hash.slice(1);
const hashParams = new URLSearchParams(hash);
const args = new Map<string, string>();
hashParams.forEach((value, key) => {
if (!args.has(key)) {
args.set(key, value);
}
});
if (!args.get('pack_id') || !args.get('pack_key')) {
return { command: null, args: new Map<never, never>() };
}
return {
command: url.pathname.replace(/\//g, ''),
args,
hash: url.hash ? url.hash.slice(1) : undefined,
};
}
if (url.host === 'signal.group') {
return {
command: url.host,
args: new Map<string, string>(),
hash: url.hash ? url.hash.slice(1) : undefined,
};
}
return { command: null, args: new Map<never, never>() };
}