api: rework url parsing

- tlds are now parsed and validated correctly (e.g. ".co.uk" works now)
- url patterns are pre-compiled instead of being compiled for every request
- aliases are computed in a safe manner using the URL object where possible
This commit is contained in:
dumbmoron
2023-12-09 11:00:54 +00:00
parent 64790b9820
commit dd563eb752
5 changed files with 116 additions and 81 deletions

View File

@@ -1,8 +1,17 @@
import UrlPattern from "url-pattern";
import { loadJSON } from "./sub/loadFromFs.js";
const config = loadJSON("./src/config.json");
const packageJson = loadJSON("./package.json");
const servicesConfigJson = loadJSON("./src/modules/processing/servicesConfig.json");
Object.values(servicesConfigJson.config).forEach(service => {
service.patterns = service.patterns.map(
pattern => new UrlPattern(pattern, {
segmentValueCharset: UrlPattern.defaultOptions.segmentValueCharset + '\\.'
})
)
})
export const
services = servicesConfigJson.config,
audioIgnore = servicesConfigJson.audioIgnore,