This commit is contained in:
tamaina
2023-06-04 17:37:00 +00:00
parent 47fae30aba
commit 669cfb1e29
6 changed files with 165 additions and 155 deletions

View File

@@ -8,49 +8,10 @@ import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '../../error.js';
export const meta = {
tags: ['channels'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:channels',
limit: {
duration: ms('1hour'),
max: 10,
},
res: {
type: 'object',
optional: false, nullable: false,
ref: 'Channel',
},
errors: {
noSuchFile: {
message: 'No such file.',
code: 'NO_SUCH_FILE',
id: 'cd1e9f3e-5a12-4ab4-96f6-5d0a2cc32050',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1, maxLength: 128 },
description: { type: 'string', nullable: true, minLength: 1, maxLength: 2048 },
bannerId: { type: 'string', format: 'misskey:id', nullable: true },
color: { type: 'string', minLength: 1, maxLength: 16 },
},
required: ['name'],
} as const;
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
export default class extends Endpoint<'channels/create'> {
name = 'channels/create' as const;
constructor(
@Inject(DI.driveFilesRepository)
private driveFilesRepository: DriveFilesRepository,
@@ -61,7 +22,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private idService: IdService,
private channelEntityService: ChannelEntityService,
) {
super(meta, paramDef, async (ps, me) => {
super(async (ps, me) => {
let banner = null;
if (ps.bannerId != null) {
banner = await this.driveFilesRepository.findOneBy({
@@ -70,7 +31,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
});
if (banner == null) {
throw new ApiError(meta.errors.noSuchFile);
throw new ApiError(this.meta.errors.noSuchFile);
}
}