X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fcaptions.ts;h=3ba9181891e008013c5d2e2d7901f63fa2c2c077;hb=6e46de095d7169355dd83030f6ce4a582304153a;hp=05412a17f20b442df76a0cd1c9e8a84decc0c3ad;hpb=40e87e9ecc54e3513fb586928330a7855eb192c6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts index 05412a17f..3ba918189 100644 --- a/server/controllers/api/videos/captions.ts +++ b/server/controllers/api/videos/captions.ts @@ -1,19 +1,14 @@ import * as express from 'express' import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' -import { - addVideoCaptionValidator, - deleteVideoCaptionValidator, - listVideoCaptionsValidator -} from '../../../middlewares/validators/video-captions' +import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' import { createReqFiles } from '../../../helpers/express-utils' import { CONFIG, sequelizeTypescript, VIDEO_CAPTIONS_MIMETYPE_EXT } from '../../../initializers' import { getFormattedObjects } from '../../../helpers/utils' import { VideoCaptionModel } from '../../../models/video/video-caption' -import { renamePromise } from '../../../helpers/core-utils' -import { join } from 'path' import { VideoModel } from '../../../models/video/video' import { logger } from '../../../helpers/logger' import { federateVideoIfNeeded } from '../../../lib/activitypub' +import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' const reqVideoCaptionAdd = createReqFiles( [ 'captionfile' ], @@ -66,12 +61,7 @@ async function addVideoCaption (req: express.Request, res: express.Response) { videoCaption.Video = video // Move physical file - const videoCaptionsDir = CONFIG.STORAGE.CAPTIONS_DIR - const destination = join(videoCaptionsDir, videoCaption.getCaptionName()) - await renamePromise(videoCaptionPhysicalFile.path, destination) - // This is important in case if there is another attempt in the retry process - videoCaptionPhysicalFile.filename = videoCaption.getCaptionName() - videoCaptionPhysicalFile.path = destination + await moveAndProcessCaptionFile(videoCaptionPhysicalFile, videoCaption) await sequelizeTypescript.transaction(async t => { await VideoCaptionModel.insertOrReplaceLanguage(video.id, req.params.captionLanguage, t)