mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
Check caption file content
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
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'
|
||||
@@ -79,14 +80,19 @@ async function listVideoCaptions (req: express.Request, res: express.Response) {
|
||||
|
||||
async function createVideoCaption (req: express.Request, res: express.Response) {
|
||||
const videoCaptionPhysicalFile: Express.Multer.File = req.files['captionfile'][0]
|
||||
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({
|
||||
video,
|
||||
language: captionLanguage,
|
||||
path: videoCaptionPhysicalFile.path,
|
||||
path: captionPath,
|
||||
automaticallyGenerated: false
|
||||
})
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_TEXT_LANGUAGES } from '../../initi
|
||||
import { logger } from '../logger.js'
|
||||
import { exists, isFileValid } from './misc.js'
|
||||
|
||||
function isVideoCaptionLanguageValid (value: any) {
|
||||
export function isVideoCaptionLanguageValid (value: any) {
|
||||
return exists(value) && VIDEO_TEXT_LANGUAGES[value] !== undefined
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ const videoCaptionTypesRegex = [ ...Object.keys(MIMETYPES.VIDEO_CAPTIONS.MIMETYP
|
||||
.map(m => `(${m})`)
|
||||
.join('|')
|
||||
|
||||
function isVideoCaptionFile (files: UploadFilesForCheck, field: string) {
|
||||
export function isVideoCaptionFile (files: UploadFilesForCheck, field: string) {
|
||||
return isFileValid({
|
||||
files,
|
||||
mimeTypeRegex: videoCaptionTypesRegex,
|
||||
@@ -23,7 +23,7 @@ function isVideoCaptionFile (files: UploadFilesForCheck, field: string) {
|
||||
})
|
||||
}
|
||||
|
||||
async function isVTTFileValid (filePath: string) {
|
||||
export async function isVTTFileValid (filePath: string) {
|
||||
const size = await getFileSize(filePath)
|
||||
const content = await readFile(filePath, 'utf8')
|
||||
|
||||
@@ -31,13 +31,5 @@ async function isVTTFileValid (filePath: string) {
|
||||
|
||||
if (size > CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) return false
|
||||
|
||||
return content?.startsWith('WEBVTT')
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
isVideoCaptionFile,
|
||||
isVTTFileValid,
|
||||
isVideoCaptionLanguageValid
|
||||
return !!content?.startsWith('WEBVTT')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user