Remove ng2 file upload module

Unmaintained and we don't need it anymore with httpclient
This commit is contained in:
Chocobozzz
2017-09-14 17:06:31 +02:00
parent d5050d1e09
commit bfb3a98fac
20 changed files with 188 additions and 162 deletions

View File

@@ -11,7 +11,11 @@ import { isTestInstance } from '../../helpers'
function makeFriendsValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
// Force https if the administrator wants to make friends
if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') {
return res.status(400).send('Cannot make friends with a non HTTPS web server.')
return res.status(400)
.json({
error: 'Cannot make friends with a non HTTPS web server.'
})
.end()
}
req.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid()

View File

@@ -45,9 +45,13 @@ function usersRemoveValidator (req: express.Request, res: express.Response, next
return res.sendStatus(500)
}
if (user.username === 'root') return res.status(400).send('Cannot remove the root user')
if (user.username === 'root') {
return res.status(400)
.send({ error: 'Cannot remove the root user' })
.end()
}
next()
return next()
})
})
}
@@ -99,9 +103,13 @@ function usersVideoRatingValidator (req: express.Request, res: express.Response,
videoPromise
.then(video => {
if (!video) return res.status(404).send('Video not found')
if (!video) {
return res.status(404)
.json({ error: 'Video not found' })
.end()
}
next()
return next()
})
.catch(err => {
logger.error('Error in user request validator.', err)
@@ -113,7 +121,9 @@ function usersVideoRatingValidator (req: express.Request, res: express.Response,
function ensureUserRegistrationAllowed (req: express.Request, res: express.Response, next: express.NextFunction) {
isSignupAllowed().then(allowed => {
if (allowed === false) {
return res.status(403).send('User registration is not enabled or user limit is reached.')
return res.status(403)
.send({ error: 'User registration is not enabled or user limit is reached.' })
.end()
}
return next()
@@ -138,10 +148,14 @@ export {
function checkUserExists (id: number, res: express.Response, callback: (err: Error, user: UserInstance) => void) {
db.User.loadById(id)
.then(user => {
if (!user) return res.status(404).send('User not found')
if (!user) {
return res.status(404)
.send({ error: 'User not found' })
.end()
}
res.locals.user = user
callback(null, user)
return callback(null, user)
})
.catch(err => {
logger.error('Error in user request validator.', err)
@@ -152,9 +166,13 @@ function checkUserExists (id: number, res: express.Response, callback: (err: Err
function checkUserDoesNotAlreadyExist (username: string, email: string, res: express.Response, callback: () => void) {
db.User.loadByUsernameOrEmail(username, email)
.then(user => {
if (user) return res.status(409).send('User already exists.')
if (user) {
return res.status(409)
.send({ error: 'User already exists.' })
.end()
}
callback()
return callback()
})
.catch(err => {
logger.error('Error in usersAdd request validator.', err)

View File

@@ -30,7 +30,9 @@ function videosAddValidator (req: express.Request, res: express.Response, next:
user.isAbleToUploadVideo(videoFile)
.then(isAble => {
if (isAble === false) {
res.status(403).send('The user video quota is exceeded with this video.')
res.status(403)
.json({ error: 'The user video quota is exceeded with this video.' })
.end()
return undefined
}
@@ -38,17 +40,23 @@ function videosAddValidator (req: express.Request, res: express.Response, next:
return db.Video.getDurationFromFile(videoFile.path)
.catch(err => {
logger.error('Invalid input file in videosAddValidator.', err)
res.status(400).send('Invalid input file.')
res.status(400)
.json({ error: 'Invalid input file.' })
.end()
return undefined
})
})
.then(duration => {
// Previous test failed, abort
if (duration === undefined) return undefined
if (duration === undefined) return
if (!isVideoDurationValid('' + duration)) {
return res.status(400).send('Duration of the video file is too big (max: ' + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).')
return res.status(400)
.json({
error: 'Duration of the video file is too big (max: ' + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).'
})
.end()
}
videoFile['duration'] = duration
@@ -80,11 +88,15 @@ function videosUpdateValidator (req: express.Request, res: express.Response, nex
checkVideoExists(req.params.id, res, () => {
// We need to make additional checks
if (res.locals.video.isOwned() === false) {
return res.status(403).send('Cannot update video of another pod')
return res.status(403)
.json({ error: 'Cannot update video of another pod' })
.end()
}
if (res.locals.video.Author.userId !== res.locals.oauth.token.User.id) {
return res.status(403).send('Cannot update video of another user')
return res.status(403)
.json({ error: 'Cannot update video of another user' })
.end()
}
next()
@@ -188,7 +200,11 @@ function checkVideoExists (id: string, res: express.Response, callback: () => vo
}
promise.then(video => {
if (!video) return res.status(404).send('Video not found')
if (!video) {
return res.status(404)
.json({ error: 'Video not found' })
.end()
}
res.locals.video = video
callback()
@@ -204,14 +220,18 @@ function checkUserCanDeleteVideo (userId: number, res: express.Response, callbac
db.User.loadById(userId)
.then(user => {
if (res.locals.video.isOwned() === false) {
return res.status(403).send('Cannot remove video of another pod, blacklist it')
return res.status(403)
.json({ error: 'Cannot remove video of another pod, blacklist it' })
.end()
}
// Check if the user can delete the video
// The user can delete it if s/he is an admin
// Or if s/he is the video's author
if (user.isAdmin() === false && res.locals.video.Author.userId !== res.locals.oauth.token.User.id) {
return res.status(403).send('Cannot remove video of another user')
return res.status(403)
.json({ error: 'Cannot remove video of another user' })
.end()
}
// If we reach this comment, we can delete the video
@@ -225,7 +245,9 @@ function checkUserCanDeleteVideo (userId: number, res: express.Response, callbac
function checkVideoIsBlacklistable (req: express.Request, res: express.Response, callback: () => void) {
if (res.locals.video.isOwned() === true) {
return res.status(403).send('Cannot blacklist a local video')
return res.status(403)
.json({ error: 'Cannot blacklist a local video' })
.end()
}
callback()