summaryrefslogtreecommitdiff
path: root/packages/client/src/scripts/get-static-image-url.ts
blob: 79dbcf9325a51b6b96235d68eff398d2c1968802 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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付けるだけ
		u.searchParams.set('static', '1');
		return u.href;
	}
	const dummy = `${u.host}${u.pathname}`;	// 拡張子がないとキャッシュしてくれないCDNがあるので
	return `${instanceUrl}/proxy/${dummy}?${url.query({
		url: u.href,
		static: '1',
	})}`;
}