X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fcaptions.ts;h=2a9a9d233a73b1dcb45b73d357349d7e2b7c36e2;hb=c3edc5b074aa4bb1861ed0a94d3713808e87170f;hp=37481d12f525b4291868bd626934d5a214a41df4;hpb=d5c8932a601c1854db0a2e399ccaf26e17385f1a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts index 37481d12f..2a9a9d233 100644 --- a/server/controllers/api/videos/captions.ts +++ b/server/controllers/api/videos/captions.ts @@ -1,16 +1,18 @@ -import * as express from 'express' -import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' -import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' +import express from 'express' +import { MVideoCaption } from '@server/types/models' +import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' +import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' import { createReqFiles } from '../../../helpers/express-utils' -import { MIMETYPES } from '../../../initializers/constants' -import { getFormattedObjects } from '../../../helpers/utils' -import { VideoCaptionModel } from '../../../models/video/video-caption' import { logger } from '../../../helpers/logger' -import { federateVideoIfNeeded } from '../../../lib/activitypub' -import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' +import { getFormattedObjects } from '../../../helpers/utils' import { CONFIG } from '../../../initializers/config' +import { MIMETYPES } from '../../../initializers/constants' import { sequelizeTypescript } from '../../../initializers/database' -import { MVideoCaptionVideo } from '@server/typings/models' +import { federateVideoIfNeeded } from '../../../lib/activitypub/videos' +import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' +import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' +import { VideoCaptionModel } from '../../../models/video/video-caption' +import { Hooks } from '@server/lib/plugins/hooks' const reqVideoCaptionAdd = createReqFiles( [ 'captionfile' ], @@ -47,7 +49,7 @@ export { // --------------------------------------------------------------------------- async function listVideoCaptions (req: express.Request, res: express.Response) { - const data = await VideoCaptionModel.listVideoCaptions(res.locals.videoId.id) + const data = await VideoCaptionModel.listVideoCaptions(res.locals.onlyVideo.id) return res.json(getFormattedObjects(data, data.length)) } @@ -56,23 +58,27 @@ async function addVideoCaption (req: express.Request, res: express.Response) { const videoCaptionPhysicalFile = req.files['captionfile'][0] const video = res.locals.videoAll + const captionLanguage = req.params.captionLanguage + const videoCaption = new VideoCaptionModel({ videoId: video.id, - language: req.params.captionLanguage - }) as MVideoCaptionVideo - videoCaption.Video = video + filename: VideoCaptionModel.generateCaptionName(captionLanguage), + language: captionLanguage + }) as MVideoCaption // Move physical file await moveAndProcessCaptionFile(videoCaptionPhysicalFile, videoCaption) await sequelizeTypescript.transaction(async t => { - await VideoCaptionModel.insertOrReplaceLanguage(video.id, req.params.captionLanguage, t) + await VideoCaptionModel.insertOrReplaceLanguage(videoCaption, t) // Update video update await federateVideoIfNeeded(video, false, t) }) - return res.status(204).end() + Hooks.runAction('action:api.video-caption.created', { caption: videoCaption, req, res }) + + return res.status(HttpStatusCode.NO_CONTENT_204).end() } async function deleteVideoCaption (req: express.Request, res: express.Response) { @@ -88,5 +94,7 @@ async function deleteVideoCaption (req: express.Request, res: express.Response) logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid) - return res.type('json').status(204).end() + Hooks.runAction('action:api.video-caption.deleted', { caption: videoCaption, req, res }) + + return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() }