0
0

リモートのファイルをキャッシュするかどうかの設定をDBに保存するように

This commit is contained in:
syuilo 2018-11-06 07:52:13 +09:00
parent 42e007ddb7
commit 2a5c19cd01
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
9 changed files with 36 additions and 12 deletions

View File

@ -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'

View File

@ -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: "メガバイト単位"

View File

@ -12,6 +12,7 @@
</section>
<section class="fit-bottom">
<header><fa icon="cloud"/> %i18n:@drive-config%</header>
<ui-switch v-model="cacheRemoteFiles">%i18n:@cache-remote-files%<span slot="desc">%i18n:@cache-remote-files-desc%</span></ui-switch>
<ui-input v-model="localDriveCapacityMb">%i18n:@local-drive-capacity-mb%<span slot="text">%i18n:@mb%</span><span slot="suffix">MB</span></ui-input>
<ui-input v-model="remoteDriveCapacityMb">%i18n:@remote-drive-capacity-mb%<span slot="text">%i18n:@mb%</span><span slot="suffix">MB</span></ui-input>
</section>
@ -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)

View File

@ -46,8 +46,6 @@ export type Source = {
secret_key: string;
};
preventCacheRemoteFiles: boolean;
drive?: {
storage: string;
bucket?: string;

View File

@ -2,6 +2,7 @@ import Meta, { IMeta } from '../models/meta';
const defaultMeta: any = {
name: 'Misskey',
cacheRemoteFiles: true,
localDriveCapacityMb: 256,
remoteDriveCapacityMb: 8,
hidedTags: [],

View File

@ -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)
*/

View File

@ -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 });

View File

@ -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,

View File

@ -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;