jormungandr-bite/packages/client/src/scripts/get-static-image-url.ts

17 lines
567 B
TypeScript
Raw Normal View History

2023-01-12 21:40:33 -07:00
import { url as instanceUrl } from "@/config";
import * as url from "@/scripts/url";
export function getStaticImageUrl(baseUrl: string): string {
const u = new URL(baseUrl);
if (u.href.startsWith(`${instanceUrl}/proxy/`)) {
// もう既にproxyっぽそうだったらsearchParams付けるだけ
2023-01-12 21:40:33 -07:00
u.searchParams.set("static", "1");
return u.href;
}
2023-01-12 21:40:33 -07:00
const dummy = `${u.host}${u.pathname}`; // 拡張子がないとキャッシュしてくれないCDNがあるので
return `${instanceUrl}/proxy/${dummy}?${url.query({
url: u.href,
2023-01-12 21:40:33 -07:00
static: "1",
})}`;
}