mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Add ability to set video thumbnail/preview
This commit is contained in:
parent
e883399fa6
commit
ac81d1a06d
22 changed files with 454 additions and 143 deletions
|
@ -1,3 +1,4 @@
|
|||
import 'multer'
|
||||
import * as validator from 'validator'
|
||||
|
||||
function exists (value: any) {
|
||||
|
@ -28,6 +29,29 @@ function isBooleanValid (value: string) {
|
|||
return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
|
||||
}
|
||||
|
||||
function isFileValid (
|
||||
files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[],
|
||||
mimeTypeRegex: string,
|
||||
field: string,
|
||||
optional = false
|
||||
) {
|
||||
// Should have files
|
||||
if (!files) return optional
|
||||
if (isArray(files)) return optional
|
||||
|
||||
// Should have a file
|
||||
const fileArray = files[ field ]
|
||||
if (!fileArray || fileArray.length === 0) {
|
||||
return optional
|
||||
}
|
||||
|
||||
// The file should exist
|
||||
const file = fileArray[ 0 ]
|
||||
if (!file || !file.originalname) return false
|
||||
|
||||
return new RegExp(`^${mimeTypeRegex}$`, 'i').test(file.mimetype)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
|
@ -37,5 +61,6 @@ export {
|
|||
isUUIDValid,
|
||||
isIdOrUUIDValid,
|
||||
isDateValid,
|
||||
isBooleanValid
|
||||
isBooleanValid,
|
||||
isFileValid
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue