mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): ♻️ Use URL literal instead of strings
This commit is contained in:
parent
99fac323c8
commit
76d1ccc859
50 changed files with 343 additions and 256 deletions
|
|
@ -32,7 +32,7 @@ export const applyToHono = (app: OpenAPIHono<HonoEnv>): void => {
|
|||
},
|
||||
boardLogo: {
|
||||
path:
|
||||
config.instance.logo ??
|
||||
config.instance.logo?.toString() ??
|
||||
"https://cdn.versia.pub/branding/icon.svg",
|
||||
height: 40,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { config } from "~/packages/config-manager/index.ts";
|
||||
|
||||
export const localObjectUri = (id: string): string =>
|
||||
new URL(`/objects/${id}`, config.http.base_url).toString();
|
||||
export const localObjectUri = (id: string): URL =>
|
||||
new URL(`/objects/${id}`, config.http.base_url);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,12 +9,9 @@ export type Json =
|
|||
| Json[]
|
||||
| { [key: string]: Json };
|
||||
|
||||
export const proxyUrl = (url: string | null = null): string | null => {
|
||||
const urlAsBase64Url = Buffer.from(url || "").toString("base64url");
|
||||
return url
|
||||
? new URL(
|
||||
`/media/proxy/${urlAsBase64Url}`,
|
||||
config.http.base_url,
|
||||
).toString()
|
||||
: url;
|
||||
export const proxyUrl = (url: URL): URL => {
|
||||
const urlAsBase64Url = Buffer.from(url.toString() || "").toString(
|
||||
"base64url",
|
||||
);
|
||||
return new URL(`/media/proxy/${urlAsBase64Url}`, config.http.base_url);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -136,7 +136,11 @@ export const sanitizeHtml = async (
|
|||
element(element): void {
|
||||
element.setAttribute(
|
||||
"src",
|
||||
proxyUrl(element.getAttribute("src") ?? "") ?? "",
|
||||
element.getAttribute("src")
|
||||
? proxyUrl(
|
||||
new URL(element.getAttribute("src") as string),
|
||||
).toString()
|
||||
: "",
|
||||
);
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue