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-captions.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-captions.ts')
-rw-r--r-- | server/helpers/middlewares/video-captions.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/server/helpers/middlewares/video-captions.ts b/server/helpers/middlewares/video-captions.ts new file mode 100644 index 000000000..dc3d0144b --- /dev/null +++ b/server/helpers/middlewares/video-captions.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import { VideoModel } from '../../models/video/video' | ||
2 | import { Response } from 'express' | ||
3 | import { VideoCaptionModel } from '../../models/video/video-caption' | ||
4 | |||
5 | async function doesVideoCaptionExist (video: VideoModel, language: string, res: Response) { | ||
6 | const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) | ||
7 | |||
8 | if (!videoCaption) { | ||
9 | res.status(404) | ||
10 | .json({ error: 'Video caption not found' }) | ||
11 | .end() | ||
12 | |||
13 | return false | ||
14 | } | ||
15 | |||
16 | res.locals.videoCaption = videoCaption | ||
17 | return true | ||
18 | } | ||
19 | |||
20 | // --------------------------------------------------------------------------- | ||
21 | |||
22 | export { | ||
23 | doesVideoCaptionExist | ||
24 | } | ||