X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fmiddlewares%2Fvideo-channels.ts;h=e6eab65a28a0d43238bdc6b7ee9ccca2e6e82082;hb=1fa23d6f5e487f3c149e1f0001beadd919ee82fc;hp=1b573ca37e7ae2bf0dff4956af95ecb76ac9b2d6;hpb=3e753302d8c911b59971c16a8018df0e1ab78465;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/middlewares/video-channels.ts b/server/helpers/middlewares/video-channels.ts index 1b573ca37..e6eab65a2 100644 --- a/server/helpers/middlewares/video-channels.ts +++ b/server/helpers/middlewares/video-channels.ts @@ -1,23 +1,42 @@ -import { Response } from 'express' -import { VideoAbuseModel } from '../../models/video/video-abuse' +import * as express from 'express' +import { MChannelBannerAccountDefault } from '@server/types/models' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' +import { VideoChannelModel } from '../../models/video/video-channel' -async function doesVideoAbuseExist (abuseId: number, videoId: number, res: Response) { - const videoAbuse = await VideoAbuseModel.loadByIdAndVideoId(abuseId, videoId) +async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { + const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) - if (videoAbuse === null) { - res.status(404) - .json({ error: 'Video abuse not found' }) - .end() + return processVideoChannelExist(videoChannel, res) +} - return false - } +async function doesVideoChannelIdExist (id: number, res: express.Response) { + const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) - res.locals.videoAbuse = videoAbuse - return true + return processVideoChannelExist(videoChannel, res) +} + +async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) { + const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain) + + return processVideoChannelExist(videoChannel, res) } // --------------------------------------------------------------------------- export { - doesVideoAbuseExist + doesLocalVideoChannelNameExist, + doesVideoChannelIdExist, + doesVideoChannelNameWithHostExist +} + +function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) { + if (!videoChannel) { + res.status(HttpStatusCode.NOT_FOUND_404) + .json({ error: 'Video channel not found' }) + + return false + } + + res.locals.videoChannel = videoChannel + return true }