mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
fix(api): 🐛 Fetch media content-type from data, instead of doing naive guesses
This commit is contained in:
parent
6f67881d96
commit
4fdb96930f
8 changed files with 111 additions and 23 deletions
|
|
@ -28,7 +28,10 @@ export const getBestContentType = (
|
|||
return { content: "", format: "text/plain" };
|
||||
};
|
||||
|
||||
export const urlToContentFormat = (url?: string): ContentFormat | null => {
|
||||
export const urlToContentFormat = (
|
||||
url: string,
|
||||
contentType?: string,
|
||||
): ContentFormat | null => {
|
||||
if (!url) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -41,6 +44,7 @@ export const urlToContentFormat = (url?: string): ContentFormat | null => {
|
|||
};
|
||||
}
|
||||
const mimeType =
|
||||
contentType ||
|
||||
lookup(url.replace(new URL(url).search, "")) ||
|
||||
"application/octet-stream";
|
||||
|
||||
|
|
@ -63,7 +67,13 @@ export const mimeLookup = (url: string): Promise<string> => {
|
|||
method: "HEAD",
|
||||
// @ts-expect-error Proxy is a Bun-specific feature
|
||||
proxy: config.http.proxy.address,
|
||||
}).then((response) => response.headers.get("content-type") || "");
|
||||
})
|
||||
.then(
|
||||
(response) =>
|
||||
response.headers.get("content-type") ||
|
||||
"application/octet-stream",
|
||||
)
|
||||
.catch(() => "application/octet-stream");
|
||||
|
||||
return fetchLookup;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue