]>
Commit | Line | Data |
---|---|---|
3e753302 C |
1 | import * as express from 'express' |
2 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | |
26d6bf65 | 3 | import { MVideoPlaylist } from '../../types/models/video/video-playlist' |
3e753302 | 4 | |
453e83ea C |
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 | |
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 | ||
22 | export { | |
23 | doesVideoPlaylistExist | |
24 | } | |
25 | ||
26 | // --------------------------------------------------------------------------- | |
27 | ||
28 | function 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 | } |