mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
expliciting type checks and predicates (server only)
This commit is contained in:
parent
5f7021c33d
commit
c1e791bad0
34 changed files with 127 additions and 84 deletions
|
@ -51,7 +51,7 @@ function isFileValid (
|
|||
files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[],
|
||||
mimeTypeRegex: string,
|
||||
field: string,
|
||||
maxSize: number,
|
||||
maxSize: number | null,
|
||||
optional = false
|
||||
) {
|
||||
// Should have files
|
||||
|
@ -69,7 +69,7 @@ function isFileValid (
|
|||
if (!file || !file.originalname) return false
|
||||
|
||||
// Check size
|
||||
if (maxSize && file.size > maxSize) return false
|
||||
if ((maxSize !== null) && file.size > maxSize) return false
|
||||
|
||||
return new RegExp(`^${mimeTypeRegex}$`, 'i').test(file.mimetype)
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use
|
|||
}
|
||||
|
||||
async function isVideoExist (id: string, res: Response) {
|
||||
let video: VideoModel
|
||||
let video: VideoModel | null
|
||||
|
||||
if (validator.isInt(id)) {
|
||||
video = await VideoModel.loadAndPopulateAccountAndServerAndTags(+id)
|
||||
|
@ -158,7 +158,7 @@ async function isVideoExist (id: string, res: Response) {
|
|||
video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id)
|
||||
}
|
||||
|
||||
if (!video) {
|
||||
if (video && video !== null) {
|
||||
res.status(404)
|
||||
.json({ error: 'Video not found' })
|
||||
.end()
|
||||
|
@ -173,7 +173,7 @@ async function isVideoExist (id: string, res: Response) {
|
|||
async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) {
|
||||
if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
|
||||
const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
|
||||
if (!videoChannel) {
|
||||
if (videoChannel && videoChannel !== null) {
|
||||
res.status(400)
|
||||
.json({ error: 'Unknown video video channel on this instance.' })
|
||||
.end()
|
||||
|
@ -186,7 +186,7 @@ async function isVideoChannelOfAccountExist (channelId: number, user: UserModel,
|
|||
}
|
||||
|
||||
const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
|
||||
if (!videoChannel) {
|
||||
if (videoChannel && videoChannel !== null) {
|
||||
res.status(400)
|
||||
.json({ error: 'Unknown video video channel for this account.' })
|
||||
.end()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue