Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix caption checker

Chocobozzze5ad7b76718e
diff --git a/server/core/controllers/api/videos/captions.ts b/server/core/controllers/api/videos/captions.ts
index f381a79462..c0c4487390 100644
--- a/server/core/controllers/api/videos/captions.ts
+++ b/server/core/controllers/api/videos/captions.ts
@@ -1,5 +1,4 @@
import { HttpStatusCode, VideoCaptionGenerate, VideoChannelActivityAction } from '@peertube/peertube-models'
-import { isVTTFileValid } from '@server/helpers/custom-validators/video-captions.js'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
import { Hooks } from '@server/lib/plugins/hooks.js'
import { createLocalCaption, createTranscriptionTaskIfNeeded, updateHLSMasterOnCaptionChangeIfNeeded } from '@server/lib/video-captions.js'
@@ -83,10 +82,6 @@ async function createVideoCaption (req: express.Request, res: express.Response)
const captionPath = videoCaptionPhysicalFile.path
const video = res.locals.videoFull
- if (!await isVTTFileValid(captionPath)) {
- return res.fail({ status: HttpStatusCode.BAD_REQUEST_400, message: req.t('Invalid caption file') })
- }
-
const captionLanguage = req.params.captionLanguage
const videoCaption = await createLocalCaption({
diff --git a/server/core/lib/video-captions.ts b/server/core/lib/video-captions.ts
index ea8c760aae..7d6db4823f 100644
--- a/server/core/lib/video-captions.ts
+++ b/server/core/lib/video-captions.ts
@@ -2,7 +2,7 @@ import { FileStorage, VideoFileStream } from '@peertube/peertube-models'
import { buildSUUID } from '@peertube/peertube-node-utils'
import { AbstractTranscriber, TranscriptionModel, WhisperBuiltinModel, transcriberFactory } from '@peertube/peertube-transcription'
import { moveAndProcessCaptionFile } from '@server/helpers/captions-utils.js'
-import { isVideoCaptionLanguageValid } from '@server/helpers/custom-validators/video-captions.js'
+import { isVideoCaptionLanguageValid, isVTTFileValid } from '@server/helpers/custom-validators/video-captions.js'
import { retryTransactionWrapper } from '@server/helpers/database-utils.js'
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
@@ -45,6 +45,15 @@ export async function createLocalCaption (options: {
await moveAndProcessCaptionFile({ path }, videoCaption)
+ const captionDest = videoCaption.getFSFilePath()
+
+ if (!await isVTTFileValid(captionDest)) {
+ remove(captionDest)
+ .catch(err => logger.error('Cannot remove invalid VTT file', { err, ...lTags(video.uuid) }))
+
+ throw new Error(`Invalid VTT file`)
+ }
+
const hls = await VideoStreamingPlaylistModel.loadHLSByVideo(video.id)
// If object storage is enabled, the move to object storage job will upload the playlist on the fly