From d6a13b297d018a5078c8d4521d9da20be5aa8499 Mon Sep 17 00:00:00 2001 From: kozakura913 <98575220+kozakura913@users.noreply.github.com> Date: Fri, 21 Jun 2024 00:59:25 +0900 Subject: [PATCH] =?UTF-8?q?remoteProxy=E3=82=A8=E3=83=B3=E3=83=89=E3=83=9D?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=88=E8=A8=AD=E5=AE=9A=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=20(#93)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/docker_example.yml | 4 +++ .config/example.yml | 4 +++ CHANGELOG_yojo.md | 31 +++++++++++++++++++ packages/backend/src/config.ts | 8 +++++ .../core/entities/DriveFileEntityService.ts | 12 +++++++ 5 files changed, 59 insertions(+) create mode 100644 CHANGELOG_yojo.md diff --git a/.config/docker_example.yml b/.config/docker_example.yml index d492bee81d..8b8b14ff6b 100644 --- a/.config/docker_example.yml +++ b/.config/docker_example.yml @@ -187,6 +187,10 @@ proxyBypassHosts: # Media Proxy #mediaProxy: https://example.com/proxy +# Proxy remote files endpoint +# remoteProxy: https://example.com/files/ +# remoteProxy: /files/ + # Proxy remote files (default: true) proxyRemoteFiles: true diff --git a/.config/example.yml b/.config/example.yml index 866d94df1c..b5210e3fde 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -285,6 +285,10 @@ proxyBypassHosts: # * Perform image compression (on a different server resource than the main process) #mediaProxy: https://example.com/proxy +# Proxy remote files endpoint +# remoteProxy: https://example.com/files/ +# remoteProxy: /files/ + # Proxy remote files (default: true) # Proxy remote files by this instance or mediaProxy to prevent remote files from running in remote domains. proxyRemoteFiles: true diff --git a/CHANGELOG_yojo.md b/CHANGELOG_yojo.md new file mode 100644 index 0000000000..3706f167fc --- /dev/null +++ b/CHANGELOG_yojo.md @@ -0,0 +1,31 @@ + +## 0.1.0 (unreleased) + +### Release Date +2024-03-09 + +### General +- メディアプロキシurlと拡大画像urlを分割 + +### Server +- remoteProxyエンドポイント設定を追加 + +### Others +- engawaをマージ +- cherrypickからフォーク diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 7ba2e568a2..d93582112b 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -102,6 +102,7 @@ type Source = { apFileBaseUrl?: string; mediaProxy?: string; + remoteProxy?: string; proxyRemoteFiles?: boolean; videoThumbnailGenerator?: string; @@ -197,6 +198,7 @@ export type Config = { clientEntry: string; clientManifestExists: boolean; mediaProxy: string; + remoteProxy?: string; externalMediaProxyEnabled: boolean; videoThumbnailGenerator: string | null; redis: RedisOptions & RedisOptionsSource; @@ -246,6 +248,11 @@ export function loadConfig(): Config { config.mediaProxy.endsWith('/') ? config.mediaProxy.substring(0, config.mediaProxy.length - 1) : config.mediaProxy : null; const internalMediaProxy = `${scheme}://${host}/proxy`; + + const remoteProxy = config.remoteProxy ? + config.remoteProxy.endsWith('/') ? config.remoteProxy.substring(0, config.remoteProxy.length - 1) : config.remoteProxy + : null; + const redis = convertRedisOptions(config.redis, host); return { @@ -297,6 +304,7 @@ export function loadConfig(): Config { apFileBaseUrl: config.apFileBaseUrl, mediaProxy: externalMediaProxy ?? internalMediaProxy, externalMediaProxyEnabled: externalMediaProxy !== null && externalMediaProxy !== internalMediaProxy, + remoteProxy, videoThumbnailGenerator: config.videoThumbnailGenerator ? config.videoThumbnailGenerator.endsWith('/') ? config.videoThumbnailGenerator.substring(0, config.videoThumbnailGenerator.length - 1) : config.videoThumbnailGenerator : null, diff --git a/packages/backend/src/core/entities/DriveFileEntityService.ts b/packages/backend/src/core/entities/DriveFileEntityService.ts index 15782b9298..0e1c7f49bc 100644 --- a/packages/backend/src/core/entities/DriveFileEntityService.ts +++ b/packages/backend/src/core/entities/DriveFileEntityService.ts @@ -110,6 +110,18 @@ export class DriveFileEntityService { @bindThis public getPublicUrl(file: MiDriveFile, mode?: 'avatar', ap?: boolean): string { // static = thumbnail + // PublicUrlにはexternalMediaProxyEnabledでもremoteProxyを使う + // https://github.com/yojo-art/cherrypick/issues/84 + if (file.uri != null && file.userHost != null && mode !== 'avatar' && this.config.remoteProxy != null) { + //下のローカルプロキシからコピペで持ってきた + const key = file.webpublicAccessKey; + if (key && !key.match('/')) { // 古いものはここにオブジェクトストレージキーが入ってるので除外 + if (this.config.remoteProxy.startsWith('/')) { + return `${this.config.url}${this.config.remoteProxy}/${key}`; + } + return `${this.config.remoteProxy}/${key}`; + } + } // リモートかつメディアプロキシ if (file.uri != null && file.userHost != null && this.config.externalMediaProxyEnabled) { return this.getProxiedUrl(file.uri, mode);