diff --git a/.config/example.yml b/.config/example.yml index abbbea50a..63142e86e 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -57,15 +57,6 @@ mongodb: user: example-misskey-user pass: example-misskey-pass -# If enabled: -# Server will not cache remote files (Using direct link instead). -# You can save your storage. -# -# NOTE: -# * Users cannot see remote images when they turn off "Show media from a remote server" setting. -# * Since thumbnails are not provided, traffic increases. -preventCacheRemoteFiles: false - drive: storage: 'db' diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 0528a511c..7794bebc2 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1079,6 +1079,8 @@ admin/views/instance.vue: instance-description: "インスタンスの紹介" banner-url: "バナー画像URL" drive-config: "ドライブの設定" + cache-remote-files: "リモートのファイルをキャッシュする" + cache-remote-files-desc: "この設定を無効にすると、リモートファイルをキャッシュせず直リンクするようになります。そのためサーバーのストレージを節約できますが、プライバシー設定で直リンクを無効にしているユーザーにはファイルが見えなくなったり、サムネイルが生成されないので通信量が増加します。通常はこの設定をオンにしておくことをおすすめします。" local-drive-capacity-mb: "ローカルユーザーひとりあたりのドライブ容量" remote-drive-capacity-mb: "リモートユーザーひとりあたりのドライブ容量" mb: "メガバイト単位" diff --git a/src/client/app/admin/views/instance.vue b/src/client/app/admin/views/instance.vue index 9a7f8d556..4d7965e70 100644 --- a/src/client/app/admin/views/instance.vue +++ b/src/client/app/admin/views/instance.vue @@ -12,6 +12,7 @@
%i18n:@drive-config%
+ %i18n:@cache-remote-files%%i18n:@cache-remote-files-desc% %i18n:@local-drive-capacity-mb%%i18n:@mb%MB %i18n:@remote-drive-capacity-mb%%i18n:@mb%MB
@@ -49,6 +50,7 @@ export default Vue.extend({ bannerUrl: null, name: null, description: null, + cacheRemoteFiles: false, localDriveCapacityMb: null, remoteDriveCapacityMb: null, maxNoteTextLength: null, @@ -61,6 +63,7 @@ export default Vue.extend({ this.bannerUrl = meta.bannerUrl; this.name = meta.name; this.description = meta.description; + this.cacheRemoteFiles = meta.cacheRemoteFiles; this.localDriveCapacityMb = meta.driveCapacityPerLocalUserMb; this.remoteDriveCapacityMb = meta.driveCapacityPerRemoteUserMb; this.maxNoteTextLength = meta.maxNoteTextLength; @@ -86,6 +89,7 @@ export default Vue.extend({ bannerUrl: this.bannerUrl, name: this.name, description: this.description, + cacheRemoteFiles: this.cacheRemoteFiles, localDriveCapacityMb: parseInt(this.localDriveCapacityMb, 10), remoteDriveCapacityMb: parseInt(this.remoteDriveCapacityMb, 10), maxNoteTextLength: parseInt(this.maxNoteTextLength, 10) diff --git a/src/config/types.ts b/src/config/types.ts index f1cbb84c8..e6fe6a67c 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -46,8 +46,6 @@ export type Source = { secret_key: string; }; - preventCacheRemoteFiles: boolean; - drive?: { storage: string; bucket?: string; diff --git a/src/misc/fetch-meta.ts b/src/misc/fetch-meta.ts index 778aa029c..fde244d1c 100644 --- a/src/misc/fetch-meta.ts +++ b/src/misc/fetch-meta.ts @@ -2,6 +2,7 @@ import Meta, { IMeta } from '../models/meta'; const defaultMeta: any = { name: 'Misskey', + cacheRemoteFiles: true, localDriveCapacityMb: 256, remoteDriveCapacityMb: 8, hidedTags: [], diff --git a/src/models/meta.ts b/src/models/meta.ts index 7caf41f19..073be7de8 100644 --- a/src/models/meta.ts +++ b/src/models/meta.ts @@ -50,6 +50,17 @@ if ((config as any).remoteDriveCapacityMb) { } }); } +if ((config as any).preventCacheRemoteFiles) { + Meta.findOne({}).then(m => { + if (m != null && m.cacheRemoteFiles == null) { + Meta.update({}, { + $set: { + cacheRemoteFiles: !(config as any).preventCacheRemoteFiles + } + }); + } + }); +} export type IMeta = { name?: string; @@ -66,6 +77,8 @@ export type IMeta = { hidedTags?: string[]; bannerUrl?: string; + cacheRemoteFiles?: boolean; + /** * Drive capacity of a local user (MB) */ diff --git a/src/server/api/endpoints/admin/update-meta.ts b/src/server/api/endpoints/admin/update-meta.ts index 4c4a3ac85..b4b2b231a 100644 --- a/src/server/api/endpoints/admin/update-meta.ts +++ b/src/server/api/endpoints/admin/update-meta.ts @@ -82,6 +82,13 @@ export const meta = { 'en-US': 'Drive capacity of a remote user (MB)' } }, + + cacheRemoteFiles: { + validator: $.bool.optional, + desc: { + 'ja-JP': 'リモートのファイルをキャッシュするか否か' + } + } } }; @@ -128,6 +135,10 @@ export default define(meta, (ps) => new Promise(async (res, rej) => { set.remoteDriveCapacityMb = ps.remoteDriveCapacityMb; } + if (ps.cacheRemoteFiles !== undefined) { + set.cacheRemoteFiles = ps.cacheRemoteFiles; + } + await Meta.update({}, { $set: set }, { upsert: true }); diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts index f7a5ed4f1..e3d3ad520 100644 --- a/src/server/api/endpoints/meta.ts +++ b/src/server/api/endpoints/meta.ts @@ -59,6 +59,7 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => { disableLocalTimeline: instance.disableLocalTimeline, driveCapacityPerLocalUserMb: instance.localDriveCapacityMb, driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb, + cacheRemoteFiles: instance.cacheRemoteFiles, recaptchaSitekey: config.recaptcha ? config.recaptcha.site_key : null, swPublickey: config.sw ? config.sw.public_key : null, hidedTags: (me && me.isAdmin) ? instance.hidedTags : undefined, diff --git a/src/services/drive/upload-from-url.ts b/src/services/drive/upload-from-url.ts index 2184edf00..7d4785be0 100644 --- a/src/services/drive/upload-from-url.ts +++ b/src/services/drive/upload-from-url.ts @@ -10,6 +10,7 @@ import create from './add-file'; import config from '../../config'; import { IUser } from '../../models/user'; import * as mongodb from 'mongodb'; +import fetchMeta from '../../misc/fetch-meta'; const log = debug('misskey:drive:upload-from-url'); @@ -51,11 +52,13 @@ export default async (url: string, user: IUser, folderId: mongodb.ObjectID = nul .on('error', rej); }); + const instance = await fetchMeta(); + let driveFile: IDriveFile; let error; try { - driveFile = await create(user, path, name, null, folderId, false, config.preventCacheRemoteFiles, url, uri, sensitive); + driveFile = await create(user, path, name, null, folderId, false, !instance.cacheRemoteFiles, url, uri, sensitive); log(`got: ${driveFile._id}`); } catch (e) { error = e;