From 297a7f541e497211cf3d34965417c6c137540b63 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 21 Jul 2018 19:17:15 +0900 Subject: [PATCH] #1947 --- .config/example.yml | 6 ++++++ src/config/load.ts | 3 +++ src/config/types.ts | 2 ++ src/docs/api/entities/user.yaml | 7 ------- src/models/user.ts | 2 -- src/remote/activitypub/models/person.ts | 1 - src/server/api/endpoints/drive.ts | 3 ++- src/server/api/private/signup.ts | 1 - src/services/drive/add-file.ts | 5 ++++- 9 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.config/example.yml b/.config/example.yml index a9289dfd4..6c939a4f3 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -41,6 +41,12 @@ redis: port: 6379 pass: example-pass +# Drive capacity of a local user (MB) +localDriveCapacityMb: 256 + +# Drive capacity of a remote user (MB) +remoteDriveCapacityMb: 8 + # If enabled: # Server will not cache remote files (Using direct link instead). # You can save your storage. diff --git a/src/config/load.ts b/src/config/load.ts index d0f659a68..44a24c96a 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -44,6 +44,9 @@ export default function load() { mixin.status_url = `${mixin.scheme}://${mixin.host}/status`; mixin.drive_url = `${mixin.scheme}://${mixin.host}/files`; + if (config.localDriveCapacityMb == null) config.localDriveCapacityMb = 256; + if (config.remoteDriveCapacityMb == null) config.remoteDriveCapacityMb = 8; + return Object.assign(config, mixin); } diff --git a/src/config/types.ts b/src/config/types.ts index aa4357aa5..c26ff9db9 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -45,6 +45,8 @@ export type Source = { secret_key: string; }; + localDriveCapacityMb: number; + remoteDriveCapacityMb: number; preventCacheRemoteFiles: boolean; /** diff --git a/src/docs/api/entities/user.yaml b/src/docs/api/entities/user.yaml index 22613e02f..c24597456 100644 --- a/src/docs/api/entities/user.yaml +++ b/src/docs/api/entities/user.yaml @@ -115,13 +115,6 @@ props: ja: "ピン留めされた投稿のID" en: "The ID of the pinned note of this user" - driveCapacity: - type: "number" - optional: false - desc: - ja: "ドライブの容量(bytes)" - en: "The capacity of drive of this user (bytes)" - host: type: "string | null" optional: false diff --git a/src/models/user.ts b/src/models/user.ts index b4daa906c..8ba788331 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -43,7 +43,6 @@ type IUserBase = { followingCount: number; name?: string; notesCount: number; - driveCapacity: number; username: string; usernameLower: string; avatarId: mongo.ObjectID; @@ -418,7 +417,6 @@ export const pack = ( if (!meId || !meId.equals(_user.id) || !opts.detail) { delete _user.avatarId; delete _user.bannerId; - delete _user.driveCapacity; delete _user.hasUnreadMessagingMessage; delete _user.hasUnreadNotification; } diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index c6f3e8911..eee4aa1bf 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -107,7 +107,6 @@ export async function createPerson(value: any, resolver?: Resolver): Promise new Promise(async (res, rej) = }); res({ - capacity: user.driveCapacity, + capacity: 1024 * 1024 * config.localDriveCapacityMb, usage: usage }); }); diff --git a/src/server/api/private/signup.ts b/src/server/api/private/signup.ts index 2346222b6..b969b75fc 100644 --- a/src/server/api/private/signup.ts +++ b/src/server/api/private/signup.ts @@ -72,7 +72,6 @@ export default async (ctx: Koa.Context) => { followingCount: 0, name: null, notesCount: 0, - driveCapacity: 1024 * 1024 * 128, // 128MiB username: username, usernameLower: username.toLowerCase(), host: null, diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts index 73d5b4962..f7c8922b5 100644 --- a/src/services/drive/add-file.ts +++ b/src/services/drive/add-file.ts @@ -17,6 +17,7 @@ import { isLocalUser, IUser, IRemoteUser } from '../../models/user'; import { getDriveFileThumbnailBucket } from '../../models/drive-file-thumbnail'; import genThumbnail from '../../drive/gen-thumbnail'; import delFile from './delete-file'; +import config from '../../config'; const gm = _gm.subClass({ imageMagick: true @@ -175,8 +176,10 @@ export default async function( log(`drive usage is ${usage}`); + const driveCapacity = 1024 * 1024 * (isLocalUser(user) ? config.localDriveCapacityMb : config.remoteDriveCapacityMb); + // If usage limit exceeded - if (usage + size > user.driveCapacity) { + if (usage + size > driveCapacity) { if (isLocalUser(user)) { throw 'no-free-space'; } else {