mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 17:59:37 +02:00
emit more specific status codes on video upload (#3423)
- reduce http status codes list to potentially useful codes - convert more codes to typed ones - factorize html generator for error responses
This commit is contained in:
parent
c977fd3ec9
commit
f2eb23cd87
53 changed files with 506 additions and 310 deletions
|
@ -86,6 +86,50 @@ function toIntArray (value: any) {
|
|||
return value.map(v => validator.toInt(v))
|
||||
}
|
||||
|
||||
function isFileFieldValid (
|
||||
files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[],
|
||||
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 file
|
||||
}
|
||||
|
||||
function isFileMimeTypeValid (
|
||||
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)
|
||||
}
|
||||
|
||||
function isFileValid (
|
||||
files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[],
|
||||
mimeTypeRegex: string,
|
||||
|
@ -132,5 +176,7 @@ export {
|
|||
toIntOrNull,
|
||||
toArray,
|
||||
toIntArray,
|
||||
isFileFieldValid,
|
||||
isFileMimeTypeValid,
|
||||
isFileValid
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue