api: move url extraction to url module

This commit is contained in:
dumbmoron
2024-05-15 12:22:36 +00:00
parent 5c9ecb2781
commit ae91f8b120
2 changed files with 30 additions and 19 deletions

View File

@ -125,3 +125,29 @@ export function getHostIfValid(url) {
return host.sld;
}
export function extract(url) {
const host = getHostIfValid(url);
if (!host || !services[host].enabled) {
return null;
}
let patternMatch;
for (const pattern of services[host].patterns) {
patternMatch = pattern.match(
url.pathname.substring(1) + url.search
);
if (patternMatch) {
break;
}
}
if (!patternMatch) {
return null;
}
return { host, patternMatch };
}