From 075f16caac5236cb04c98ae7b3a989766d764bb3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Jul 2017 17:04:57 +0200 Subject: Remove "function" in favor of () => {} --- server/models/oauth/oauth-token.ts | 39 +++++++++++++++------------- server/models/pod/pod.ts | 2 +- server/models/request/request-video-event.ts | 2 +- server/models/request/request-video-qadu.ts | 2 +- server/models/request/request.ts | 4 +-- server/models/user/user.ts | 6 ++--- server/models/video/author.ts | 2 +- server/models/video/video-abuse.ts | 4 +-- server/models/video/video.ts | 26 ++++++++----------- 9 files changed, 43 insertions(+), 44 deletions(-) (limited to 'server/models') 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) { include: [ OAuthToken['sequelize'].models.OAuthClient ] } - return OAuthToken.findOne(query).then(function (token) { - if (!token) return null - - const tokenInfos: OAuthTokenInfo = { - refreshToken: token.refreshToken, - refreshTokenExpiresAt: token.refreshTokenExpiresAt, - client: { - id: token['client'].id - }, - user: { - id: token['user'] + return OAuthToken.findOne(query) + .then(token => { + if (!token) return null + + const tokenInfos: OAuthTokenInfo = { + refreshToken: token.refreshToken, + refreshTokenExpiresAt: token.refreshTokenExpiresAt, + client: { + id: token['client'].id + }, + user: { + id: token['user'] + } } - } - return tokenInfos - }).catch(function (err) { - logger.info('getRefreshToken error.', err) - }) + return tokenInfos + }) + .catch(err => { + logger.info('getRefreshToken error.', err) + throw err + }) } getByTokenAndPopulateUser = function (bearerToken: string) { @@ -126,7 +129,7 @@ getByTokenAndPopulateUser = function (bearerToken: string) { include: [ OAuthToken['sequelize'].models.User ] } - return OAuthToken.findOne(query).then(function (token) { + return OAuthToken.findOne(query).then(token => { if (token) token['user'] = token.User return token @@ -141,7 +144,7 @@ getByRefreshTokenAndPopulateUser = function (refreshToken: string) { include: [ OAuthToken['sequelize'].models.User ] } - return OAuthToken.findOne(query).then(function (token) { + return OAuthToken.findOne(query).then(token => { token['user'] = token.User 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 type: DataTypes.STRING, allowNull: false, validate: { - isHost: function (value) { + isHost: value => { const res = isHostValid(value) if (res === false) throw new Error('Host not valid.') } 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 () { function groupAndTruncateRequests (events: RequestVideoEventInstance[], limitRequestsPerPod: number) { const eventsGrouped: RequestsVideoEventGrouped = {} - events.forEach(function (event) { + events.forEach(event => { const pod = event.Video.Author.Pod 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 () { function groupAndTruncateRequests (requests: RequestVideoQaduInstance[], limitRequestsPerPod: number) { const requestsGrouped = {} - requests.forEach(function (request) { + requests.forEach(request => { const pod = request.Pod 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 () { function groupAndTruncateRequests (requests: RequestInstance[], limitRequestsPerPod: number) { const requestsGrouped: RequestsGrouped = {} - requests.forEach(function (request) { - request.Pods.forEach(function (pod) { + requests.forEach(request => { + request.Pods.forEach(pod => { if (!requestsGrouped[pod.id]) requestsGrouped[pod.id] = [] 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 type: DataTypes.STRING, allowNull: false, validate: { - passwordValid: function (value) { + passwordValid: value => { const res = isUserPasswordValid(value) if (res === false) throw new Error('Password not valid.') } @@ -48,7 +48,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da type: DataTypes.STRING, allowNull: false, validate: { - usernameValid: function (value) { + usernameValid: value => { const res = isUserUsernameValid(value) if (res === false) throw new Error('Username not valid.') } @@ -66,7 +66,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da allowNull: false, defaultValue: false, validate: { - nsfwValid: function (value) { + nsfwValid: value => { const res = isUserDisplayNSFWValid(value) if (res === false) throw new Error('Display NSFW is not valid.') } 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: type: DataTypes.STRING, allowNull: false, validate: { - usernameValid: function (value) { + usernameValid: value => { const res = isUserUsernameValid(value) if (res === false) throw new Error('Username is not valid.') } 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 type: DataTypes.STRING, allowNull: false, validate: { - reporterUsernameValid: function (value) { + reporterUsernameValid: value => { const res = isVideoAbuseReporterUsernameValid(value) if (res === false) throw new Error('Video abuse reporter username is not valid.') } @@ -32,7 +32,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da type: DataTypes.STRING, allowNull: false, validate: { - reasonValid: function (value) { + reasonValid: value => { const res = isVideoAbuseReasonValid(value) if (res === false) throw new Error('Video abuse reason is not valid.') } 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 type: DataTypes.STRING, allowNull: false, validate: { - nameValid: function (value) { + nameValid: value => { const res = isVideoNameValid(value) if (res === false) throw new Error('Video name is not valid.') } @@ -101,7 +101,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da type: DataTypes.INTEGER, allowNull: false, validate: { - categoryValid: function (value) { + categoryValid: value => { const res = isVideoCategoryValid(value) if (res === false) throw new Error('Video category is not valid.') } @@ -112,7 +112,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da allowNull: false, defaultValue: null, validate: { - licenceValid: function (value) { + licenceValid: value => { const res = isVideoLicenceValid(value) if (res === false) throw new Error('Video licence is not valid.') } @@ -122,7 +122,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da type: DataTypes.INTEGER, allowNull: true, validate: { - languageValid: function (value) { + languageValid: value => { const res = isVideoLanguageValid(value) if (res === false) throw new Error('Video language is not valid.') } @@ -132,7 +132,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da type: DataTypes.BOOLEAN, allowNull: false, validate: { - nsfwValid: function (value) { + nsfwValid: value => { const res = isVideoNSFWValid(value) if (res === false) throw new Error('Video nsfw attribute is not valid.') } @@ -142,7 +142,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da type: DataTypes.STRING, allowNull: false, validate: { - descriptionValid: function (value) { + descriptionValid: value => { const res = isVideoDescriptionValid(value) if (res === false) throw new Error('Video description is not valid.') } @@ -152,7 +152,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da type: DataTypes.STRING, allowNull: false, validate: { - infoHashValid: function (value) { + infoHashValid: value => { const res = isVideoInfoHashValid(value) if (res === false) throw new Error('Video info hash is not valid.') } @@ -162,7 +162,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da type: DataTypes.INTEGER, allowNull: false, validate: { - durationValid: function (value) { + durationValid: value => { const res = isVideoDurationValid(value) if (res === false) throw new Error('Video duration is not valid.') } @@ -549,9 +549,7 @@ transcodeVideofile = function (this: VideoInstance) { }) .catch(err => { // Autodesctruction... - video.destroy().asCallback(function (err) { - if (err) logger.error('Cannot destruct video after transcoding failure.', err) - }) + video.destroy().catch(err => logger.error('Cannot destruct video after transcoding failure.', err)) return rej(err) }) @@ -574,7 +572,7 @@ generateThumbnailFromData = function (video: VideoInstance, thumbnailData: strin getDurationFromFile = function (videoPath: string) { return new Promise((res, rej) => { - ffmpeg.ffprobe(videoPath, function (err, metadata) { + ffmpeg.ffprobe(videoPath, (err, metadata) => { if (err) return rej(err) return res(Math.floor(metadata.format.duration)) @@ -865,9 +863,7 @@ function generateImage (video: VideoInstance, videoPath: string, folder: string, return new Promise((res, rej) => { ffmpeg(videoPath) .on('error', rej) - .on('end', function () { - return res(imageName) - }) + .on('end', () => res(imageName)) .thumbnail(options) }) } -- cgit v1.2.3