diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-15 14:08:16 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-02-16 10:36:44 +0100 |
commit | 6302d599cdf98b5a5363a2a1dcdc266447950191 (patch) | |
tree | b7dc6dc0f08f0fb8a20720242c9c0a71afeeaa3f /server/controllers/api/videos/captions.ts | |
parent | a8b1b40485145ac1eae513a661d7dd6e0986ce96 (diff) | |
download | PeerTube-6302d599cdf98b5a5363a2a1dcdc266447950191.tar.gz PeerTube-6302d599cdf98b5a5363a2a1dcdc266447950191.tar.zst PeerTube-6302d599cdf98b5a5363a2a1dcdc266447950191.zip |
Generate a name for caption files
Diffstat (limited to 'server/controllers/api/videos/captions.ts')
-rw-r--r-- | server/controllers/api/videos/captions.ts | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts index bf82e2c19..ad7423a31 100644 --- a/server/controllers/api/videos/captions.ts +++ b/server/controllers/api/videos/captions.ts | |||
@@ -1,17 +1,17 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' | 2 | import { MVideoCaption } from '@server/types/models' |
3 | import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' | 3 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
4 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | ||
4 | import { createReqFiles } from '../../../helpers/express-utils' | 5 | import { createReqFiles } from '../../../helpers/express-utils' |
5 | import { MIMETYPES } from '../../../initializers/constants' | ||
6 | import { getFormattedObjects } from '../../../helpers/utils' | ||
7 | import { VideoCaptionModel } from '../../../models/video/video-caption' | ||
8 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
9 | import { federateVideoIfNeeded } from '../../../lib/activitypub/videos' | 7 | import { getFormattedObjects } from '../../../helpers/utils' |
10 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | ||
11 | import { CONFIG } from '../../../initializers/config' | 8 | import { CONFIG } from '../../../initializers/config' |
9 | import { MIMETYPES } from '../../../initializers/constants' | ||
12 | import { sequelizeTypescript } from '../../../initializers/database' | 10 | import { sequelizeTypescript } from '../../../initializers/database' |
13 | import { MVideoCaptionVideo } from '@server/types/models' | 11 | import { federateVideoIfNeeded } from '../../../lib/activitypub/videos' |
14 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 12 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' |
13 | import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' | ||
14 | import { VideoCaptionModel } from '../../../models/video/video-caption' | ||
15 | 15 | ||
16 | const reqVideoCaptionAdd = createReqFiles( | 16 | const reqVideoCaptionAdd = createReqFiles( |
17 | [ 'captionfile' ], | 17 | [ 'captionfile' ], |
@@ -57,17 +57,19 @@ async function addVideoCaption (req: express.Request, res: express.Response) { | |||
57 | const videoCaptionPhysicalFile = req.files['captionfile'][0] | 57 | const videoCaptionPhysicalFile = req.files['captionfile'][0] |
58 | const video = res.locals.videoAll | 58 | const video = res.locals.videoAll |
59 | 59 | ||
60 | const captionLanguage = req.params.captionLanguage | ||
61 | |||
60 | const videoCaption = new VideoCaptionModel({ | 62 | const videoCaption = new VideoCaptionModel({ |
61 | videoId: video.id, | 63 | videoId: video.id, |
62 | language: req.params.captionLanguage | 64 | filename: VideoCaptionModel.generateCaptionName(captionLanguage), |
63 | }) as MVideoCaptionVideo | 65 | language: captionLanguage |
64 | videoCaption.Video = video | 66 | }) as MVideoCaption |
65 | 67 | ||
66 | // Move physical file | 68 | // Move physical file |
67 | await moveAndProcessCaptionFile(videoCaptionPhysicalFile, videoCaption) | 69 | await moveAndProcessCaptionFile(videoCaptionPhysicalFile, videoCaption) |
68 | 70 | ||
69 | await sequelizeTypescript.transaction(async t => { | 71 | await sequelizeTypescript.transaction(async t => { |
70 | await VideoCaptionModel.insertOrReplaceLanguage(video.id, req.params.captionLanguage, null, t) | 72 | await VideoCaptionModel.insertOrReplaceLanguage(videoCaption, t) |
71 | 73 | ||
72 | // Update video update | 74 | // Update video update |
73 | await federateVideoIfNeeded(video, false, t) | 75 | await federateVideoIfNeeded(video, false, t) |