mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 16:25:13 +00:00
リモートのファイルをキャッシュするかどうかの設定をDBに保存するように
This commit is contained in:
parent
42e007ddb7
commit
2a5c19cd01
9 changed files with 36 additions and 12 deletions
|
@ -57,15 +57,6 @@ mongodb:
|
||||||
user: example-misskey-user
|
user: example-misskey-user
|
||||||
pass: example-misskey-pass
|
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:
|
drive:
|
||||||
storage: 'db'
|
storage: 'db'
|
||||||
|
|
||||||
|
|
|
@ -1079,6 +1079,8 @@ admin/views/instance.vue:
|
||||||
instance-description: "インスタンスの紹介"
|
instance-description: "インスタンスの紹介"
|
||||||
banner-url: "バナー画像URL"
|
banner-url: "バナー画像URL"
|
||||||
drive-config: "ドライブの設定"
|
drive-config: "ドライブの設定"
|
||||||
|
cache-remote-files: "リモートのファイルをキャッシュする"
|
||||||
|
cache-remote-files-desc: "この設定を無効にすると、リモートファイルをキャッシュせず直リンクするようになります。そのためサーバーのストレージを節約できますが、プライバシー設定で直リンクを無効にしているユーザーにはファイルが見えなくなったり、サムネイルが生成されないので通信量が増加します。通常はこの設定をオンにしておくことをおすすめします。"
|
||||||
local-drive-capacity-mb: "ローカルユーザーひとりあたりのドライブ容量"
|
local-drive-capacity-mb: "ローカルユーザーひとりあたりのドライブ容量"
|
||||||
remote-drive-capacity-mb: "リモートユーザーひとりあたりのドライブ容量"
|
remote-drive-capacity-mb: "リモートユーザーひとりあたりのドライブ容量"
|
||||||
mb: "メガバイト単位"
|
mb: "メガバイト単位"
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
</section>
|
</section>
|
||||||
<section class="fit-bottom">
|
<section class="fit-bottom">
|
||||||
<header><fa icon="cloud"/> %i18n:@drive-config%</header>
|
<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="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>
|
<ui-input v-model="remoteDriveCapacityMb">%i18n:@remote-drive-capacity-mb%<span slot="text">%i18n:@mb%</span><span slot="suffix">MB</span></ui-input>
|
||||||
</section>
|
</section>
|
||||||
|
@ -49,6 +50,7 @@ export default Vue.extend({
|
||||||
bannerUrl: null,
|
bannerUrl: null,
|
||||||
name: null,
|
name: null,
|
||||||
description: null,
|
description: null,
|
||||||
|
cacheRemoteFiles: false,
|
||||||
localDriveCapacityMb: null,
|
localDriveCapacityMb: null,
|
||||||
remoteDriveCapacityMb: null,
|
remoteDriveCapacityMb: null,
|
||||||
maxNoteTextLength: null,
|
maxNoteTextLength: null,
|
||||||
|
@ -61,6 +63,7 @@ export default Vue.extend({
|
||||||
this.bannerUrl = meta.bannerUrl;
|
this.bannerUrl = meta.bannerUrl;
|
||||||
this.name = meta.name;
|
this.name = meta.name;
|
||||||
this.description = meta.description;
|
this.description = meta.description;
|
||||||
|
this.cacheRemoteFiles = meta.cacheRemoteFiles;
|
||||||
this.localDriveCapacityMb = meta.driveCapacityPerLocalUserMb;
|
this.localDriveCapacityMb = meta.driveCapacityPerLocalUserMb;
|
||||||
this.remoteDriveCapacityMb = meta.driveCapacityPerRemoteUserMb;
|
this.remoteDriveCapacityMb = meta.driveCapacityPerRemoteUserMb;
|
||||||
this.maxNoteTextLength = meta.maxNoteTextLength;
|
this.maxNoteTextLength = meta.maxNoteTextLength;
|
||||||
|
@ -86,6 +89,7 @@ export default Vue.extend({
|
||||||
bannerUrl: this.bannerUrl,
|
bannerUrl: this.bannerUrl,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
description: this.description,
|
description: this.description,
|
||||||
|
cacheRemoteFiles: this.cacheRemoteFiles,
|
||||||
localDriveCapacityMb: parseInt(this.localDriveCapacityMb, 10),
|
localDriveCapacityMb: parseInt(this.localDriveCapacityMb, 10),
|
||||||
remoteDriveCapacityMb: parseInt(this.remoteDriveCapacityMb, 10),
|
remoteDriveCapacityMb: parseInt(this.remoteDriveCapacityMb, 10),
|
||||||
maxNoteTextLength: parseInt(this.maxNoteTextLength, 10)
|
maxNoteTextLength: parseInt(this.maxNoteTextLength, 10)
|
||||||
|
|
|
@ -46,8 +46,6 @@ export type Source = {
|
||||||
secret_key: string;
|
secret_key: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
preventCacheRemoteFiles: boolean;
|
|
||||||
|
|
||||||
drive?: {
|
drive?: {
|
||||||
storage: string;
|
storage: string;
|
||||||
bucket?: string;
|
bucket?: string;
|
||||||
|
|
|
@ -2,6 +2,7 @@ import Meta, { IMeta } from '../models/meta';
|
||||||
|
|
||||||
const defaultMeta: any = {
|
const defaultMeta: any = {
|
||||||
name: 'Misskey',
|
name: 'Misskey',
|
||||||
|
cacheRemoteFiles: true,
|
||||||
localDriveCapacityMb: 256,
|
localDriveCapacityMb: 256,
|
||||||
remoteDriveCapacityMb: 8,
|
remoteDriveCapacityMb: 8,
|
||||||
hidedTags: [],
|
hidedTags: [],
|
||||||
|
|
|
@ -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 = {
|
export type IMeta = {
|
||||||
name?: string;
|
name?: string;
|
||||||
|
@ -66,6 +77,8 @@ export type IMeta = {
|
||||||
hidedTags?: string[];
|
hidedTags?: string[];
|
||||||
bannerUrl?: string;
|
bannerUrl?: string;
|
||||||
|
|
||||||
|
cacheRemoteFiles?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drive capacity of a local user (MB)
|
* Drive capacity of a local user (MB)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -82,6 +82,13 @@ export const meta = {
|
||||||
'en-US': 'Drive capacity of a remote user (MB)'
|
'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;
|
set.remoteDriveCapacityMb = ps.remoteDriveCapacityMb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ps.cacheRemoteFiles !== undefined) {
|
||||||
|
set.cacheRemoteFiles = ps.cacheRemoteFiles;
|
||||||
|
}
|
||||||
|
|
||||||
await Meta.update({}, {
|
await Meta.update({}, {
|
||||||
$set: set
|
$set: set
|
||||||
}, { upsert: true });
|
}, { upsert: true });
|
||||||
|
|
|
@ -59,6 +59,7 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||||
disableLocalTimeline: instance.disableLocalTimeline,
|
disableLocalTimeline: instance.disableLocalTimeline,
|
||||||
driveCapacityPerLocalUserMb: instance.localDriveCapacityMb,
|
driveCapacityPerLocalUserMb: instance.localDriveCapacityMb,
|
||||||
driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb,
|
driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb,
|
||||||
|
cacheRemoteFiles: instance.cacheRemoteFiles,
|
||||||
recaptchaSitekey: config.recaptcha ? config.recaptcha.site_key : null,
|
recaptchaSitekey: config.recaptcha ? config.recaptcha.site_key : null,
|
||||||
swPublickey: config.sw ? config.sw.public_key : null,
|
swPublickey: config.sw ? config.sw.public_key : null,
|
||||||
hidedTags: (me && me.isAdmin) ? instance.hidedTags : undefined,
|
hidedTags: (me && me.isAdmin) ? instance.hidedTags : undefined,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import create from './add-file';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import { IUser } from '../../models/user';
|
import { IUser } from '../../models/user';
|
||||||
import * as mongodb from 'mongodb';
|
import * as mongodb from 'mongodb';
|
||||||
|
import fetchMeta from '../../misc/fetch-meta';
|
||||||
|
|
||||||
const log = debug('misskey:drive:upload-from-url');
|
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);
|
.on('error', rej);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const instance = await fetchMeta();
|
||||||
|
|
||||||
let driveFile: IDriveFile;
|
let driveFile: IDriveFile;
|
||||||
let error;
|
let error;
|
||||||
|
|
||||||
try {
|
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}`);
|
log(`got: ${driveFile._id}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
|
|
Loading…
Reference in a new issue