From 6458239a7cf6f2767d7a7988ed306558c0b87fa5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 13 Jan 2023 11:14:07 +0900 Subject: [PATCH] =?UTF-8?q?remoteDriveCapacityMb=E3=82=92=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=81=AB=E7=B5=B1=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/migration/1673575973645-MetaClean.js | 11 +++++++++++ packages/backend/src/core/DriveService.ts | 16 +++++----------- packages/backend/src/models/entities/Meta.ts | 6 ------ .../src/server/api/endpoints/admin/meta.ts | 5 ----- .../server/api/endpoints/admin/update-meta.ts | 5 ----- .../backend/src/server/api/endpoints/meta.ts | 5 ----- packages/frontend/src/pages/admin/settings.vue | 9 --------- 7 files changed, 16 insertions(+), 41 deletions(-) create mode 100644 packages/backend/migration/1673575973645-MetaClean.js diff --git a/packages/backend/migration/1673575973645-MetaClean.js b/packages/backend/migration/1673575973645-MetaClean.js new file mode 100644 index 0000000000..11be4c1cdd --- /dev/null +++ b/packages/backend/migration/1673575973645-MetaClean.js @@ -0,0 +1,11 @@ +export class MetaClean1673575973645 { + name = 'MetaClean1673575973645' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "remoteDriveCapacityMb"`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" ADD "remoteDriveCapacityMb" integer NOT NULL DEFAULT '32'`); + } +} diff --git a/packages/backend/src/core/DriveService.ts b/packages/backend/src/core/DriveService.ts index 747dfd6130..9002c96a65 100644 --- a/packages/backend/src/core/DriveService.ts +++ b/packages/backend/src/core/DriveService.ts @@ -386,7 +386,7 @@ export class DriveService { }, err => { this.registerLogger.error(`Upload Failed: key = ${key}, filename = ${filename}`, err); - } + }, ); } @@ -479,16 +479,10 @@ export class DriveService { if (user && !isLink) { const usage = await this.driveFileEntityService.calcDriveUsageOf(user); - let driveCapacity: number; - if (this.userEntityService.isLocalUser(user)) { - const role = await this.roleService.getUserRoleOptions(user.id); - driveCapacity = 1024 * 1024 * role.driveCapacityMb; - this.registerLogger.debug('drive capacity override applied'); - this.registerLogger.debug(`overrideCap: ${driveCapacity}bytes, usage: ${usage}bytes, u+s: ${usage + info.size}bytes`); - } else { - const instance = await this.metaService.fetch(); - driveCapacity = 1024 * 1024 * instance.remoteDriveCapacityMb; - } + const role = await this.roleService.getUserRoleOptions(user.id); + const driveCapacity = 1024 * 1024 * role.driveCapacityMb; + this.registerLogger.debug('drive capacity override applied'); + this.registerLogger.debug(`overrideCap: ${driveCapacity}bytes, usage: ${usage}bytes, u+s: ${usage + info.size}bytes`); this.registerLogger.debug(`drive usage is ${usage} (max: ${driveCapacity})`); diff --git a/packages/backend/src/models/entities/Meta.ts b/packages/backend/src/models/entities/Meta.ts index 0d65a8d17a..e724ba9a49 100644 --- a/packages/backend/src/models/entities/Meta.ts +++ b/packages/backend/src/models/entities/Meta.ts @@ -217,12 +217,6 @@ export class Meta { }) public enableSensitiveMediaDetectionForVideos: boolean; - @Column('integer', { - default: 32, - comment: 'Drive capacity of a remote user (MB)', - }) - public remoteDriveCapacityMb: number; - @Column('varchar', { length: 128, nullable: true, diff --git a/packages/backend/src/server/api/endpoints/admin/meta.ts b/packages/backend/src/server/api/endpoints/admin/meta.ts index 33f162acf9..fd08a5f847 100644 --- a/packages/backend/src/server/api/endpoints/admin/meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/meta.ts @@ -16,10 +16,6 @@ export const meta = { type: 'object', optional: false, nullable: false, properties: { - driveCapacityPerRemoteUserMb: { - type: 'number', - optional: false, nullable: false, - }, cacheRemoteFiles: { type: 'boolean', optional: false, nullable: false, @@ -374,7 +370,6 @@ export default class extends Endpoint { repositoryUrl: instance.repositoryUrl, feedbackUrl: instance.feedbackUrl, disableRegistration: instance.disableRegistration, - driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb, emailRequiredForSignup: instance.emailRequiredForSignup, enableHcaptcha: instance.enableHcaptcha, hcaptchaSiteKey: instance.hcaptchaSiteKey, diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts index c766494e6b..c5b44b6b86 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -40,7 +40,6 @@ export const paramDef = { description: { type: 'string', nullable: true }, defaultLightTheme: { type: 'string', nullable: true }, defaultDarkTheme: { type: 'string', nullable: true }, - remoteDriveCapacityMb: { type: 'integer' }, cacheRemoteFiles: { type: 'boolean' }, emailRequiredForSignup: { type: 'boolean' }, enableHcaptcha: { type: 'boolean' }, @@ -183,10 +182,6 @@ export default class extends Endpoint { set.defaultDarkTheme = ps.defaultDarkTheme; } - if (ps.remoteDriveCapacityMb !== undefined) { - set.remoteDriveCapacityMb = ps.remoteDriveCapacityMb; - } - if (ps.cacheRemoteFiles !== undefined) { set.cacheRemoteFiles = ps.cacheRemoteFiles; } diff --git a/packages/backend/src/server/api/endpoints/meta.ts b/packages/backend/src/server/api/endpoints/meta.ts index f87fca63e3..f46a32dfe7 100644 --- a/packages/backend/src/server/api/endpoints/meta.ts +++ b/packages/backend/src/server/api/endpoints/meta.ts @@ -78,10 +78,6 @@ export const meta = { type: 'boolean', optional: false, nullable: false, }, - driveCapacityPerRemoteUserMb: { - type: 'number', - optional: false, nullable: false, - }, cacheRemoteFiles: { type: 'boolean', optional: false, nullable: false, @@ -303,7 +299,6 @@ export default class extends Endpoint { repositoryUrl: instance.repositoryUrl, feedbackUrl: instance.feedbackUrl, disableRegistration: instance.disableRegistration, - driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb, emailRequiredForSignup: instance.emailRequiredForSignup, enableHcaptcha: instance.enableHcaptcha, hcaptchaSiteKey: instance.hcaptchaSiteKey, diff --git a/packages/frontend/src/pages/admin/settings.vue b/packages/frontend/src/pages/admin/settings.vue index eae822c7c8..12d852a90e 100644 --- a/packages/frontend/src/pages/admin/settings.vue +++ b/packages/frontend/src/pages/admin/settings.vue @@ -91,12 +91,6 @@ - - - - - - @@ -171,7 +165,6 @@ let defaultLightTheme: any = $ref(null); let defaultDarkTheme: any = $ref(null); let pinnedUsers: string = $ref(''); let cacheRemoteFiles: boolean = $ref(false); -let remoteDriveCapacityMb: any = $ref(0); let enableRegistration: boolean = $ref(false); let emailRequiredForSignup: boolean = $ref(false); let enableServiceWorker: boolean = $ref(false); @@ -195,7 +188,6 @@ async function init() { maintainerEmail = meta.maintainerEmail; pinnedUsers = meta.pinnedUsers.join('\n'); cacheRemoteFiles = meta.cacheRemoteFiles; - remoteDriveCapacityMb = meta.driveCapacityPerRemoteUserMb; enableRegistration = !meta.disableRegistration; emailRequiredForSignup = meta.emailRequiredForSignup; enableServiceWorker = meta.enableServiceWorker; @@ -220,7 +212,6 @@ function save() { maintainerEmail, pinnedUsers: pinnedUsers.split('\n'), cacheRemoteFiles, - remoteDriveCapacityMb: parseInt(remoteDriveCapacityMb, 10), disableRegistration: !enableRegistration, emailRequiredForSignup, enableServiceWorker,