1
0
Fork 0
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:
Chocobozzz 2018-02-13 18:17:05 +01:00
parent e883399fa6
commit ac81d1a06d
No known key found for this signature in database
GPG key ID: 583A612D890159BE
22 changed files with 454 additions and 143 deletions

View file

@ -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
}