]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/middlewares/video-playlists.ts
Proxy youtube-dl format command too
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / video-playlists.ts
CommitLineData
3e753302
C
1import * as express from 'express'
2import { VideoPlaylistModel } from '../../models/video/video-playlist'
453e83ea 3import { MVideoPlaylist } from '../../typings/models/video/video-playlist'
3e753302 4
453e83ea
C
5export type VideoPlaylistFetchType = 'summary' | 'all'
6async 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
3e753302 10
453e83ea
C
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
22export {
23 doesVideoPlaylistExist
24}
25
26// ---------------------------------------------------------------------------
27
28function handleVideoPlaylist (videoPlaylist: MVideoPlaylist, res: express.Response) {
3e753302
C
29 if (!videoPlaylist) {
30 res.status(404)
31 .json({ error: 'Video playlist not found' })
32 .end()
33
34 return false
35 }
36
3e753302
C
37 return true
38}