mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Implement captions/subtitles
This commit is contained in:
parent
d4557fd3ec
commit
40e87e9ecc
83 changed files with 1867 additions and 298 deletions
41
server/helpers/custom-validators/video-captions.ts
Normal file
41
server/helpers/custom-validators/video-captions.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { CONSTRAINTS_FIELDS, VIDEO_LANGUAGES } from '../../initializers'
|
||||
import { exists, isFileValid } from './misc'
|
||||
import { Response } from 'express'
|
||||
import { VideoModel } from '../../models/video/video'
|
||||
import { VideoCaptionModel } from '../../models/video/video-caption'
|
||||
|
||||
function isVideoCaptionLanguageValid (value: any) {
|
||||
return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined
|
||||
}
|
||||
|
||||
const videoCaptionTypes = CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.EXTNAME
|
||||
.map(v => v.replace('.', ''))
|
||||
.join('|')
|
||||
const videoCaptionsTypesRegex = `text/(${videoCaptionTypes})`
|
||||
|
||||
function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) {
|
||||
return isFileValid(files, videoCaptionsTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
|
||||
}
|
||||
|
||||
async function isVideoCaptionExist (video: VideoModel, language: string, res: Response) {
|
||||
const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language)
|
||||
|
||||
if (!videoCaption) {
|
||||
res.status(404)
|
||||
.json({ error: 'Video caption not found' })
|
||||
.end()
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
res.locals.videoCaption = videoCaption
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
isVideoCaptionFile,
|
||||
isVideoCaptionLanguageValid,
|
||||
isVideoCaptionExist
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue