remoteDriveCapacityMbをロールに統合

This commit is contained in:
syuilo 2023-01-13 11:14:07 +09:00
parent a5aaa032ca
commit 6458239a7c
7 changed files with 16 additions and 41 deletions

View file

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

View file

@ -386,7 +386,7 @@ export class DriveService {
}, },
err => { err => {
this.registerLogger.error(`Upload Failed: key = ${key}, filename = ${filename}`, err); this.registerLogger.error(`Upload Failed: key = ${key}, filename = ${filename}`, err);
} },
); );
} }
@ -479,16 +479,10 @@ export class DriveService {
if (user && !isLink) { if (user && !isLink) {
const usage = await this.driveFileEntityService.calcDriveUsageOf(user); const usage = await this.driveFileEntityService.calcDriveUsageOf(user);
let driveCapacity: number; const role = await this.roleService.getUserRoleOptions(user.id);
if (this.userEntityService.isLocalUser(user)) { const driveCapacity = 1024 * 1024 * role.driveCapacityMb;
const role = await this.roleService.getUserRoleOptions(user.id); this.registerLogger.debug('drive capacity override applied');
driveCapacity = 1024 * 1024 * role.driveCapacityMb; this.registerLogger.debug(`overrideCap: ${driveCapacity}bytes, usage: ${usage}bytes, u+s: ${usage + info.size}bytes`);
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;
}
this.registerLogger.debug(`drive usage is ${usage} (max: ${driveCapacity})`); this.registerLogger.debug(`drive usage is ${usage} (max: ${driveCapacity})`);

View file

@ -217,12 +217,6 @@ export class Meta {
}) })
public enableSensitiveMediaDetectionForVideos: boolean; public enableSensitiveMediaDetectionForVideos: boolean;
@Column('integer', {
default: 32,
comment: 'Drive capacity of a remote user (MB)',
})
public remoteDriveCapacityMb: number;
@Column('varchar', { @Column('varchar', {
length: 128, length: 128,
nullable: true, nullable: true,

View file

@ -16,10 +16,6 @@ export const meta = {
type: 'object', type: 'object',
optional: false, nullable: false, optional: false, nullable: false,
properties: { properties: {
driveCapacityPerRemoteUserMb: {
type: 'number',
optional: false, nullable: false,
},
cacheRemoteFiles: { cacheRemoteFiles: {
type: 'boolean', type: 'boolean',
optional: false, nullable: false, optional: false, nullable: false,
@ -374,7 +370,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
repositoryUrl: instance.repositoryUrl, repositoryUrl: instance.repositoryUrl,
feedbackUrl: instance.feedbackUrl, feedbackUrl: instance.feedbackUrl,
disableRegistration: instance.disableRegistration, disableRegistration: instance.disableRegistration,
driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb,
emailRequiredForSignup: instance.emailRequiredForSignup, emailRequiredForSignup: instance.emailRequiredForSignup,
enableHcaptcha: instance.enableHcaptcha, enableHcaptcha: instance.enableHcaptcha,
hcaptchaSiteKey: instance.hcaptchaSiteKey, hcaptchaSiteKey: instance.hcaptchaSiteKey,

View file

@ -40,7 +40,6 @@ export const paramDef = {
description: { type: 'string', nullable: true }, description: { type: 'string', nullable: true },
defaultLightTheme: { type: 'string', nullable: true }, defaultLightTheme: { type: 'string', nullable: true },
defaultDarkTheme: { type: 'string', nullable: true }, defaultDarkTheme: { type: 'string', nullable: true },
remoteDriveCapacityMb: { type: 'integer' },
cacheRemoteFiles: { type: 'boolean' }, cacheRemoteFiles: { type: 'boolean' },
emailRequiredForSignup: { type: 'boolean' }, emailRequiredForSignup: { type: 'boolean' },
enableHcaptcha: { type: 'boolean' }, enableHcaptcha: { type: 'boolean' },
@ -183,10 +182,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
set.defaultDarkTheme = ps.defaultDarkTheme; set.defaultDarkTheme = ps.defaultDarkTheme;
} }
if (ps.remoteDriveCapacityMb !== undefined) {
set.remoteDriveCapacityMb = ps.remoteDriveCapacityMb;
}
if (ps.cacheRemoteFiles !== undefined) { if (ps.cacheRemoteFiles !== undefined) {
set.cacheRemoteFiles = ps.cacheRemoteFiles; set.cacheRemoteFiles = ps.cacheRemoteFiles;
} }

View file

@ -78,10 +78,6 @@ export const meta = {
type: 'boolean', type: 'boolean',
optional: false, nullable: false, optional: false, nullable: false,
}, },
driveCapacityPerRemoteUserMb: {
type: 'number',
optional: false, nullable: false,
},
cacheRemoteFiles: { cacheRemoteFiles: {
type: 'boolean', type: 'boolean',
optional: false, nullable: false, optional: false, nullable: false,
@ -303,7 +299,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
repositoryUrl: instance.repositoryUrl, repositoryUrl: instance.repositoryUrl,
feedbackUrl: instance.feedbackUrl, feedbackUrl: instance.feedbackUrl,
disableRegistration: instance.disableRegistration, disableRegistration: instance.disableRegistration,
driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb,
emailRequiredForSignup: instance.emailRequiredForSignup, emailRequiredForSignup: instance.emailRequiredForSignup,
enableHcaptcha: instance.enableHcaptcha, enableHcaptcha: instance.enableHcaptcha,
hcaptchaSiteKey: instance.hcaptchaSiteKey, hcaptchaSiteKey: instance.hcaptchaSiteKey,

View file

@ -91,12 +91,6 @@
<template #label>{{ i18n.ts.cacheRemoteFiles }}</template> <template #label>{{ i18n.ts.cacheRemoteFiles }}</template>
<template #caption>{{ i18n.ts.cacheRemoteFilesDescription }}</template> <template #caption>{{ i18n.ts.cacheRemoteFilesDescription }}</template>
</MkSwitch> </MkSwitch>
<MkInput v-model="remoteDriveCapacityMb" type="number" :disabled="!cacheRemoteFiles">
<template #label>{{ i18n.ts.driveCapacityPerRemoteAccount }}</template>
<template #suffix>MB</template>
<template #caption>{{ i18n.ts.inMb }}</template>
</MkInput>
</div> </div>
</FormSection> </FormSection>
@ -171,7 +165,6 @@ let defaultLightTheme: any = $ref(null);
let defaultDarkTheme: any = $ref(null); let defaultDarkTheme: any = $ref(null);
let pinnedUsers: string = $ref(''); let pinnedUsers: string = $ref('');
let cacheRemoteFiles: boolean = $ref(false); let cacheRemoteFiles: boolean = $ref(false);
let remoteDriveCapacityMb: any = $ref(0);
let enableRegistration: boolean = $ref(false); let enableRegistration: boolean = $ref(false);
let emailRequiredForSignup: boolean = $ref(false); let emailRequiredForSignup: boolean = $ref(false);
let enableServiceWorker: boolean = $ref(false); let enableServiceWorker: boolean = $ref(false);
@ -195,7 +188,6 @@ async function init() {
maintainerEmail = meta.maintainerEmail; maintainerEmail = meta.maintainerEmail;
pinnedUsers = meta.pinnedUsers.join('\n'); pinnedUsers = meta.pinnedUsers.join('\n');
cacheRemoteFiles = meta.cacheRemoteFiles; cacheRemoteFiles = meta.cacheRemoteFiles;
remoteDriveCapacityMb = meta.driveCapacityPerRemoteUserMb;
enableRegistration = !meta.disableRegistration; enableRegistration = !meta.disableRegistration;
emailRequiredForSignup = meta.emailRequiredForSignup; emailRequiredForSignup = meta.emailRequiredForSignup;
enableServiceWorker = meta.enableServiceWorker; enableServiceWorker = meta.enableServiceWorker;
@ -220,7 +212,6 @@ function save() {
maintainerEmail, maintainerEmail,
pinnedUsers: pinnedUsers.split('\n'), pinnedUsers: pinnedUsers.split('\n'),
cacheRemoteFiles, cacheRemoteFiles,
remoteDriveCapacityMb: parseInt(remoteDriveCapacityMb, 10),
disableRegistration: !enableRegistration, disableRegistration: !enableRegistration,
emailRequiredForSignup, emailRequiredForSignup,
enableServiceWorker, enableServiceWorker,