]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/helpers/middlewares/video-playlists.ts
Merge branch 'master' into develop
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / video-playlists.ts
1 import * as express from 'express'
2 import { VideoPlaylistModel } from '../../models/video/video-playlist'
3 import { MVideoPlaylist } from '../../typings/models/video/video-playlist'
4
5 export type VideoPlaylistFetchType = 'summary' | 'all'
6 async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') {
7 if (fetchType === 'summary') {
8 const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined)
9 res.locals.videoPlaylistSummary = videoPlaylist
10
11 return handleVideoPlaylist(videoPlaylist, res)
12 }
13
14 const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined)
15 res.locals.videoPlaylistFull = videoPlaylist
16
17 return handleVideoPlaylist(videoPlaylist, res)
18 }
19
20 // ---------------------------------------------------------------------------
21
22 export {
23 doesVideoPlaylistExist
24 }
25
26 // ---------------------------------------------------------------------------
27
28 function handleVideoPlaylist (videoPlaylist: MVideoPlaylist, res: express.Response) {
29 if (!videoPlaylist) {
30 res.status(404)
31 .json({ error: 'Video playlist not found' })
32 .end()
33
34 return false
35 }
36
37 return true
38 }