diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-23 10:40:39 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 3e753302d8c911b59971c16a8018df0e1ab78465 (patch) | |
tree | efce7ece3273589228c5c948ea6757b2bdf65429 /server/helpers/middlewares/video-playlists.ts | |
parent | a8b666e9f1ed002230869606308749614390c82f (diff) | |
download | PeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.tar.gz PeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.tar.zst PeerTube-3e753302d8c911b59971c16a8018df0e1ab78465.zip |
Refactor middleware helpers
Diffstat (limited to 'server/helpers/middlewares/video-playlists.ts')
-rw-r--r-- | server/helpers/middlewares/video-playlists.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/server/helpers/middlewares/video-playlists.ts b/server/helpers/middlewares/video-playlists.ts new file mode 100644 index 000000000..735bf362f --- /dev/null +++ b/server/helpers/middlewares/video-playlists.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import * as express from 'express' | ||
2 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | ||
3 | |||
4 | async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: 'summary' | 'all' = 'summary') { | ||
5 | const videoPlaylist = fetchType === 'summary' | ||
6 | ? await VideoPlaylistModel.loadWithAccountAndChannelSummary(id, undefined) | ||
7 | : await VideoPlaylistModel.loadWithAccountAndChannel(id, undefined) | ||
8 | |||
9 | if (!videoPlaylist) { | ||
10 | res.status(404) | ||
11 | .json({ error: 'Video playlist not found' }) | ||
12 | .end() | ||
13 | |||
14 | return false | ||
15 | } | ||
16 | |||
17 | res.locals.videoPlaylist = videoPlaylist | ||
18 | return true | ||
19 | } | ||
20 | |||
21 | // --------------------------------------------------------------------------- | ||
22 | |||
23 | export { | ||
24 | doesVideoPlaylistExist | ||
25 | } | ||