refactor(api): ♻️ Use URL literal instead of strings

This commit is contained in:
Jesse Wierzbinski 2025-02-01 16:32:18 +01:00
parent 99fac323c8
commit 76d1ccc859
No known key found for this signature in database
50 changed files with 343 additions and 256 deletions

View file

@ -30,28 +30,25 @@ export const getBestContentType = (
};
export const urlToContentFormat = (
url: string,
url: URL,
contentType?: string,
): ContentFormat | null => {
if (!url) {
return null;
}
if (url.startsWith("https://api.dicebear.com/")) {
if (url.href.startsWith("https://api.dicebear.com/")) {
return {
"image/svg+xml": {
content: url,
content: url.toString(),
remote: true,
},
};
}
const mimeType =
contentType ||
lookup(url.replace(new URL(url).search, "")) ||
lookup(url.toString().replace(url.search, "")) ||
"application/octet-stream";
return {
[mimeType]: {
content: url,
content: url.toString(),
remote: true,
},
};