From 9bc07c1a1ce8c82c7f0d00a78a00f9c6e6a22b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=92=8C=E9=A2=A8=E3=83=89=E3=83=AC=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=B3=E3=82=B0?= <37681609+CookieRamen@users.noreply.github.com> Date: Fri, 20 Dec 2019 01:54:28 +0900 Subject: [PATCH] =?UTF-8?q?Media=20Proxy=20=E3=82=92=E5=AE=9F=E8=A3=85=20(?= =?UTF-8?q?#5649)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Media Proxy を実装 * サンプルを追加 --- .config/example.yml | 3 +++ src/config/types.ts | 2 ++ src/models/repositories/drive-file.ts | 7 ++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.config/example.yml b/.config/example.yml index 44d798bc8..f75224bf7 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -140,3 +140,6 @@ autoAdmin: true #proxySmtp: http://127.0.0.1:3128 # use HTTP/1.1 CONNECT #proxySmtp: socks4://127.0.0.1:1080 # use SOCKS4 #proxySmtp: socks5://127.0.0.1:1080 # use SOCKS5 + +# Media Proxy +#mediaProxy: http://127.0.0.1:3000 diff --git a/src/config/types.ts b/src/config/types.ts index e766d1f14..2bf94af74 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -52,6 +52,8 @@ export type Source = { host: string; port: number; }; + + mediaProxy?: string; }; /** diff --git a/src/models/repositories/drive-file.ts b/src/models/repositories/drive-file.ts index 702f195e9..a20d39304 100644 --- a/src/models/repositories/drive-file.ts +++ b/src/models/repositories/drive-file.ts @@ -6,6 +6,7 @@ import { toPuny } from '../../misc/convert-host'; import { ensure } from '../../prelude/ensure'; import { awaitAll } from '../../prelude/await-all'; import { SchemaType } from '../../misc/schema'; +import config from '../../config'; export type PackedDriveFile = SchemaType; @@ -22,7 +23,11 @@ export class DriveFileRepository extends Repository { } public getPublicUrl(file: DriveFile, thumbnail = false): string | null { - return thumbnail ? (file.thumbnailUrl || file.webpublicUrl || null) : (file.webpublicUrl || file.url); + let url = thumbnail ? (file.thumbnailUrl || file.webpublicUrl || null) : (file.webpublicUrl || file.url); + if (file.src !== null && file.userHost !== null && config.mediaProxy !== null) { + url = `${config.mediaProxy}/${thumbnail ? 'thumbnail' : ''}?url=${file.src}`; + } + return url; } public async clacDriveUsageOf(user: User['id'] | User): Promise {