aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/captions.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-15 14:08:16 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-16 10:36:44 +0100
commit6302d599cdf98b5a5363a2a1dcdc266447950191 (patch)
treeb7dc6dc0f08f0fb8a20720242c9c0a71afeeaa3f /server/controllers/api/videos/captions.ts
parenta8b1b40485145ac1eae513a661d7dd6e0986ce96 (diff)
downloadPeerTube-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.ts28
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' 2import { MVideoCaption } from '@server/types/models'
3import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' 3import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
4import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
4import { createReqFiles } from '../../../helpers/express-utils' 5import { createReqFiles } from '../../../helpers/express-utils'
5import { MIMETYPES } from '../../../initializers/constants'
6import { getFormattedObjects } from '../../../helpers/utils'
7import { VideoCaptionModel } from '../../../models/video/video-caption'
8import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
9import { federateVideoIfNeeded } from '../../../lib/activitypub/videos' 7import { getFormattedObjects } from '../../../helpers/utils'
10import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
11import { CONFIG } from '../../../initializers/config' 8import { CONFIG } from '../../../initializers/config'
9import { MIMETYPES } from '../../../initializers/constants'
12import { sequelizeTypescript } from '../../../initializers/database' 10import { sequelizeTypescript } from '../../../initializers/database'
13import { MVideoCaptionVideo } from '@server/types/models' 11import { federateVideoIfNeeded } from '../../../lib/activitypub/videos'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 12import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
13import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators'
14import { VideoCaptionModel } from '../../../models/video/video-caption'
15 15
16const reqVideoCaptionAdd = createReqFiles( 16const 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)