aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-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
9 files changed, 43 insertions, 44 deletions
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}