Skip to content

Commit

Permalink
Drive: Resolve #143
Browse files Browse the repository at this point in the history
  • Loading branch information
fs5m8 committed Feb 12, 2022
1 parent 2322d08 commit f954ab7
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@ admin/views/instance.vue:
proxy-remote-files: "Proxy remote files"
proxy-remote-files-desc: "If enabled, Remote files that not stored locally or deleted by storage overusage will be proxied locally and also thumbnails will be generated."
local-drive-capacity-mb: "Volume of Drive per user"
premium-drive-capacity-mb: "Volume of Drive per premium user"
remote-drive-capacity-mb: "Volume of Drive per remote user"
mb: "In megabytes"
recaptcha-config: "the reCAPTCHA settings"
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,7 @@ admin/views/instance.vue:
proxy-remote-files: "リモートのファイルをプロキシする"
proxy-remote-files-desc: "この設定を有効にすると、未保存または保存容量超過で削除されたリモートファイルをローカルでプロキシし、サムネイルも生成するようになります。"
local-drive-capacity-mb: "ローカルユーザーひとりあたりのドライブ容量"
premium-drive-capacity-mb: "プレミアムユーザーひとりあたりのドライブ容量"
remote-drive-capacity-mb: "リモートユーザーひとりあたりのドライブ容量"
mb: "メガバイト単位"
recaptcha-config: "reCAPTCHAの設定"
Expand Down
13 changes: 13 additions & 0 deletions migration/1570091775183-PremiumDrive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class PremiumDrive1570091775183 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "meta" ADD "premiumDriveCapacityMb" integer NOT NULL DEFAULT 2048`, undefined);
}

public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "premiumDriveCapacityMb"`, undefined);
}

}
4 changes: 4 additions & 0 deletions src/client/app/admin/views/instance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
</section>
<section class="fit-top fit-bottom">
<ui-input v-model="localDriveCapacityMb" type="number">{{ $t('local-drive-capacity-mb') }}<template #suffix>MB</template><template #desc>{{ $t('mb') }}</template></ui-input>
<ui-input v-model="premiumDriveCapacityMb" type="number">{{ $t('premium-drive-capacity-mb') }}<template #suffix>MB</template><template #desc>{{ $t('mb') }}</template></ui-input>
<ui-input v-model="remoteDriveCapacityMb" type="number" :disabled="!cacheRemoteFiles">{{ $t('remote-drive-capacity-mb') }}<template #suffix>MB</template><template #desc>{{ $t('mb') }}</template></ui-input>
</section>
<section>
Expand Down Expand Up @@ -281,6 +282,7 @@ export default Vue.extend({
cacheRemoteFiles: false,
proxyRemoteFiles: false,
localDriveCapacityMb: null,
premiumDriveCapacityMb: null,
remoteDriveCapacityMb: null,
maxNoteTextLength: null,
enableRecaptcha: false,
Expand Down Expand Up @@ -349,6 +351,7 @@ export default Vue.extend({
this.cacheRemoteFiles = meta.cacheRemoteFiles;
this.proxyRemoteFiles = meta.proxyRemoteFiles;
this.localDriveCapacityMb = meta.driveCapacityPerLocalUserMb;
this.premiumDriveCapacityMb = meta.driveCapacityPerPremiumUserMb;
this.remoteDriveCapacityMb = meta.driveCapacityPerRemoteUserMb;
this.maxNoteTextLength = meta.maxNoteTextLength;
this.enableRecaptcha = meta.enableRecaptcha;
Expand Down Expand Up @@ -477,6 +480,7 @@ export default Vue.extend({
cacheRemoteFiles: this.cacheRemoteFiles,
proxyRemoteFiles: this.proxyRemoteFiles,
localDriveCapacityMb: parseInt(this.localDriveCapacityMb, 10),
premiumDriveCapacityMb: parseInt(this.premiumDriveCapacityMb, 10),
remoteDriveCapacityMb: parseInt(this.remoteDriveCapacityMb, 10),
maxNoteTextLength: parseInt(this.maxNoteTextLength, 10),
enableRecaptcha: this.enableRecaptcha,
Expand Down
7 changes: 7 additions & 0 deletions src/misc/get-drive-capacity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { User } from '../models/entities/user';
import { Meta } from '../models/entities/meta';
export function getDriveCapacity(u: User, meta: Meta) {
return !u.host
? (u.isPremium ? meta.premiumDriveCapacityMb : meta.localDriveCapacityMb)
: meta.remoteDriveCapacityMb;
}
6 changes: 6 additions & 0 deletions src/models/entities/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ export class Meta {
})
public localDriveCapacityMb: number;

@Column('integer', {
default: 2048,
comment: 'Drive capacity of a premium user (MB)'
})
public premiumDriveCapacityMb: number;

@Column('integer', {
default: 32,
comment: 'Drive capacity of a remote user (MB)'
Expand Down
12 changes: 12 additions & 0 deletions src/server/api/endpoints/admin/update-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ export const meta = {
}
},

premiumDriveCapacityMb: {
validator: $.optional.num.min(0),
desc: {
'ja-JP': 'プレミアムユーザーひとりあたりのドライブ容量 (メガバイト単位)',
'en-US': 'Drive capacity of a premium user (MB)'
}
},

remoteDriveCapacityMb: {
validator: $.optional.num.min(0),
desc: {
Expand Down Expand Up @@ -489,6 +497,10 @@ export default define(meta, async (ps, me) => {
set.localDriveCapacityMb = ps.localDriveCapacityMb;
}

if (ps.premiumDriveCapacityMb !== undefined) {
set.premiumDriveCapacityMb = ps.premiumDriveCapacityMb;
}

if (ps.remoteDriveCapacityMb !== undefined) {
set.remoteDriveCapacityMb = ps.remoteDriveCapacityMb;
}
Expand Down
3 changes: 2 additions & 1 deletion src/server/api/endpoints/drive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import define from '../define';
import { fetchMeta } from '../../../misc/fetch-meta';
import { DriveFiles } from '../../../models';
import { getDriveCapacity } from '../../../misc/get-drive-capacity';

export const meta = {
desc: {
Expand Down Expand Up @@ -37,7 +38,7 @@ export default define(meta, async (ps, user) => {
const usage = await DriveFiles.clacDriveUsageOf(user);

return {
capacity: 1024 * 1024 * instance.localDriveCapacityMb,
capacity: 1024 * 1024 * getDriveCapacity(user, instance),
usage: usage
};
});
1 change: 1 addition & 0 deletions src/server/api/endpoints/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export default define(meta, async (ps, me) => {
disableGlobalTimeline: instance.disableGlobalTimeline,
enableEmojiReaction: instance.enableEmojiReaction,
driveCapacityPerLocalUserMb: instance.localDriveCapacityMb,
driveCapacityPerPremiumUserMb: instance.premiumDriveCapacityMb,
driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb,
cacheRemoteFiles: instance.cacheRemoteFiles,
proxyRemoteFiles: instance.proxyRemoteFiles,
Expand Down
5 changes: 5 additions & 0 deletions src/server/web/views/info.pug
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ html
td
= meta.localDriveCapacityMb
| MB
tr
th Drive capacity per premium user
td
= meta.premiumDriveCapacityMb
| MB
tr
th Drive capacity per remote user
td
Expand Down
3 changes: 2 additions & 1 deletion src/services/drive/add-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { v4 as uuid } from 'uuid';
import { publishMainStream, publishDriveStream } from '../stream';
import { deleteFile } from './delete-file';
import { fetchMeta } from '../../misc/fetch-meta';
import { getDriveCapacity } from '../../misc/get-drive-capacity';
import { GenerateVideoThumbnail } from './generate-video-thumbnail';
import { driveLogger } from './logger';
import { IImage, convertToJpeg, convertToWebp, convertToPng, convertToPngOrJpeg } from './image-processor';
Expand Down Expand Up @@ -311,7 +312,7 @@ export default async function(
const usage = await DriveFiles.clacDriveUsageOf(user);

const instance = await fetchMeta();
const driveCapacity = 1024 * 1024 * (Users.isLocalUser(user) ? instance.localDriveCapacityMb : instance.remoteDriveCapacityMb);
const driveCapacity = 1024 * 1024 * getDriveCapacity(user, instance);

logger.debug(`drive usage is ${usage} (max: ${driveCapacity})`);

Expand Down

1 comment on commit f954ab7

@fs5m8
Copy link
Member Author

@fs5m8 fs5m8 commented on f954ab7 Feb 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要マイグレーション

Please sign in to comment.