aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/api/videos/index.ts6
-rw-r--r--server/controllers/client.ts4
-rw-r--r--server/helpers/custom-validators/pods.ts2
-rw-r--r--server/helpers/custom-validators/remote/videos.ts6
-rw-r--r--server/helpers/custom-validators/videos.ts2
-rw-r--r--server/helpers/database-utils.ts14
-rw-r--r--server/helpers/utils.ts2
-rw-r--r--server/initializers/checker.ts2
-rw-r--r--server/initializers/database.ts6
-rw-r--r--server/initializers/migrator.ts2
-rw-r--r--server/lib/friends.ts6
-rw-r--r--server/lib/oauth-model.ts4
-rw-r--r--server/middlewares/oauth.ts2
-rw-r--r--server/middlewares/validators/pods.ts4
-rw-r--r--server/middlewares/validators/users.ts6
-rw-r--r--server/middlewares/validators/videos.ts22
-rw-r--r--server/models/oauth/oauth-token.ts39
-rw-r--r--server/models/pod/pod.ts2
-rw-r--r--server/models/request/request-video-event.ts2
-rw-r--r--server/models/request/request-video-qadu.ts2
-rw-r--r--server/models/request/request.ts4
-rw-r--r--server/models/user/user.ts6
-rw-r--r--server/models/video/author.ts2
-rw-r--r--server/models/video/video-abuse.ts4
-rw-r--r--server/models/video/video.ts26
25 files changed, 86 insertions, 91 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index e70a5319e..815881df3 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -49,11 +49,11 @@ const videosRouter = express.Router()
49 49
50// multer configuration 50// multer configuration
51const storage = multer.diskStorage({ 51const storage = multer.diskStorage({
52 destination: function (req, file, cb) { 52 destination: (req, file, cb) => {
53 cb(null, CONFIG.STORAGE.VIDEOS_DIR) 53 cb(null, CONFIG.STORAGE.VIDEOS_DIR)
54 }, 54 },
55 55
56 filename: function (req, file, cb) { 56 filename: (req, file, cb) => {
57 let extension = '' 57 let extension = ''
58 if (file.mimetype === 'video/webm') extension = 'webm' 58 if (file.mimetype === 'video/webm') extension = 'webm'
59 else if (file.mimetype === 'video/mp4') extension = 'mp4' 59 else if (file.mimetype === 'video/mp4') extension = 'mp4'
@@ -310,7 +310,7 @@ function updateVideo (req: express.Request, res: express.Response) {
310 // Force fields we want to update 310 // Force fields we want to update
311 // If the transaction is retried, sequelize will think the object has not changed 311 // If the transaction is retried, sequelize will think the object has not changed
312 // So it will skip the SQL request, even if the last one was ROLLBACKed! 312 // So it will skip the SQL request, even if the last one was ROLLBACKed!
313 Object.keys(videoFieldsSave).forEach(function (key) { 313 Object.keys(videoFieldsSave).forEach(key => {
314 const value = videoFieldsSave[key] 314 const value = videoFieldsSave[key]
315 videoInstance.set(key, value) 315 videoInstance.set(key, value)
316 }) 316 })
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index ac722a578..d913f81b8 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -24,7 +24,7 @@ const indexPath = join(distPath, 'index.html')
24// Do not use a template engine for a so little thing 24// Do not use a template engine for a so little thing
25clientsRouter.use('/videos/watch/:id', generateWatchHtmlPage) 25clientsRouter.use('/videos/watch/:id', generateWatchHtmlPage)
26 26
27clientsRouter.use('/videos/embed', function (req: express.Request, res: express.Response, next: express.NextFunction) { 27clientsRouter.use('/videos/embed', (req: express.Request, res: express.Response, next: express.NextFunction) => {
28 res.sendFile(embedPath) 28 res.sendFile(embedPath)
29}) 29})
30 30
@@ -32,7 +32,7 @@ clientsRouter.use('/videos/embed', function (req: express.Request, res: express.
32clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE })) 32clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE }))
33 33
34// 404 for static files not found 34// 404 for static files not found
35clientsRouter.use('/client/*', function (req: express.Request, res: express.Response, next: express.NextFunction) { 35clientsRouter.use('/client/*', (req: express.Request, res: express.Response, next: express.NextFunction) => {
36 res.sendStatus(404) 36 res.sendStatus(404)
37}) 37})
38 38
diff --git a/server/helpers/custom-validators/pods.ts b/server/helpers/custom-validators/pods.ts
index ec9f26cc8..0519def52 100644
--- a/server/helpers/custom-validators/pods.ts
+++ b/server/helpers/custom-validators/pods.ts
@@ -9,7 +9,7 @@ function isHostValid (host: string) {
9function isEachUniqueHostValid (hosts: string[]) { 9function isEachUniqueHostValid (hosts: string[]) {
10 return isArray(hosts) && 10 return isArray(hosts) &&
11 hosts.length !== 0 && 11 hosts.length !== 0 &&
12 hosts.every(function (host) { 12 hosts.every(host => {
13 return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host) 13 return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
14 }) 14 })
15} 15}
diff --git a/server/helpers/custom-validators/remote/videos.ts b/server/helpers/custom-validators/remote/videos.ts
index e14673cb3..b33d8c9be 100644
--- a/server/helpers/custom-validators/remote/videos.ts
+++ b/server/helpers/custom-validators/remote/videos.ts
@@ -33,7 +33,7 @@ const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
33 33
34function isEachRemoteRequestVideosValid (requests: any[]) { 34function isEachRemoteRequestVideosValid (requests: any[]) {
35 return isArray(requests) && 35 return isArray(requests) &&
36 requests.every(function (request) { 36 requests.every(request => {
37 const video = request.data 37 const video = request.data
38 38
39 if (!video) return false 39 if (!video) return false
@@ -63,7 +63,7 @@ function isEachRemoteRequestVideosValid (requests: any[]) {
63 63
64function isEachRemoteRequestVideosQaduValid (requests: any[]) { 64function isEachRemoteRequestVideosQaduValid (requests: any[]) {
65 return isArray(requests) && 65 return isArray(requests) &&
66 requests.every(function (request) { 66 requests.every(request => {
67 const video = request.data 67 const video = request.data
68 68
69 if (!video) return false 69 if (!video) return false
@@ -79,7 +79,7 @@ function isEachRemoteRequestVideosQaduValid (requests: any[]) {
79 79
80function isEachRemoteRequestVideosEventsValid (requests: any[]) { 80function isEachRemoteRequestVideosEventsValid (requests: any[]) {
81 return isArray(requests) && 81 return isArray(requests) &&
82 requests.every(function (request) { 82 requests.every(request => {
83 const eventData = request.data 83 const eventData = request.data
84 84
85 if (!eventData) return false 85 if (!eventData) return false
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index e335b09d1..62132acb1 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -68,7 +68,7 @@ function isVideoNameValid (value: string) {
68function isVideoTagsValid (tags: string[]) { 68function isVideoTagsValid (tags: string[]) {
69 return isArray(tags) && 69 return isArray(tags) &&
70 validator.isInt(tags.length.toString(), VIDEOS_CONSTRAINTS_FIELDS.TAGS) && 70 validator.isInt(tags.length.toString(), VIDEOS_CONSTRAINTS_FIELDS.TAGS) &&
71 tags.every(function (tag) { 71 tags.every(tag => {
72 return exists(tag) && validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG) 72 return exists(tag) && validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG)
73 }) 73 })
74} 74}
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts
index e174dc3e9..987e42eb0 100644
--- a/server/helpers/database-utils.ts
+++ b/server/helpers/database-utils.ts
@@ -8,13 +8,11 @@ type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[]
8function retryTransactionWrapper (functionToRetry: (... args) => Promise<any>, options: RetryTransactionWrapperOptions) { 8function retryTransactionWrapper (functionToRetry: (... args) => Promise<any>, options: RetryTransactionWrapperOptions) {
9 const args = options.arguments ? options.arguments : [] 9 const args = options.arguments ? options.arguments : []
10 10
11 return transactionRetryer( 11 return transactionRetryer(callback => {
12 function (callback) { 12 functionToRetry.apply(this, args)
13 functionToRetry.apply(this, args)
14 .then(result => callback(null, result)) 13 .then(result => callback(null, result))
15 .catch(err => callback(err)) 14 .catch(err => callback(err))
16 } 15 })
17 )
18 .catch(err => { 16 .catch(err => {
19 // Do not throw the error, continue the process 17 // Do not throw the error, continue the process
20 logger.error(options.errorMessage, err) 18 logger.error(options.errorMessage, err)
@@ -26,14 +24,12 @@ function transactionRetryer (func: Function) {
26 retry({ 24 retry({
27 times: 5, 25 times: 5,
28 26
29 errorFilter: function (err) { 27 errorFilter: err => {
30 const willRetry = (err.name === 'SequelizeDatabaseError') 28 const willRetry = (err.name === 'SequelizeDatabaseError')
31 logger.debug('Maybe retrying the transaction function.', { willRetry }) 29 logger.debug('Maybe retrying the transaction function.', { willRetry })
32 return willRetry 30 return willRetry
33 } 31 }
34 }, func, function (err) { 32 }, func, err => err ? rej(err) : res())
35 err ? rej(err) : res()
36 })
37 }) 33 })
38} 34}
39 35
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index e99a48393..9c08afb71 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -18,7 +18,7 @@ interface FormatableToJSON {
18function getFormatedObjects<U, T extends FormatableToJSON> (objects: T[], objectsTotal: number) { 18function getFormatedObjects<U, T extends FormatableToJSON> (objects: T[], objectsTotal: number) {
19 const formatedObjects: U[] = [] 19 const formatedObjects: U[] = []
20 20
21 objects.forEach(function (object) { 21 objects.forEach(object => {
22 formatedObjects.push(object.toFormatedJSON()) 22 formatedObjects.push(object.toFormatedJSON())
23 }) 23 })
24 24
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts
index fb69e05fc..e4ca26f9c 100644
--- a/server/initializers/checker.ts
+++ b/server/initializers/checker.ts
@@ -45,7 +45,7 @@ function checkFFmpeg () {
45 if (CONFIG.TRANSCODING.ENABLED === false) return undefined 45 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
46 46
47 const canEncode = [ 'libx264' ] 47 const canEncode = [ 'libx264' ]
48 canEncode.forEach(function (codec) { 48 canEncode.forEach(codec => {
49 if (codecs[codec] === undefined) { 49 if (codecs[codec] === undefined) {
50 throw new Error('Unknown codec ' + codec + ' in FFmpeg.') 50 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
51 } 51 }
diff --git a/server/initializers/database.ts b/server/initializers/database.ts
index 6e3a8d009..9e691bf1d 100644
--- a/server/initializers/database.ts
+++ b/server/initializers/database.ts
@@ -60,7 +60,7 @@ const sequelize = new Sequelize(dbname, username, password, {
60 port: CONFIG.DATABASE.PORT, 60 port: CONFIG.DATABASE.PORT,
61 benchmark: isTestInstance(), 61 benchmark: isTestInstance(),
62 62
63 logging: function (message: string, benchmark: number) { 63 logging: (message: string, benchmark: number) => {
64 let newMessage = message 64 let newMessage = message
65 if (benchmark !== undefined) { 65 if (benchmark !== undefined) {
66 newMessage += ' | ' + benchmark + 'ms' 66 newMessage += ' | ' + benchmark + 'ms'
@@ -72,7 +72,7 @@ const sequelize = new Sequelize(dbname, username, password, {
72 72
73database.sequelize = sequelize 73database.sequelize = sequelize
74 74
75database.init = function (silent: boolean) { 75database.init = (silent: boolean) => {
76 const modelDirectory = join(__dirname, '..', 'models') 76 const modelDirectory = join(__dirname, '..', 'models')
77 77
78 return getModelFiles(modelDirectory).then(filePaths => { 78 return getModelFiles(modelDirectory).then(filePaths => {
@@ -105,7 +105,7 @@ export {
105function getModelFiles (modelDirectory: string) { 105function getModelFiles (modelDirectory: string) {
106 return readdirPromise(modelDirectory) 106 return readdirPromise(modelDirectory)
107 .then(files => { 107 .then(files => {
108 const directories: string[] = files.filter(function (directory) { 108 const directories: string[] = files.filter(directory => {
109 // Find directories 109 // Find directories
110 if ( 110 if (
111 directory.endsWith('.js.map') || 111 directory.endsWith('.js.map') ||
diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts
index 4b3be6d16..71a656c59 100644
--- a/server/initializers/migrator.ts
+++ b/server/initializers/migrator.ts
@@ -64,7 +64,7 @@ function getMigrationScripts () {
64 script: string 64 script: string
65 }[] = [] 65 }[] = []
66 66
67 files.forEach(function (file) { 67 files.forEach(file => {
68 // Filename is something like 'version-blabla.js' 68 // Filename is something like 'version-blabla.js'
69 const version = file.split('-')[0] 69 const version = file.split('-')[0]
70 filesToMigrate.push({ 70 filesToMigrate.push({
diff --git a/server/lib/friends.ts b/server/lib/friends.ts
index cbdc60441..6ed0da013 100644
--- a/server/lib/friends.ts
+++ b/server/lib/friends.ts
@@ -111,7 +111,7 @@ function quickAndDirtyUpdateVideoToFriends (qaduParam: QaduParam, transaction?:
111function quickAndDirtyUpdatesVideoToFriends (qadusParams: QaduParam[], transaction: Sequelize.Transaction) { 111function quickAndDirtyUpdatesVideoToFriends (qadusParams: QaduParam[], transaction: Sequelize.Transaction) {
112 const tasks = [] 112 const tasks = []
113 113
114 qadusParams.forEach(function (qaduParams) { 114 qadusParams.forEach(qaduParams => {
115 tasks.push(quickAndDirtyUpdateVideoToFriends(qaduParams, transaction)) 115 tasks.push(quickAndDirtyUpdateVideoToFriends(qaduParams, transaction))
116 }) 116 })
117 117
@@ -130,7 +130,7 @@ function addEventToRemoteVideo (eventParam: EventParam, transaction?: Sequelize.
130function addEventsToRemoteVideo (eventsParams: EventParam[], transaction: Sequelize.Transaction) { 130function addEventsToRemoteVideo (eventsParams: EventParam[], transaction: Sequelize.Transaction) {
131 const tasks = [] 131 const tasks = []
132 132
133 eventsParams.forEach(function (eventParams) { 133 eventsParams.forEach(eventParams => {
134 tasks.push(addEventToRemoteVideo(eventParams, transaction)) 134 tasks.push(addEventToRemoteVideo(eventParams, transaction))
135 }) 135 })
136 136
@@ -307,7 +307,7 @@ function getForeignPodsList (host: string) {
307 return new Promise< ResultList<FormatedPod> >((res, rej) => { 307 return new Promise< ResultList<FormatedPod> >((res, rej) => {
308 const path = '/api/' + API_VERSION + '/pods' 308 const path = '/api/' + API_VERSION + '/pods'
309 309
310 request.get(REMOTE_SCHEME.HTTP + '://' + host + path, function (err, response, body) { 310 request.get(REMOTE_SCHEME.HTTP + '://' + host + path, (err, response, body) => {
311 if (err) return rej(err) 311 if (err) return rej(err)
312 312
313 try { 313 try {
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts
index 2d7e56756..769ea126a 100644
--- a/server/lib/oauth-model.ts
+++ b/server/lib/oauth-model.ts
@@ -27,7 +27,7 @@ function getRefreshToken (refreshToken: string) {
27function getUser (username: string, password: string) { 27function getUser (username: string, password: string) {
28 logger.debug('Getting User (username: ' + username + ', password: ' + password + ').') 28 logger.debug('Getting User (username: ' + username + ', password: ' + password + ').')
29 29
30 return db.User.getByUsername(username).then(function (user) { 30 return db.User.getByUsername(username).then(user => {
31 if (!user) return null 31 if (!user) return null
32 32
33 return user.isPasswordMatch(password).then(passwordMatch => { 33 return user.isPasswordMatch(password).then(passwordMatch => {
@@ -39,7 +39,7 @@ function getUser (username: string, password: string) {
39} 39}
40 40
41function revokeToken (token: TokenInfo) { 41function revokeToken (token: TokenInfo) {
42 return db.OAuthToken.getByRefreshTokenAndPopulateUser(token.refreshToken).then(function (tokenDB) { 42 return db.OAuthToken.getByRefreshTokenAndPopulateUser(token.refreshToken).then(tokenDB => {
43 if (tokenDB) tokenDB.destroy() 43 if (tokenDB) tokenDB.destroy()
44 44
45 /* 45 /*
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index fe0490436..3faecdbcc 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -12,7 +12,7 @@ const oAuthServer = new OAuthServer({
12}) 12})
13 13
14function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) { 14function authenticate (req: express.Request, res: express.Response, next: express.NextFunction) {
15 oAuthServer.authenticate()(req, res, function (err) { 15 oAuthServer.authenticate()(req, res, err => {
16 if (err) { 16 if (err) {
17 logger.error('Cannot authenticate.', err) 17 logger.error('Cannot authenticate.', err)
18 return res.sendStatus(500) 18 return res.sendStatus(500)
diff --git a/server/middlewares/validators/pods.ts b/server/middlewares/validators/pods.ts
index 022fd7f9a..481a66957 100644
--- a/server/middlewares/validators/pods.ts
+++ b/server/middlewares/validators/pods.ts
@@ -18,7 +18,7 @@ function makeFriendsValidator (req: express.Request, res: express.Response, next
18 18
19 logger.debug('Checking makeFriends parameters', { parameters: req.body }) 19 logger.debug('Checking makeFriends parameters', { parameters: req.body })
20 20
21 checkErrors(req, res, function () { 21 checkErrors(req, res, () => {
22 hasFriends() 22 hasFriends()
23 .then(heHasFriends => { 23 .then(heHasFriends => {
24 if (heHasFriends === true) { 24 if (heHasFriends === true) {
@@ -41,7 +41,7 @@ function podsAddValidator (req: express.Request, res: express.Response, next: ex
41 req.checkBody('publicKey', 'Should have a public key').notEmpty() 41 req.checkBody('publicKey', 'Should have a public key').notEmpty()
42 logger.debug('Checking podsAdd parameters', { parameters: req.body }) 42 logger.debug('Checking podsAdd parameters', { parameters: req.body })
43 43
44 checkErrors(req, res, function () { 44 checkErrors(req, res, () => {
45 db.Pod.loadByHost(req.body.host) 45 db.Pod.loadByHost(req.body.host)
46 .then(pod => { 46 .then(pod => {
47 // Pod with this host already exists 47 // Pod with this host already exists
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 90a46752c..38f8aed5b 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -15,7 +15,7 @@ function usersAddValidator (req: express.Request, res: express.Response, next: e
15 15
16 logger.debug('Checking usersAdd parameters', { parameters: req.body }) 16 logger.debug('Checking usersAdd parameters', { parameters: req.body })
17 17
18 checkErrors(req, res, function () { 18 checkErrors(req, res, () => {
19 db.User.loadByUsernameOrEmail(req.body.username, req.body.email) 19 db.User.loadByUsernameOrEmail(req.body.username, req.body.email)
20 .then(user => { 20 .then(user => {
21 if (user) return res.status(409).send('User already exists.') 21 if (user) return res.status(409).send('User already exists.')
@@ -34,7 +34,7 @@ function usersRemoveValidator (req: express.Request, res: express.Response, next
34 34
35 logger.debug('Checking usersRemove parameters', { parameters: req.params }) 35 logger.debug('Checking usersRemove parameters', { parameters: req.params })
36 36
37 checkErrors(req, res, function () { 37 checkErrors(req, res, () => {
38 db.User.loadById(req.params.id) 38 db.User.loadById(req.params.id)
39 .then(user => { 39 .then(user => {
40 if (!user) return res.status(404).send('User not found') 40 if (!user) return res.status(404).send('User not found')
@@ -66,7 +66,7 @@ function usersVideoRatingValidator (req: express.Request, res: express.Response,
66 66
67 logger.debug('Checking usersVideoRating parameters', { parameters: req.params }) 67 logger.debug('Checking usersVideoRating parameters', { parameters: req.params })
68 68
69 checkErrors(req, res, function () { 69 checkErrors(req, res, () => {
70 let videoPromise: Promise<VideoInstance> 70 let videoPromise: Promise<VideoInstance>
71 71
72 if (validator.isUUID(req.params.videoId)) { 72 if (validator.isUUID(req.params.videoId)) {
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts
index 0a88e064e..bd223a1cb 100644
--- a/server/middlewares/validators/videos.ts
+++ b/server/middlewares/validators/videos.ts
@@ -23,7 +23,7 @@ function videosAddValidator (req: express.Request, res: express.Response, next:
23 23
24 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) 24 logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
25 25
26 checkErrors(req, res, function () { 26 checkErrors(req, res, () => {
27 const videoFile = req.files.videofile[0] 27 const videoFile = req.files.videofile[0]
28 28
29 db.Video.getDurationFromFile(videoFile.path) 29 db.Video.getDurationFromFile(videoFile.path)
@@ -54,8 +54,8 @@ function videosUpdateValidator (req: express.Request, res: express.Response, nex
54 54
55 logger.debug('Checking videosUpdate parameters', { parameters: req.body }) 55 logger.debug('Checking videosUpdate parameters', { parameters: req.body })
56 56
57 checkErrors(req, res, function () { 57 checkErrors(req, res, () => {
58 checkVideoExists(req.params.id, res, function () { 58 checkVideoExists(req.params.id, res, () => {
59 // We need to make additional checks 59 // We need to make additional checks
60 if (res.locals.video.isOwned() === false) { 60 if (res.locals.video.isOwned() === false) {
61 return res.status(403).send('Cannot update video of another pod') 61 return res.status(403).send('Cannot update video of another pod')
@@ -75,7 +75,7 @@ function videosGetValidator (req: express.Request, res: express.Response, next:
75 75
76 logger.debug('Checking videosGet parameters', { parameters: req.params }) 76 logger.debug('Checking videosGet parameters', { parameters: req.params })
77 77
78 checkErrors(req, res, function () { 78 checkErrors(req, res, () => {
79 checkVideoExists(req.params.id, res, next) 79 checkVideoExists(req.params.id, res, next)
80 }) 80 })
81} 81}
@@ -85,12 +85,12 @@ function videosRemoveValidator (req: express.Request, res: express.Response, nex
85 85
86 logger.debug('Checking videosRemove parameters', { parameters: req.params }) 86 logger.debug('Checking videosRemove parameters', { parameters: req.params })
87 87
88 checkErrors(req, res, function () { 88 checkErrors(req, res, () => {
89 checkVideoExists(req.params.id, res, function () { 89 checkVideoExists(req.params.id, res, () => {
90 // We need to make additional checks 90 // We need to make additional checks
91 91
92 // Check if the user who did the request is able to delete the video 92 // Check if the user who did the request is able to delete the video
93 checkUserCanDeleteVideo(res.locals.oauth.token.User.id, res, function () { 93 checkUserCanDeleteVideo(res.locals.oauth.token.User.id, res, () => {
94 next() 94 next()
95 }) 95 })
96 }) 96 })
@@ -113,7 +113,7 @@ function videoAbuseReportValidator (req: express.Request, res: express.Response,
113 113
114 logger.debug('Checking videoAbuseReport parameters', { parameters: req.body }) 114 logger.debug('Checking videoAbuseReport parameters', { parameters: req.body })
115 115
116 checkErrors(req, res, function () { 116 checkErrors(req, res, () => {
117 checkVideoExists(req.params.id, res, next) 117 checkVideoExists(req.params.id, res, next)
118 }) 118 })
119} 119}
@@ -124,7 +124,7 @@ function videoRateValidator (req: express.Request, res: express.Response, next:
124 124
125 logger.debug('Checking videoRate parameters', { parameters: req.body }) 125 logger.debug('Checking videoRate parameters', { parameters: req.body })
126 126
127 checkErrors(req, res, function () { 127 checkErrors(req, res, () => {
128 checkVideoExists(req.params.id, res, next) 128 checkVideoExists(req.params.id, res, next)
129 }) 129 })
130} 130}
@@ -134,8 +134,8 @@ function videosBlacklistValidator (req: express.Request, res: express.Response,
134 134
135 logger.debug('Checking videosBlacklist parameters', { parameters: req.params }) 135 logger.debug('Checking videosBlacklist parameters', { parameters: req.params })
136 136
137 checkErrors(req, res, function () { 137 checkErrors(req, res, () => {
138 checkVideoExists(req.params.id, res, function () { 138 checkVideoExists(req.params.id, res, () => {
139 checkVideoIsBlacklistable(req, res, next) 139 checkVideoIsBlacklistable(req, res, next)
140 }) 140 })
141 }) 141 })
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts
index a0a13aab7..5c3781394 100644
--- a/server/models/oauth/oauth-token.ts
+++ b/server/models/oauth/oauth-token.ts
@@ -98,24 +98,27 @@ getByRefreshTokenAndPopulateClient = function (refreshToken: string) {
98 include: [ OAuthToken['sequelize'].models.OAuthClient ] 98 include: [ OAuthToken['sequelize'].models.OAuthClient ]
99 } 99 }
100 100
101 return OAuthToken.findOne(query).then(function (token) { 101 return OAuthToken.findOne(query)
102 if (!token) return null 102 .then(token => {
103 103 if (!token) return null
104 const tokenInfos: OAuthTokenInfo = { 104
105 refreshToken: token.refreshToken, 105 const tokenInfos: OAuthTokenInfo = {
106 refreshTokenExpiresAt: token.refreshTokenExpiresAt, 106 refreshToken: token.refreshToken,
107 client: { 107 refreshTokenExpiresAt: token.refreshTokenExpiresAt,
108 id: token['client'].id 108 client: {
109 }, 109 id: token['client'].id
110 user: { 110 },
111 id: token['user'] 111 user: {
112 id: token['user']
113 }
112 } 114 }
113 }
114 115
115 return tokenInfos 116 return tokenInfos
116 }).catch(function (err) { 117 })
117 logger.info('getRefreshToken error.', err) 118 .catch(err => {
118 }) 119 logger.info('getRefreshToken error.', err)
120 throw err
121 })
119} 122}
120 123
121getByTokenAndPopulateUser = function (bearerToken: string) { 124getByTokenAndPopulateUser = function (bearerToken: string) {
@@ -126,7 +129,7 @@ getByTokenAndPopulateUser = function (bearerToken: string) {
126 include: [ OAuthToken['sequelize'].models.User ] 129 include: [ OAuthToken['sequelize'].models.User ]
127 } 130 }
128 131
129 return OAuthToken.findOne(query).then(function (token) { 132 return OAuthToken.findOne(query).then(token => {
130 if (token) token['user'] = token.User 133 if (token) token['user'] = token.User
131 134
132 return token 135 return token
@@ -141,7 +144,7 @@ getByRefreshTokenAndPopulateUser = function (refreshToken: string) {
141 include: [ OAuthToken['sequelize'].models.User ] 144 include: [ OAuthToken['sequelize'].models.User ]
142 } 145 }
143 146
144 return OAuthToken.findOne(query).then(function (token) { 147 return OAuthToken.findOne(query).then(token => {
145 token['user'] = token.User 148 token['user'] = token.User
146 149
147 return token 150 return token
diff --git a/server/models/pod/pod.ts b/server/models/pod/pod.ts
index 62d9e3c6c..e1088977f 100644
--- a/server/models/pod/pod.ts
+++ b/server/models/pod/pod.ts
@@ -32,7 +32,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
32 type: DataTypes.STRING, 32 type: DataTypes.STRING,
33 allowNull: false, 33 allowNull: false,
34 validate: { 34 validate: {
35 isHost: function (value) { 35 isHost: value => {
36 const res = isHostValid(value) 36 const res = isHostValid(value)
37 if (res === false) throw new Error('Host not valid.') 37 if (res === false) throw new Error('Host not valid.')
38 } 38 }
diff --git a/server/models/request/request-video-event.ts b/server/models/request/request-video-event.ts
index 90ea15702..4862a5745 100644
--- a/server/models/request/request-video-event.ts
+++ b/server/models/request/request-video-event.ts
@@ -160,7 +160,7 @@ removeAll = function () {
160function groupAndTruncateRequests (events: RequestVideoEventInstance[], limitRequestsPerPod: number) { 160function groupAndTruncateRequests (events: RequestVideoEventInstance[], limitRequestsPerPod: number) {
161 const eventsGrouped: RequestsVideoEventGrouped = {} 161 const eventsGrouped: RequestsVideoEventGrouped = {}
162 162
163 events.forEach(function (event) { 163 events.forEach(event => {
164 const pod = event.Video.Author.Pod 164 const pod = event.Video.Author.Pod
165 165
166 if (!eventsGrouped[pod.id]) eventsGrouped[pod.id] = [] 166 if (!eventsGrouped[pod.id]) eventsGrouped[pod.id] = []
diff --git a/server/models/request/request-video-qadu.ts b/server/models/request/request-video-qadu.ts
index 74e28f129..9c97812b9 100644
--- a/server/models/request/request-video-qadu.ts
+++ b/server/models/request/request-video-qadu.ts
@@ -141,7 +141,7 @@ removeAll = function () {
141function groupAndTruncateRequests (requests: RequestVideoQaduInstance[], limitRequestsPerPod: number) { 141function groupAndTruncateRequests (requests: RequestVideoQaduInstance[], limitRequestsPerPod: number) {
142 const requestsGrouped = {} 142 const requestsGrouped = {}
143 143
144 requests.forEach(function (request) { 144 requests.forEach(request => {
145 const pod = request.Pod 145 const pod = request.Pod
146 146
147 if (!requestsGrouped[pod.id]) requestsGrouped[pod.id] = [] 147 if (!requestsGrouped[pod.id]) requestsGrouped[pod.id] = []
diff --git a/server/models/request/request.ts b/server/models/request/request.ts
index c3ce2cd4e..b4c0226fa 100644
--- a/server/models/request/request.ts
+++ b/server/models/request/request.ts
@@ -127,8 +127,8 @@ removeWithEmptyTo = function () {
127function groupAndTruncateRequests (requests: RequestInstance[], limitRequestsPerPod: number) { 127function groupAndTruncateRequests (requests: RequestInstance[], limitRequestsPerPod: number) {
128 const requestsGrouped: RequestsGrouped = {} 128 const requestsGrouped: RequestsGrouped = {}
129 129
130 requests.forEach(function (request) { 130 requests.forEach(request => {
131 request.Pods.forEach(function (pod) { 131 request.Pods.forEach(pod => {
132 if (!requestsGrouped[pod.id]) requestsGrouped[pod.id] = [] 132 if (!requestsGrouped[pod.id]) requestsGrouped[pod.id] = []
133 133
134 if (requestsGrouped[pod.id].length < limitRequestsPerPod) { 134 if (requestsGrouped[pod.id].length < limitRequestsPerPod) {
diff --git a/server/models/user/user.ts b/server/models/user/user.ts
index 5ff81e741..bda95d2f6 100644
--- a/server/models/user/user.ts
+++ b/server/models/user/user.ts
@@ -38,7 +38,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
38 type: DataTypes.STRING, 38 type: DataTypes.STRING,
39 allowNull: false, 39 allowNull: false,
40 validate: { 40 validate: {
41 passwordValid: function (value) { 41 passwordValid: value => {
42 const res = isUserPasswordValid(value) 42 const res = isUserPasswordValid(value)
43 if (res === false) throw new Error('Password not valid.') 43 if (res === false) throw new Error('Password not valid.')
44 } 44 }
@@ -48,7 +48,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
48 type: DataTypes.STRING, 48 type: DataTypes.STRING,
49 allowNull: false, 49 allowNull: false,
50 validate: { 50 validate: {
51 usernameValid: function (value) { 51 usernameValid: value => {
52 const res = isUserUsernameValid(value) 52 const res = isUserUsernameValid(value)
53 if (res === false) throw new Error('Username not valid.') 53 if (res === false) throw new Error('Username not valid.')
54 } 54 }
@@ -66,7 +66,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
66 allowNull: false, 66 allowNull: false,
67 defaultValue: false, 67 defaultValue: false,
68 validate: { 68 validate: {
69 nsfwValid: function (value) { 69 nsfwValid: value => {
70 const res = isUserDisplayNSFWValid(value) 70 const res = isUserDisplayNSFWValid(value)
71 if (res === false) throw new Error('Display NSFW is not valid.') 71 if (res === false) throw new Error('Display NSFW is not valid.')
72 } 72 }
diff --git a/server/models/video/author.ts b/server/models/video/author.ts
index 3222c4834..c30cc306d 100644
--- a/server/models/video/author.ts
+++ b/server/models/video/author.ts
@@ -20,7 +20,7 @@ export default function defineAuthor (sequelize: Sequelize.Sequelize, DataTypes:
20 type: DataTypes.STRING, 20 type: DataTypes.STRING,
21 allowNull: false, 21 allowNull: false,
22 validate: { 22 validate: {
23 usernameValid: function (value) { 23 usernameValid: value => {
24 const res = isUserUsernameValid(value) 24 const res = isUserUsernameValid(value)
25 if (res === false) throw new Error('Username is not valid.') 25 if (res === false) throw new Error('Username is not valid.')
26 } 26 }
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index f55a25e6a..df92609c0 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -22,7 +22,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
22 type: DataTypes.STRING, 22 type: DataTypes.STRING,
23 allowNull: false, 23 allowNull: false,
24 validate: { 24 validate: {
25 reporterUsernameValid: function (value) { 25 reporterUsernameValid: value => {
26 const res = isVideoAbuseReporterUsernameValid(value) 26 const res = isVideoAbuseReporterUsernameValid(value)
27 if (res === false) throw new Error('Video abuse reporter username is not valid.') 27 if (res === false) throw new Error('Video abuse reporter username is not valid.')
28 } 28 }
@@ -32,7 +32,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
32 type: DataTypes.STRING, 32 type: DataTypes.STRING,
33 allowNull: false, 33 allowNull: false,
34 validate: { 34 validate: {
35 reasonValid: function (value) { 35 reasonValid: value => {
36 const res = isVideoAbuseReasonValid(value) 36 const res = isVideoAbuseReasonValid(value)
37 if (res === false) throw new Error('Video abuse reason is not valid.') 37 if (res === false) throw new Error('Video abuse reason is not valid.')
38 } 38 }
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 3bb74bf6d..650025205 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -87,7 +87,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
87 type: DataTypes.STRING, 87 type: DataTypes.STRING,
88 allowNull: false, 88 allowNull: false,
89 validate: { 89 validate: {
90 nameValid: function (value) { 90 nameValid: value => {
91 const res = isVideoNameValid(value) 91 const res = isVideoNameValid(value)
92 if (res === false) throw new Error('Video name is not valid.') 92 if (res === false) throw new Error('Video name is not valid.')
93 } 93 }
@@ -101,7 +101,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
101 type: DataTypes.INTEGER, 101 type: DataTypes.INTEGER,
102 allowNull: false, 102 allowNull: false,
103 validate: { 103 validate: {
104 categoryValid: function (value) { 104 categoryValid: value => {
105 const res = isVideoCategoryValid(value) 105 const res = isVideoCategoryValid(value)
106 if (res === false) throw new Error('Video category is not valid.') 106 if (res === false) throw new Error('Video category is not valid.')
107 } 107 }
@@ -112,7 +112,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
112 allowNull: false, 112 allowNull: false,
113 defaultValue: null, 113 defaultValue: null,
114 validate: { 114 validate: {
115 licenceValid: function (value) { 115 licenceValid: value => {
116 const res = isVideoLicenceValid(value) 116 const res = isVideoLicenceValid(value)
117 if (res === false) throw new Error('Video licence is not valid.') 117 if (res === false) throw new Error('Video licence is not valid.')
118 } 118 }
@@ -122,7 +122,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
122 type: DataTypes.INTEGER, 122 type: DataTypes.INTEGER,
123 allowNull: true, 123 allowNull: true,
124 validate: { 124 validate: {
125 languageValid: function (value) { 125 languageValid: value => {
126 const res = isVideoLanguageValid(value) 126 const res = isVideoLanguageValid(value)
127 if (res === false) throw new Error('Video language is not valid.') 127 if (res === false) throw new Error('Video language is not valid.')
128 } 128 }
@@ -132,7 +132,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
132 type: DataTypes.BOOLEAN, 132 type: DataTypes.BOOLEAN,
133 allowNull: false, 133 allowNull: false,
134 validate: { 134 validate: {
135 nsfwValid: function (value) { 135 nsfwValid: value => {
136 const res = isVideoNSFWValid(value) 136 const res = isVideoNSFWValid(value)
137 if (res === false) throw new Error('Video nsfw attribute is not valid.') 137 if (res === false) throw new Error('Video nsfw attribute is not valid.')
138 } 138 }
@@ -142,7 +142,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
142 type: DataTypes.STRING, 142 type: DataTypes.STRING,
143 allowNull: false, 143 allowNull: false,
144 validate: { 144 validate: {
145 descriptionValid: function (value) { 145 descriptionValid: value => {
146 const res = isVideoDescriptionValid(value) 146 const res = isVideoDescriptionValid(value)
147 if (res === false) throw new Error('Video description is not valid.') 147 if (res === false) throw new Error('Video description is not valid.')
148 } 148 }
@@ -152,7 +152,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
152 type: DataTypes.STRING, 152 type: DataTypes.STRING,
153 allowNull: false, 153 allowNull: false,
154 validate: { 154 validate: {
155 infoHashValid: function (value) { 155 infoHashValid: value => {
156 const res = isVideoInfoHashValid(value) 156 const res = isVideoInfoHashValid(value)
157 if (res === false) throw new Error('Video info hash is not valid.') 157 if (res === false) throw new Error('Video info hash is not valid.')
158 } 158 }
@@ -162,7 +162,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
162 type: DataTypes.INTEGER, 162 type: DataTypes.INTEGER,
163 allowNull: false, 163 allowNull: false,
164 validate: { 164 validate: {
165 durationValid: function (value) { 165 durationValid: value => {
166 const res = isVideoDurationValid(value) 166 const res = isVideoDurationValid(value)
167 if (res === false) throw new Error('Video duration is not valid.') 167 if (res === false) throw new Error('Video duration is not valid.')
168 } 168 }
@@ -549,9 +549,7 @@ transcodeVideofile = function (this: VideoInstance) {
549 }) 549 })
550 .catch(err => { 550 .catch(err => {
551 // Autodesctruction... 551 // Autodesctruction...
552 video.destroy().asCallback(function (err) { 552 video.destroy().catch(err => logger.error('Cannot destruct video after transcoding failure.', err))
553 if (err) logger.error('Cannot destruct video after transcoding failure.', err)
554 })
555 553
556 return rej(err) 554 return rej(err)
557 }) 555 })
@@ -574,7 +572,7 @@ generateThumbnailFromData = function (video: VideoInstance, thumbnailData: strin
574 572
575getDurationFromFile = function (videoPath: string) { 573getDurationFromFile = function (videoPath: string) {
576 return new Promise<number>((res, rej) => { 574 return new Promise<number>((res, rej) => {
577 ffmpeg.ffprobe(videoPath, function (err, metadata) { 575 ffmpeg.ffprobe(videoPath, (err, metadata) => {
578 if (err) return rej(err) 576 if (err) return rej(err)
579 577
580 return res(Math.floor(metadata.format.duration)) 578 return res(Math.floor(metadata.format.duration))
@@ -865,9 +863,7 @@ function generateImage (video: VideoInstance, videoPath: string, folder: string,
865 return new Promise<string>((res, rej) => { 863 return new Promise<string>((res, rej) => {
866 ffmpeg(videoPath) 864 ffmpeg(videoPath)
867 .on('error', rej) 865 .on('error', rej)
868 .on('end', function () { 866 .on('end', () => res(imageName))
869 return res(imageName)
870 })
871 .thumbnail(options) 867 .thumbnail(options)
872 }) 868 })
873} 869}