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/custom-validators/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/custom-validators/video-captions.ts')
-rw-r--r-- | server/helpers/custom-validators/video-captions.ts | 21 |
1 files changed, 1 insertions, 20 deletions
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts index 3b6569a8a..d06eb3695 100644 --- a/server/helpers/custom-validators/video-captions.ts +++ b/server/helpers/custom-validators/video-captions.ts | |||
@@ -1,8 +1,5 @@ | |||
1 | import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants' | 1 | import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_LANGUAGES } from '../../initializers/constants' |
2 | import { exists, isFileValid } from './misc' | 2 | import { exists, isFileValid } from './misc' |
3 | import { Response } from 'express' | ||
4 | import { VideoModel } from '../../models/video/video' | ||
5 | import { VideoCaptionModel } from '../../models/video/video-caption' | ||
6 | 3 | ||
7 | function isVideoCaptionLanguageValid (value: any) { | 4 | function isVideoCaptionLanguageValid (value: any) { |
8 | return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined | 5 | return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined |
@@ -16,25 +13,9 @@ function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File | |||
16 | return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) | 13 | return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) |
17 | } | 14 | } |
18 | 15 | ||
19 | async function doesVideoCaptionExist (video: VideoModel, language: string, res: Response) { | ||
20 | const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) | ||
21 | |||
22 | if (!videoCaption) { | ||
23 | res.status(404) | ||
24 | .json({ error: 'Video caption not found' }) | ||
25 | .end() | ||
26 | |||
27 | return false | ||
28 | } | ||
29 | |||
30 | res.locals.videoCaption = videoCaption | ||
31 | return true | ||
32 | } | ||
33 | |||
34 | // --------------------------------------------------------------------------- | 16 | // --------------------------------------------------------------------------- |
35 | 17 | ||
36 | export { | 18 | export { |
37 | isVideoCaptionFile, | 19 | isVideoCaptionFile, |
38 | isVideoCaptionLanguageValid, | 20 | isVideoCaptionLanguageValid |
39 | doesVideoCaptionExist | ||
40 | } | 21 | } |