diff --git a/packages/backend/src/server/api/endpoints/channels/create.ts b/packages/backend/src/server/api/endpoints/channels/create.ts index 4962bd3da..1a55cebe4 100644 --- a/packages/backend/src/server/api/endpoints/channels/create.ts +++ b/packages/backend/src/server/api/endpoints/channels/create.ts @@ -7,6 +7,8 @@ import { ApiError } from '../../error.js'; export const meta = { tags: ['channels'], + description: 'Creates a new channel with the current user as its administrator.', + requireCredential: true, kind: 'write:channels', @@ -32,14 +34,13 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export export default define(meta, paramDef, async (ps, user) => { - let banner = null; if (ps.bannerId != null) { - banner = await DriveFiles.findOneBy({ + const bannerExists = await DriveFiles.countBy({ id: ps.bannerId, userId: user.id, }); - if (banner == null) throw new ApiError('NO_SUCH_FILE'); + if (!bannerExists) throw new ApiError('NO_SUCH_FILE'); } const channel = await Channels.insert({ @@ -47,8 +48,8 @@ export default define(meta, paramDef, async (ps, user) => { createdAt: new Date(), userId: user.id, name: ps.name, - description: ps.description || null, - bannerId: banner ? banner.id : null, + description: ps.description, + bannerId: ps.bannerId, } as Channel).then(x => Channels.findOneByOrFail(x.identifiers[0])); return await Channels.pack(channel, user);