perf(server): improvement of external mediaProxy (#9787)
* perf(server): improvement of external mediaProxy * add a comment * ✌️ * /filesでsharpの処理を行わずリダイレクトする * fix * thumbnail => static * Fix #9788 * add avatar mode * add url * fix * static.webp * remove encodeURIComponent from media proxy path * remove existance check
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { query, appendQuery } from '@/scripts/url';
|
||||
import { url } from '@/config';
|
||||
import { instance } from '@/instance';
|
||||
|
||||
export function getProxiedImageUrl(imageUrl: string, type?: 'preview'): string {
|
||||
if (imageUrl.startsWith(`${url}/proxy/`) || imageUrl.startsWith('/proxy/')) {
|
||||
if (imageUrl.startsWith(instance.mediaProxy + '/') || imageUrl.startsWith('/proxy/')) {
|
||||
// もう既にproxyっぽそうだったらsearchParams付けるだけ
|
||||
return appendQuery(imageUrl, query({
|
||||
fallback: '1',
|
||||
@@ -10,7 +11,7 @@ export function getProxiedImageUrl(imageUrl: string, type?: 'preview'): string {
|
||||
}));
|
||||
}
|
||||
|
||||
return `${url}/proxy/image.webp?${query({
|
||||
return `${instance.mediaProxy}/image.webp?${query({
|
||||
url: imageUrl,
|
||||
fallback: '1',
|
||||
...(type ? { [type]: '1' } : {}),
|
||||
@@ -25,22 +26,19 @@ export function getProxiedImageUrlNullable(imageUrl: string | null | undefined,
|
||||
export function getStaticImageUrl(baseUrl: string): string {
|
||||
const u = baseUrl.startsWith('http') ? new URL(baseUrl) : new URL(baseUrl, url);
|
||||
|
||||
if (u.href.startsWith(`${url}/proxy/`)) {
|
||||
// もう既にproxyっぽそうだったらsearchParams付けるだけ
|
||||
u.searchParams.set('static', '1');
|
||||
return u.href;
|
||||
}
|
||||
|
||||
if (u.href.startsWith(`${url}/emoji/`)) {
|
||||
// もう既にemojiっぽそうだったらsearchParams付けるだけ
|
||||
u.searchParams.set('static', '1');
|
||||
return u.href;
|
||||
}
|
||||
|
||||
// 拡張子がないとキャッシュしてくれないCDNがあるのでダミーの名前を指定する
|
||||
const dummy = `${encodeURIComponent(`${u.host}${u.pathname}`)}.webp`;
|
||||
if (u.href.startsWith(instance.mediaProxy + '/')) {
|
||||
// もう既にproxyっぽそうだったらsearchParams付けるだけ
|
||||
u.searchParams.set('static', '1');
|
||||
return u.href;
|
||||
}
|
||||
|
||||
return `${url}/proxy/${dummy}?${query({
|
||||
return `${instance.mediaProxy}/static.webp?${query({
|
||||
url: u.href,
|
||||
static: '1',
|
||||
})}`;
|
||||
|
Reference in New Issue
Block a user