aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/middlewares/video-playlists.ts
blob: 735bf362f77b715c16ef4980b7eaefe9ea7f2c98 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import * as express from 'express'
import { VideoPlaylistModel } from '../../models/video/video-playlist'

async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') {
  const videoPlaylist = fetchType === 'summary'
    ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined)
    : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined)

  if (!videoPlaylist) {
    res.status(404)
       .json({ error: 'Video playlist not found' })
       .end()

    return false
  }

  res.locals.videoPlaylist = videoPlaylist
  return true
}

// ---------------------------------------------------------------------------

export {
  doesVideoPlaylistExist
}