enhance: クリップおよびクリップ内のノートの作成可能数を設定可能に
This commit is contained in:
@@ -23,6 +23,8 @@ export type RoleOptions = {
|
||||
antennaLimit: number;
|
||||
wordMuteLimit: number;
|
||||
webhookLimit: number;
|
||||
clipLimit: number;
|
||||
noteEachClipsLimit: number;
|
||||
};
|
||||
|
||||
export const DEFAULT_ROLE: RoleOptions = {
|
||||
@@ -35,6 +37,8 @@ export const DEFAULT_ROLE: RoleOptions = {
|
||||
antennaLimit: 5,
|
||||
wordMuteLimit: 200,
|
||||
webhookLimit: 3,
|
||||
clipLimit: 10,
|
||||
noteEachClipsLimit: 200,
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
@@ -206,6 +210,8 @@ export class RoleService implements OnApplicationShutdown {
|
||||
antennaLimit: Math.max(...getOptionValues('antennaLimit')),
|
||||
wordMuteLimit: Math.max(...getOptionValues('wordMuteLimit')),
|
||||
webhookLimit: Math.max(...getOptionValues('webhookLimit')),
|
||||
clipLimit: Math.max(...getOptionValues('clipLimit')),
|
||||
noteEachClipsLimit: Math.max(...getOptionValues('noteEachClipsLimit')),
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,7 @@ import { IdService } from '@/core/IdService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import type { ClipNotesRepository, ClipsRepository } from '@/models/index.js';
|
||||
import { GetterService } from '@/server/api/GetterService.js';
|
||||
import { RoleService } from '@/core/RoleService.js';
|
||||
import { ApiError } from '../../error.js';
|
||||
|
||||
export const meta = {
|
||||
@@ -37,6 +38,12 @@ export const meta = {
|
||||
code: 'ALREADY_CLIPPED',
|
||||
id: '734806c4-542c-463a-9311-15c512803965',
|
||||
},
|
||||
|
||||
tooManyClipNotes: {
|
||||
message: 'You cannot add notes to the clip any more.',
|
||||
code: 'TOO_MANY_CLIP_NOTES',
|
||||
id: 'f0dba960-ff73-4615-8df4-d6ac5d9dc118',
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
@@ -60,6 +67,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
private clipNotesRepository: ClipNotesRepository,
|
||||
|
||||
private idService: IdService,
|
||||
private roleService: RoleService,
|
||||
private getterService: GetterService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
@@ -86,6 +94,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
throw new ApiError(meta.errors.alreadyClipped);
|
||||
}
|
||||
|
||||
const currentCount = await this.clipNotesRepository.countBy({
|
||||
clipId: clip.id,
|
||||
});
|
||||
if (currentCount > (await this.roleService.getUserRoleOptions(me.id)).noteEachClipsLimit) {
|
||||
throw new ApiError(meta.errors.tooManyClipNotes);
|
||||
}
|
||||
|
||||
await this.clipNotesRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
noteId: note.id,
|
||||
|
@@ -4,6 +4,8 @@ import { IdService } from '@/core/IdService.js';
|
||||
import type { ClipsRepository } from '@/models/index.js';
|
||||
import { ClipEntityService } from '@/core/entities/ClipEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { RoleService } from '@/core/RoleService.js';
|
||||
import { ApiError } from '@/server/api/error.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['clips'],
|
||||
@@ -17,6 +19,14 @@ export const meta = {
|
||||
optional: false, nullable: false,
|
||||
ref: 'Clip',
|
||||
},
|
||||
|
||||
errors: {
|
||||
tooManyClips: {
|
||||
message: 'You cannot create clip any more.',
|
||||
code: 'TOO_MANY_CLIPS',
|
||||
id: '920f7c2d-6208-4b76-8082-e632020f5883',
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
@@ -37,9 +47,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
private clipsRepository: ClipsRepository,
|
||||
|
||||
private clipEntityService: ClipEntityService,
|
||||
private roleService: RoleService,
|
||||
private idService: IdService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const currentCount = await this.clipsRepository.countBy({
|
||||
userId: me.id,
|
||||
});
|
||||
if (currentCount > (await this.roleService.getUserRoleOptions(me.id)).clipLimit) {
|
||||
throw new ApiError(meta.errors.tooManyClips);
|
||||
}
|
||||
|
||||
const clip = await this.clipsRepository.insert({
|
||||
id: this.idService.genId(),
|
||||
createdAt: new Date(),
|
||||
|
Reference in New Issue
Block a user