video-channels.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import express from 'express'
  2. import { VideoChannelModel } from '@server/models/video/video-channel'
  3. import { MChannelBannerAccountDefault } from '@server/types/models'
  4. import { HttpStatusCode } from '@shared/models'
  5. async function doesVideoChannelIdExist (id: number, res: express.Response) {
  6. const videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
  7. return processVideoChannelExist(videoChannel, res)
  8. }
  9. async function doesVideoChannelNameWithHostExist (nameWithDomain: string, res: express.Response) {
  10. const videoChannel = await VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithDomain)
  11. return processVideoChannelExist(videoChannel, res)
  12. }
  13. // ---------------------------------------------------------------------------
  14. export {
  15. doesVideoChannelIdExist,
  16. doesVideoChannelNameWithHostExist
  17. }
  18. function processVideoChannelExist (videoChannel: MChannelBannerAccountDefault, res: express.Response) {
  19. if (!videoChannel) {
  20. res.fail({
  21. status: HttpStatusCode.NOT_FOUND_404,
  22. message: 'Video channel not found'
  23. })
  24. return false
  25. }
  26. res.locals.videoChannel = videoChannel
  27. return true
  28. }