]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/shared/video-playlists.ts
Add Podcast RSS feeds (#5487)
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / shared / video-playlists.ts
CommitLineData
41fb13c3 1import express from 'express'
10363c74
C
2import { VideoPlaylistModel } from '@server/models/video/video-playlist'
3import { MVideoPlaylist } from '@server/types/models'
c0e8b12e 4import { HttpStatusCode } from '@shared/models'
3e753302 5
453e83ea
C
6export type VideoPlaylistFetchType = 'summary' | 'all'
7async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') {
8 if (fetchType === 'summary') {
9 const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined)
10 res.locals.videoPlaylistSummary = videoPlaylist
3e753302 11
453e83ea
C
12 return handleVideoPlaylist(videoPlaylist, res)
13 }
14
15 const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined)
16 res.locals.videoPlaylistFull = videoPlaylist
17
18 return handleVideoPlaylist(videoPlaylist, res)
19}
20
21// ---------------------------------------------------------------------------
22
23export {
24 doesVideoPlaylistExist
25}
26
27// ---------------------------------------------------------------------------
28
29function handleVideoPlaylist (videoPlaylist: MVideoPlaylist, res: express.Response) {
3e753302 30 if (!videoPlaylist) {
76148b27
RK
31 res.fail({
32 status: HttpStatusCode.NOT_FOUND_404,
33 message: 'Video playlist not found'
34 })
3e753302
C
35 return false
36 }
37
3e753302
C
38 return true
39}