aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-15 22:22:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-20 09:57:40 +0200
commit65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch)
tree4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/models
parentd5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff)
downloadPeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip
First typescript iteration
Diffstat (limited to 'server/models')
-rw-r--r--server/models/application.ts (renamed from server/models/application.js)4
-rw-r--r--server/models/author.ts (renamed from server/models/author.js)8
-rw-r--r--server/models/job.ts (renamed from server/models/job.js)8
-rw-r--r--server/models/oauth-client.ts (renamed from server/models/oauth-client.js)2
-rw-r--r--server/models/oauth-token.ts (renamed from server/models/oauth-token.js)4
-rw-r--r--server/models/pod.ts (renamed from server/models/pod.js)28
-rw-r--r--server/models/request-to-pod.ts (renamed from server/models/request-to-pod.js)6
-rw-r--r--server/models/request-video-event.ts (renamed from server/models/request-video-event.js)12
-rw-r--r--server/models/request-video-qadu.ts (renamed from server/models/request-video-qadu.js)8
-rw-r--r--server/models/request.ts (renamed from server/models/request.js)10
-rw-r--r--server/models/tag.ts (renamed from server/models/tag.js)6
-rw-r--r--server/models/user-video-rate.ts (renamed from server/models/user-video-rate.js)11
-rw-r--r--server/models/user.ts (renamed from server/models/user.js)35
-rw-r--r--server/models/utils.ts (renamed from server/models/utils.js)10
-rw-r--r--server/models/video-abuse.ts (renamed from server/models/video-abuse.js)16
-rw-r--r--server/models/video-blacklist.ts (renamed from server/models/video-blacklist.js)6
-rw-r--r--server/models/video-tag.ts (renamed from server/models/video-tag.js)4
-rw-r--r--server/models/video.ts (renamed from server/models/video.js)155
18 files changed, 155 insertions, 178 deletions
diff --git a/server/models/application.js b/server/models/application.ts
index 64e1a0540..38a57e327 100644
--- a/server/models/application.js
+++ b/server/models/application.ts
@@ -1,5 +1,3 @@
1'use strict'
2
3module.exports = function (sequelize, DataTypes) { 1module.exports = function (sequelize, DataTypes) {
4 const Application = sequelize.define('Application', 2 const Application = sequelize.define('Application',
5 { 3 {
@@ -38,7 +36,7 @@ function loadMigrationVersion (callback) {
38} 36}
39 37
40function updateMigrationVersion (newVersion, transaction, callback) { 38function updateMigrationVersion (newVersion, transaction, callback) {
41 const options = { 39 const options: { where?: any, transaction?: any } = {
42 where: {} 40 where: {}
43 } 41 }
44 42
diff --git a/server/models/author.js b/server/models/author.ts
index 34b013097..4a7396929 100644
--- a/server/models/author.js
+++ b/server/models/author.ts
@@ -1,6 +1,4 @@
1'use strict' 1import { isUserUsernameValid } from '../helpers'
2
3const customUsersValidators = require('../helpers/custom-validators').users
4 2
5module.exports = function (sequelize, DataTypes) { 3module.exports = function (sequelize, DataTypes) {
6 const Author = sequelize.define('Author', 4 const Author = sequelize.define('Author',
@@ -10,7 +8,7 @@ module.exports = function (sequelize, DataTypes) {
10 allowNull: false, 8 allowNull: false,
11 validate: { 9 validate: {
12 usernameValid: function (value) { 10 usernameValid: function (value) {
13 const res = customUsersValidators.isUserUsernameValid(value) 11 const res = isUserUsernameValid(value)
14 if (res === false) throw new Error('Username is not valid.') 12 if (res === false) throw new Error('Username is not valid.')
15 } 13 }
16 } 14 }
@@ -76,7 +74,7 @@ function findOrCreateAuthor (name, podId, userId, transaction, callback) {
76 userId 74 userId
77 } 75 }
78 76
79 const query = { 77 const query: any = {
80 where: author, 78 where: author,
81 defaults: author 79 defaults: author
82 } 80 }
diff --git a/server/models/job.js b/server/models/job.ts
index 949f88d44..6843e399b 100644
--- a/server/models/job.js
+++ b/server/models/job.ts
@@ -1,8 +1,6 @@
1'use strict' 1import { values } from 'lodash'
2 2
3const values = require('lodash/values') 3import { JOB_STATES } from '../initializers'
4
5const constants = require('../initializers/constants')
6 4
7// --------------------------------------------------------------------------- 5// ---------------------------------------------------------------------------
8 6
@@ -10,7 +8,7 @@ module.exports = function (sequelize, DataTypes) {
10 const Job = sequelize.define('Job', 8 const Job = sequelize.define('Job',
11 { 9 {
12 state: { 10 state: {
13 type: DataTypes.ENUM(values(constants.JOB_STATES)), 11 type: DataTypes.ENUM(values(JOB_STATES)),
14 allowNull: false 12 allowNull: false
15 }, 13 },
16 handlerName: { 14 handlerName: {
diff --git a/server/models/oauth-client.js b/server/models/oauth-client.ts
index 021a34007..3198a85ef 100644
--- a/server/models/oauth-client.js
+++ b/server/models/oauth-client.ts
@@ -1,5 +1,3 @@
1'use strict'
2
3module.exports = function (sequelize, DataTypes) { 1module.exports = function (sequelize, DataTypes) {
4 const OAuthClient = sequelize.define('OAuthClient', 2 const OAuthClient = sequelize.define('OAuthClient',
5 { 3 {
diff --git a/server/models/oauth-token.js b/server/models/oauth-token.ts
index 68e7c9ff7..74c9180eb 100644
--- a/server/models/oauth-token.js
+++ b/server/models/oauth-token.ts
@@ -1,6 +1,4 @@
1'use strict' 1import { logger } from '../helpers'
2
3const logger = require('../helpers/logger')
4 2
5// --------------------------------------------------------------------------- 3// ---------------------------------------------------------------------------
6 4
diff --git a/server/models/pod.js b/server/models/pod.ts
index 8e2d488e1..0e0262978 100644
--- a/server/models/pod.js
+++ b/server/models/pod.ts
@@ -1,12 +1,8 @@
1'use strict' 1import { each, waterfall } from 'async'
2import { map } from 'lodash'
2 3
3const each = require('async/each') 4import { FRIEND_SCORE, PODS_SCORE } from '../initializers'
4const map = require('lodash/map') 5import { logger, isHostValid } from '../helpers'
5const waterfall = require('async/waterfall')
6
7const constants = require('../initializers/constants')
8const logger = require('../helpers/logger')
9const customPodsValidators = require('../helpers/custom-validators').pods
10 6
11// --------------------------------------------------------------------------- 7// ---------------------------------------------------------------------------
12 8
@@ -18,7 +14,7 @@ module.exports = function (sequelize, DataTypes) {
18 allowNull: false, 14 allowNull: false,
19 validate: { 15 validate: {
20 isHost: function (value) { 16 isHost: function (value) {
21 const res = customPodsValidators.isHostValid(value) 17 const res = isHostValid(value)
22 if (res === false) throw new Error('Host not valid.') 18 if (res === false) throw new Error('Host not valid.')
23 } 19 }
24 } 20 }
@@ -29,11 +25,11 @@ module.exports = function (sequelize, DataTypes) {
29 }, 25 },
30 score: { 26 score: {
31 type: DataTypes.INTEGER, 27 type: DataTypes.INTEGER,
32 defaultValue: constants.FRIEND_SCORE.BASE, 28 defaultValue: FRIEND_SCORE.BASE,
33 allowNull: false, 29 allowNull: false,
34 validate: { 30 validate: {
35 isInt: true, 31 isInt: true,
36 max: constants.FRIEND_SCORE.MAX 32 max: FRIEND_SCORE.MAX
37 } 33 }
38 }, 34 },
39 email: { 35 email: {
@@ -106,7 +102,7 @@ function countAll (callback) {
106} 102}
107 103
108function incrementScores (ids, value, callback) { 104function incrementScores (ids, value, callback) {
109 if (!callback) callback = function () {} 105 if (!callback) callback = function () { /* empty */ }
110 106
111 const update = { 107 const update = {
112 score: this.sequelize.literal('score +' + value) 108 score: this.sequelize.literal('score +' + value)
@@ -135,7 +131,7 @@ function listAllIds (transaction, callback) {
135 transaction = null 131 transaction = null
136 } 132 }
137 133
138 const query = { 134 const query: any = {
139 attributes: [ 'id' ] 135 attributes: [ 'id' ]
140 } 136 }
141 137
@@ -223,13 +219,13 @@ function updatePodsScore (goodPods, badPods) {
223 logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length) 219 logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length)
224 220
225 if (goodPods.length !== 0) { 221 if (goodPods.length !== 0) {
226 this.incrementScores(goodPods, constants.PODS_SCORE.BONUS, function (err) { 222 this.incrementScores(goodPods, PODS_SCORE.BONUS, function (err) {
227 if (err) logger.error('Cannot increment scores of good pods.', { error: err }) 223 if (err) logger.error('Cannot increment scores of good pods.', { error: err })
228 }) 224 })
229 } 225 }
230 226
231 if (badPods.length !== 0) { 227 if (badPods.length !== 0) {
232 this.incrementScores(badPods, constants.PODS_SCORE.MALUS, function (err) { 228 this.incrementScores(badPods, PODS_SCORE.MALUS, function (err) {
233 if (err) logger.error('Cannot decrement scores of bad pods.', { error: err }) 229 if (err) logger.error('Cannot decrement scores of bad pods.', { error: err })
234 removeBadPods.call(self) 230 removeBadPods.call(self)
235 }) 231 })
@@ -255,7 +251,7 @@ function removeBadPods () {
255 }, 251 },
256 252
257 function removeTheseBadPods (pods, callback) { 253 function removeTheseBadPods (pods, callback) {
258 each(pods, function (pod, callbackEach) { 254 each(pods, function (pod: any, callbackEach) {
259 pod.destroy().asCallback(callbackEach) 255 pod.destroy().asCallback(callbackEach)
260 }, function (err) { 256 }, function (err) {
261 return callback(err, pods.length) 257 return callback(err, pods.length)
diff --git a/server/models/request-to-pod.js b/server/models/request-to-pod.ts
index 0e01a842e..479202e40 100644
--- a/server/models/request-to-pod.js
+++ b/server/models/request-to-pod.ts
@@ -1,7 +1,3 @@
1'use strict'
2
3// ---------------------------------------------------------------------------
4
5module.exports = function (sequelize, DataTypes) { 1module.exports = function (sequelize, DataTypes) {
6 const RequestToPod = sequelize.define('RequestToPod', {}, { 2 const RequestToPod = sequelize.define('RequestToPod', {}, {
7 indexes: [ 3 indexes: [
@@ -27,7 +23,7 @@ module.exports = function (sequelize, DataTypes) {
27// --------------------------------------------------------------------------- 23// ---------------------------------------------------------------------------
28 24
29function removeByRequestIdsAndPod (requestsIds, podId, callback) { 25function removeByRequestIdsAndPod (requestsIds, podId, callback) {
30 if (!callback) callback = function () {} 26 if (!callback) callback = function () { /* empty */ }
31 27
32 const query = { 28 const query = {
33 where: { 29 where: {
diff --git a/server/models/request-video-event.js b/server/models/request-video-event.ts
index 9ebeaec90..c61525029 100644
--- a/server/models/request-video-event.js
+++ b/server/models/request-video-event.ts
@@ -1,13 +1,11 @@
1'use strict'
2
3/* 1/*
4 Request Video events (likes, dislikes, views...) 2 Request Video events (likes, dislikes, views...)
5*/ 3*/
6 4
7const values = require('lodash/values') 5import { values } from 'lodash'
8 6
9const constants = require('../initializers/constants') 7import { REQUEST_VIDEO_EVENT_TYPES } from '../initializers'
10const customVideosValidators = require('../helpers/custom-validators').videos 8import { isVideoEventCountValid } from '../helpers'
11 9
12// --------------------------------------------------------------------------- 10// ---------------------------------------------------------------------------
13 11
@@ -15,7 +13,7 @@ module.exports = function (sequelize, DataTypes) {
15 const RequestVideoEvent = sequelize.define('RequestVideoEvent', 13 const RequestVideoEvent = sequelize.define('RequestVideoEvent',
16 { 14 {
17 type: { 15 type: {
18 type: DataTypes.ENUM(values(constants.REQUEST_VIDEO_EVENT_TYPES)), 16 type: DataTypes.ENUM(values(REQUEST_VIDEO_EVENT_TYPES)),
19 allowNull: false 17 allowNull: false
20 }, 18 },
21 count: { 19 count: {
@@ -23,7 +21,7 @@ module.exports = function (sequelize, DataTypes) {
23 allowNull: false, 21 allowNull: false,
24 validate: { 22 validate: {
25 countValid: function (value) { 23 countValid: function (value) {
26 const res = customVideosValidators.isVideoEventCountValid(value) 24 const res = isVideoEventCountValid(value)
27 if (res === false) throw new Error('Video event count is not valid.') 25 if (res === false) throw new Error('Video event count is not valid.')
28 } 26 }
29 } 27 }
diff --git a/server/models/request-video-qadu.js b/server/models/request-video-qadu.ts
index 5d88738aa..2b1ed07c9 100644
--- a/server/models/request-video-qadu.js
+++ b/server/models/request-video-qadu.ts
@@ -1,5 +1,3 @@
1'use strict'
2
3/* 1/*
4 Request Video for Quick And Dirty Updates like: 2 Request Video for Quick And Dirty Updates like:
5 - views 3 - views
@@ -11,9 +9,9 @@
11 So we put it an independant request scheduler. 9 So we put it an independant request scheduler.
12*/ 10*/
13 11
14const values = require('lodash/values') 12import { values } from 'lodash'
15 13
16const constants = require('../initializers/constants') 14import { REQUEST_VIDEO_QADU_TYPES } from '../initializers'
17 15
18// --------------------------------------------------------------------------- 16// ---------------------------------------------------------------------------
19 17
@@ -21,7 +19,7 @@ module.exports = function (sequelize, DataTypes) {
21 const RequestVideoQadu = sequelize.define('RequestVideoQadu', 19 const RequestVideoQadu = sequelize.define('RequestVideoQadu',
22 { 20 {
23 type: { 21 type: {
24 type: DataTypes.ENUM(values(constants.REQUEST_VIDEO_QADU_TYPES)), 22 type: DataTypes.ENUM(values(REQUEST_VIDEO_QADU_TYPES)),
25 allowNull: false 23 allowNull: false
26 } 24 }
27 }, 25 },
diff --git a/server/models/request.js b/server/models/request.ts
index 3a047f7ee..672f79d11 100644
--- a/server/models/request.js
+++ b/server/models/request.ts
@@ -1,8 +1,6 @@
1'use strict' 1import { values } from 'lodash'
2 2
3const values = require('lodash/values') 3import { REQUEST_ENDPOINTS } from '../initializers'
4
5const constants = require('../initializers/constants')
6 4
7// --------------------------------------------------------------------------- 5// ---------------------------------------------------------------------------
8 6
@@ -14,7 +12,7 @@ module.exports = function (sequelize, DataTypes) {
14 allowNull: false 12 allowNull: false
15 }, 13 },
16 endpoint: { 14 endpoint: {
17 type: DataTypes.ENUM(values(constants.REQUEST_ENDPOINTS)), 15 type: DataTypes.ENUM(values(REQUEST_ENDPOINTS)),
18 allowNull: false 16 allowNull: false
19 } 17 }
20 }, 18 },
@@ -100,7 +98,7 @@ function removeAll (callback) {
100} 98}
101 99
102function removeWithEmptyTo (callback) { 100function removeWithEmptyTo (callback) {
103 if (!callback) callback = function () {} 101 if (!callback) callback = function () { /* empty */ }
104 102
105 const query = { 103 const query = {
106 where: { 104 where: {
diff --git a/server/models/tag.js b/server/models/tag.ts
index 145e090c1..85a0442d2 100644
--- a/server/models/tag.js
+++ b/server/models/tag.ts
@@ -1,6 +1,4 @@
1'use strict' 1import { each } from 'async'
2
3const each = require('async/each')
4 2
5// --------------------------------------------------------------------------- 3// ---------------------------------------------------------------------------
6 4
@@ -51,7 +49,7 @@ function findOrCreateTags (tags, transaction, callback) {
51 const tagInstances = [] 49 const tagInstances = []
52 50
53 each(tags, function (tag, callbackEach) { 51 each(tags, function (tag, callbackEach) {
54 const query = { 52 const query: any = {
55 where: { 53 where: {
56 name: tag 54 name: tag
57 }, 55 },
diff --git a/server/models/user-video-rate.js b/server/models/user-video-rate.ts
index 84007d70c..6603c7862 100644
--- a/server/models/user-video-rate.js
+++ b/server/models/user-video-rate.ts
@@ -1,13 +1,10 @@
1'use strict'
2
3/* 1/*
4 User rates per video. 2 User rates per video.
5 3
6*/ 4*/
5import { values } from 'lodash'
7 6
8const values = require('lodash/values') 7import { VIDEO_RATE_TYPES } from '../initializers'
9
10const constants = require('../initializers/constants')
11 8
12// --------------------------------------------------------------------------- 9// ---------------------------------------------------------------------------
13 10
@@ -15,7 +12,7 @@ module.exports = function (sequelize, DataTypes) {
15 const UserVideoRate = sequelize.define('UserVideoRate', 12 const UserVideoRate = sequelize.define('UserVideoRate',
16 { 13 {
17 type: { 14 type: {
18 type: DataTypes.ENUM(values(constants.VIDEO_RATE_TYPES)), 15 type: DataTypes.ENUM(values(VIDEO_RATE_TYPES)),
19 allowNull: false 16 allowNull: false
20 } 17 }
21 }, 18 },
@@ -70,7 +67,7 @@ function load (userId, videoId, transaction, callback) {
70 } 67 }
71 } 68 }
72 69
73 const options = {} 70 const options: any = {}
74 if (transaction) options.transaction = transaction 71 if (transaction) options.transaction = transaction
75 72
76 return this.findOne(query, options).asCallback(callback) 73 return this.findOne(query, options).asCallback(callback)
diff --git a/server/models/user.js b/server/models/user.ts
index 8f9c2bf65..d63a50cc4 100644
--- a/server/models/user.js
+++ b/server/models/user.ts
@@ -1,11 +1,14 @@
1'use strict' 1import { values } from 'lodash'
2 2
3const values = require('lodash/values') 3import { getSort } from './utils'
4 4import { USER_ROLES } from '../initializers'
5const modelUtils = require('./utils') 5import {
6const constants = require('../initializers/constants') 6 cryptPassword,
7const peertubeCrypto = require('../helpers/peertube-crypto') 7 comparePassword,
8const customUsersValidators = require('../helpers/custom-validators').users 8 isUserPasswordValid,
9 isUserUsernameValid,
10 isUserDisplayNSFWValid
11} from '../helpers'
9 12
10// --------------------------------------------------------------------------- 13// ---------------------------------------------------------------------------
11 14
@@ -17,7 +20,7 @@ module.exports = function (sequelize, DataTypes) {
17 allowNull: false, 20 allowNull: false,
18 validate: { 21 validate: {
19 passwordValid: function (value) { 22 passwordValid: function (value) {
20 const res = customUsersValidators.isUserPasswordValid(value) 23 const res = isUserPasswordValid(value)
21 if (res === false) throw new Error('Password not valid.') 24 if (res === false) throw new Error('Password not valid.')
22 } 25 }
23 } 26 }
@@ -27,7 +30,7 @@ module.exports = function (sequelize, DataTypes) {
27 allowNull: false, 30 allowNull: false,
28 validate: { 31 validate: {
29 usernameValid: function (value) { 32 usernameValid: function (value) {
30 const res = customUsersValidators.isUserUsernameValid(value) 33 const res = isUserUsernameValid(value)
31 if (res === false) throw new Error('Username not valid.') 34 if (res === false) throw new Error('Username not valid.')
32 } 35 }
33 } 36 }
@@ -45,13 +48,13 @@ module.exports = function (sequelize, DataTypes) {
45 defaultValue: false, 48 defaultValue: false,
46 validate: { 49 validate: {
47 nsfwValid: function (value) { 50 nsfwValid: function (value) {
48 const res = customUsersValidators.isUserDisplayNSFWValid(value) 51 const res = isUserDisplayNSFWValid(value)
49 if (res === false) throw new Error('Display NSFW is not valid.') 52 if (res === false) throw new Error('Display NSFW is not valid.')
50 } 53 }
51 } 54 }
52 }, 55 },
53 role: { 56 role: {
54 type: DataTypes.ENUM(values(constants.USER_ROLES)), 57 type: DataTypes.ENUM(values(USER_ROLES)),
55 allowNull: false 58 allowNull: false
56 } 59 }
57 }, 60 },
@@ -93,7 +96,7 @@ module.exports = function (sequelize, DataTypes) {
93} 96}
94 97
95function beforeCreateOrUpdate (user, options, next) { 98function beforeCreateOrUpdate (user, options, next) {
96 peertubeCrypto.cryptPassword(user.password, function (err, hash) { 99 cryptPassword(user.password, function (err, hash) {
97 if (err) return next(err) 100 if (err) return next(err)
98 101
99 user.password = hash 102 user.password = hash
@@ -105,7 +108,7 @@ function beforeCreateOrUpdate (user, options, next) {
105// ------------------------------ METHODS ------------------------------ 108// ------------------------------ METHODS ------------------------------
106 109
107function isPasswordMatch (password, callback) { 110function isPasswordMatch (password, callback) {
108 return peertubeCrypto.comparePassword(password, this.password, callback) 111 return comparePassword(password, this.password, callback)
109} 112}
110 113
111function toFormatedJSON () { 114function toFormatedJSON () {
@@ -120,7 +123,7 @@ function toFormatedJSON () {
120} 123}
121 124
122function isAdmin () { 125function isAdmin () {
123 return this.role === constants.USER_ROLES.ADMIN 126 return this.role === USER_ROLES.ADMIN
124} 127}
125 128
126// ------------------------------ STATICS ------------------------------ 129// ------------------------------ STATICS ------------------------------
@@ -159,7 +162,7 @@ function listForApi (start, count, sort, callback) {
159 const query = { 162 const query = {
160 offset: start, 163 offset: start,
161 limit: count, 164 limit: count,
162 order: [ modelUtils.getSort(sort) ] 165 order: [ getSort(sort) ]
163 } 166 }
164 167
165 return this.findAndCountAll(query).asCallback(function (err, result) { 168 return this.findAndCountAll(query).asCallback(function (err, result) {
diff --git a/server/models/utils.js b/server/models/utils.ts
index 49636b3d8..601811913 100644
--- a/server/models/utils.js
+++ b/server/models/utils.ts
@@ -1,9 +1,3 @@
1'use strict'
2
3const utils = {
4 getSort
5}
6
7// Translate for example "-name" to [ 'name', 'DESC' ] 1// Translate for example "-name" to [ 'name', 'DESC' ]
8function getSort (value) { 2function getSort (value) {
9 let field 3 let field
@@ -22,4 +16,6 @@ function getSort (value) {
22 16
23// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
24 18
25module.exports = utils 19export {
20 getSort
21}
diff --git a/server/models/video-abuse.js b/server/models/video-abuse.ts
index 67cead3af..2a18a293d 100644
--- a/server/models/video-abuse.js
+++ b/server/models/video-abuse.ts
@@ -1,8 +1,6 @@
1'use strict' 1import { CONFIG } from '../initializers'
2 2import { isVideoAbuseReporterUsernameValid, isVideoAbuseReasonValid } from '../helpers'
3const constants = require('../initializers/constants') 3import { getSort } from './utils'
4const modelUtils = require('./utils')
5const customVideosValidators = require('../helpers/custom-validators').videos
6 4
7module.exports = function (sequelize, DataTypes) { 5module.exports = function (sequelize, DataTypes) {
8 const VideoAbuse = sequelize.define('VideoAbuse', 6 const VideoAbuse = sequelize.define('VideoAbuse',
@@ -12,7 +10,7 @@ module.exports = function (sequelize, DataTypes) {
12 allowNull: false, 10 allowNull: false,
13 validate: { 11 validate: {
14 reporterUsernameValid: function (value) { 12 reporterUsernameValid: function (value) {
15 const res = customVideosValidators.isVideoAbuseReporterUsernameValid(value) 13 const res = isVideoAbuseReporterUsernameValid(value)
16 if (res === false) throw new Error('Video abuse reporter username is not valid.') 14 if (res === false) throw new Error('Video abuse reporter username is not valid.')
17 } 15 }
18 } 16 }
@@ -22,7 +20,7 @@ module.exports = function (sequelize, DataTypes) {
22 allowNull: false, 20 allowNull: false,
23 validate: { 21 validate: {
24 reasonValid: function (value) { 22 reasonValid: function (value) {
25 const res = customVideosValidators.isVideoAbuseReasonValid(value) 23 const res = isVideoAbuseReasonValid(value)
26 if (res === false) throw new Error('Video abuse reason is not valid.') 24 if (res === false) throw new Error('Video abuse reason is not valid.')
27 } 25 }
28 } 26 }
@@ -75,7 +73,7 @@ function listForApi (start, count, sort, callback) {
75 const query = { 73 const query = {
76 offset: start, 74 offset: start,
77 limit: count, 75 limit: count,
78 order: [ modelUtils.getSort(sort) ], 76 order: [ getSort(sort) ],
79 include: [ 77 include: [
80 { 78 {
81 model: this.sequelize.models.Pod, 79 model: this.sequelize.models.Pod,
@@ -98,7 +96,7 @@ function toFormatedJSON () {
98 reporterPodHost = this.Pod.host 96 reporterPodHost = this.Pod.host
99 } else { 97 } else {
100 // It means it's our video 98 // It means it's our video
101 reporterPodHost = constants.CONFIG.WEBSERVER.HOST 99 reporterPodHost = CONFIG.WEBSERVER.HOST
102 } 100 }
103 101
104 const json = { 102 const json = {
diff --git a/server/models/video-blacklist.js b/server/models/video-blacklist.ts
index 02ea15760..1f00702c7 100644
--- a/server/models/video-blacklist.js
+++ b/server/models/video-blacklist.ts
@@ -1,6 +1,4 @@
1'use strict' 1import { getSort } from './utils'
2
3const modelUtils = require('./utils')
4 2
5// --------------------------------------------------------------------------- 3// ---------------------------------------------------------------------------
6 4
@@ -64,7 +62,7 @@ function listForApi (start, count, sort, callback) {
64 const query = { 62 const query = {
65 offset: start, 63 offset: start,
66 limit: count, 64 limit: count,
67 order: [ modelUtils.getSort(sort) ] 65 order: [ getSort(sort) ]
68 } 66 }
69 67
70 return this.findAndCountAll(query).asCallback(function (err, result) { 68 return this.findAndCountAll(query).asCallback(function (err, result) {
diff --git a/server/models/video-tag.js b/server/models/video-tag.ts
index cd9277a6e..83ff6053f 100644
--- a/server/models/video-tag.js
+++ b/server/models/video-tag.ts
@@ -1,7 +1,3 @@
1'use strict'
2
3// ---------------------------------------------------------------------------
4
5module.exports = function (sequelize, DataTypes) { 1module.exports = function (sequelize, DataTypes) {
6 const VideoTag = sequelize.define('VideoTag', {}, { 2 const VideoTag = sequelize.define('VideoTag', {}, {
7 indexes: [ 3 indexes: [
diff --git a/server/models/video.js b/server/models/video.ts
index da4ddb420..1e29f1355 100644
--- a/server/models/video.js
+++ b/server/models/video.ts
@@ -1,24 +1,38 @@
1'use strict' 1import safeBuffer = require('safe-buffer')
2 2const Buffer = safeBuffer.Buffer
3const Buffer = require('safe-buffer').Buffer 3import createTorrent = require('create-torrent')
4const createTorrent = require('create-torrent') 4import ffmpeg = require('fluent-ffmpeg')
5const ffmpeg = require('fluent-ffmpeg') 5import fs = require('fs')
6const fs = require('fs') 6import magnetUtil = require('magnet-uri')
7const magnetUtil = require('magnet-uri') 7import { map, values } from 'lodash'
8const map = require('lodash/map') 8import { parallel, series } from 'async'
9const parallel = require('async/parallel') 9import parseTorrent = require('parse-torrent')
10const series = require('async/series') 10import { join } from 'path'
11const parseTorrent = require('parse-torrent') 11
12const pathUtils = require('path')
13const values = require('lodash/values')
14
15const constants = require('../initializers/constants')
16const logger = require('../helpers/logger')
17const friends = require('../lib/friends')
18const modelUtils = require('./utils')
19const customVideosValidators = require('../helpers/custom-validators').videos
20const db = require('../initializers/database') 12const db = require('../initializers/database')
21const jobScheduler = require('../lib/jobs/job-scheduler') 13import {
14 logger,
15 isVideoNameValid,
16 isVideoCategoryValid,
17 isVideoLicenceValid,
18 isVideoLanguageValid,
19 isVideoNSFWValid,
20 isVideoDescriptionValid,
21 isVideoInfoHashValid,
22 isVideoDurationValid
23} from '../helpers'
24import {
25 CONSTRAINTS_FIELDS,
26 CONFIG,
27 REMOTE_SCHEME,
28 STATIC_PATHS,
29 VIDEO_CATEGORIES,
30 VIDEO_LICENCES,
31 VIDEO_LANGUAGES,
32 THUMBNAILS_SIZE
33} from '../initializers'
34import { JobScheduler, removeVideoToFriends } from '../lib'
35import { getSort } from './utils'
22 36
23// --------------------------------------------------------------------------- 37// ---------------------------------------------------------------------------
24 38
@@ -38,13 +52,13 @@ module.exports = function (sequelize, DataTypes) {
38 allowNull: false, 52 allowNull: false,
39 validate: { 53 validate: {
40 nameValid: function (value) { 54 nameValid: function (value) {
41 const res = customVideosValidators.isVideoNameValid(value) 55 const res = isVideoNameValid(value)
42 if (res === false) throw new Error('Video name is not valid.') 56 if (res === false) throw new Error('Video name is not valid.')
43 } 57 }
44 } 58 }
45 }, 59 },
46 extname: { 60 extname: {
47 type: DataTypes.ENUM(values(constants.CONSTRAINTS_FIELDS.VIDEOS.EXTNAME)), 61 type: DataTypes.ENUM(values(CONSTRAINTS_FIELDS.VIDEOS.EXTNAME)),
48 allowNull: false 62 allowNull: false
49 }, 63 },
50 remoteId: { 64 remoteId: {
@@ -59,7 +73,7 @@ module.exports = function (sequelize, DataTypes) {
59 allowNull: false, 73 allowNull: false,
60 validate: { 74 validate: {
61 categoryValid: function (value) { 75 categoryValid: function (value) {
62 const res = customVideosValidators.isVideoCategoryValid(value) 76 const res = isVideoCategoryValid(value)
63 if (res === false) throw new Error('Video category is not valid.') 77 if (res === false) throw new Error('Video category is not valid.')
64 } 78 }
65 } 79 }
@@ -70,7 +84,7 @@ module.exports = function (sequelize, DataTypes) {
70 defaultValue: null, 84 defaultValue: null,
71 validate: { 85 validate: {
72 licenceValid: function (value) { 86 licenceValid: function (value) {
73 const res = customVideosValidators.isVideoLicenceValid(value) 87 const res = isVideoLicenceValid(value)
74 if (res === false) throw new Error('Video licence is not valid.') 88 if (res === false) throw new Error('Video licence is not valid.')
75 } 89 }
76 } 90 }
@@ -80,7 +94,7 @@ module.exports = function (sequelize, DataTypes) {
80 allowNull: true, 94 allowNull: true,
81 validate: { 95 validate: {
82 languageValid: function (value) { 96 languageValid: function (value) {
83 const res = customVideosValidators.isVideoLanguageValid(value) 97 const res = isVideoLanguageValid(value)
84 if (res === false) throw new Error('Video language is not valid.') 98 if (res === false) throw new Error('Video language is not valid.')
85 } 99 }
86 } 100 }
@@ -90,7 +104,7 @@ module.exports = function (sequelize, DataTypes) {
90 allowNull: false, 104 allowNull: false,
91 validate: { 105 validate: {
92 nsfwValid: function (value) { 106 nsfwValid: function (value) {
93 const res = customVideosValidators.isVideoNSFWValid(value) 107 const res = isVideoNSFWValid(value)
94 if (res === false) throw new Error('Video nsfw attribute is not valid.') 108 if (res === false) throw new Error('Video nsfw attribute is not valid.')
95 } 109 }
96 } 110 }
@@ -100,7 +114,7 @@ module.exports = function (sequelize, DataTypes) {
100 allowNull: false, 114 allowNull: false,
101 validate: { 115 validate: {
102 descriptionValid: function (value) { 116 descriptionValid: function (value) {
103 const res = customVideosValidators.isVideoDescriptionValid(value) 117 const res = isVideoDescriptionValid(value)
104 if (res === false) throw new Error('Video description is not valid.') 118 if (res === false) throw new Error('Video description is not valid.')
105 } 119 }
106 } 120 }
@@ -110,7 +124,7 @@ module.exports = function (sequelize, DataTypes) {
110 allowNull: false, 124 allowNull: false,
111 validate: { 125 validate: {
112 infoHashValid: function (value) { 126 infoHashValid: function (value) {
113 const res = customVideosValidators.isVideoInfoHashValid(value) 127 const res = isVideoInfoHashValid(value)
114 if (res === false) throw new Error('Video info hash is not valid.') 128 if (res === false) throw new Error('Video info hash is not valid.')
115 } 129 }
116 } 130 }
@@ -120,7 +134,7 @@ module.exports = function (sequelize, DataTypes) {
120 allowNull: false, 134 allowNull: false,
121 validate: { 135 validate: {
122 durationValid: function (value) { 136 durationValid: function (value) {
123 const res = customVideosValidators.isVideoDurationValid(value) 137 const res = isVideoDurationValid(value)
124 if (res === false) throw new Error('Video duration is not valid.') 138 if (res === false) throw new Error('Video duration is not valid.')
125 } 139 }
126 } 140 }
@@ -233,7 +247,7 @@ function beforeCreate (video, options, next) {
233 const tasks = [] 247 const tasks = []
234 248
235 if (video.isOwned()) { 249 if (video.isOwned()) {
236 const videoPath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename()) 250 const videoPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename())
237 251
238 tasks.push( 252 tasks.push(
239 function createVideoTorrent (callback) { 253 function createVideoTorrent (callback) {
@@ -249,14 +263,14 @@ function beforeCreate (video, options, next) {
249 } 263 }
250 ) 264 )
251 265
252 if (constants.CONFIG.TRANSCODING.ENABLED === true) { 266 if (CONFIG.TRANSCODING.ENABLED === true) {
253 tasks.push( 267 tasks.push(
254 function createVideoTranscoderJob (callback) { 268 function createVideoTranscoderJob (callback) {
255 const dataInput = { 269 const dataInput = {
256 id: video.id 270 id: video.id
257 } 271 }
258 272
259 jobScheduler.createJob(options.transaction, 'videoTranscoder', dataInput, callback) 273 JobScheduler.Instance.createJob(options.transaction, 'videoTranscoder', dataInput, callback)
260 } 274 }
261 ) 275 )
262 } 276 }
@@ -295,7 +309,7 @@ function afterDestroy (video, options, next) {
295 remoteId: video.id 309 remoteId: video.id
296 } 310 }
297 311
298 friends.removeVideoToFriends(params) 312 removeVideoToFriends(params)
299 313
300 return callback() 314 return callback()
301 } 315 }
@@ -332,19 +346,20 @@ function associate (models) {
332} 346}
333 347
334function generateMagnetUri () { 348function generateMagnetUri () {
335 let baseUrlHttp, baseUrlWs 349 let baseUrlHttp
350 let baseUrlWs
336 351
337 if (this.isOwned()) { 352 if (this.isOwned()) {
338 baseUrlHttp = constants.CONFIG.WEBSERVER.URL 353 baseUrlHttp = CONFIG.WEBSERVER.URL
339 baseUrlWs = constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT 354 baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
340 } else { 355 } else {
341 baseUrlHttp = constants.REMOTE_SCHEME.HTTP + '://' + this.Author.Pod.host 356 baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + this.Author.Pod.host
342 baseUrlWs = constants.REMOTE_SCHEME.WS + '://' + this.Author.Pod.host 357 baseUrlWs = REMOTE_SCHEME.WS + '://' + this.Author.Pod.host
343 } 358 }
344 359
345 const xs = baseUrlHttp + constants.STATIC_PATHS.TORRENTS + this.getTorrentName() 360 const xs = baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentName()
346 const announce = baseUrlWs + '/tracker/socket' 361 const announce = baseUrlWs + '/tracker/socket'
347 const urlList = [ baseUrlHttp + constants.STATIC_PATHS.WEBSEED + this.getVideoFilename() ] 362 const urlList = [ baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename() ]
348 363
349 const magnetHash = { 364 const magnetHash = {
350 xs, 365 xs,
@@ -395,19 +410,19 @@ function toFormatedJSON () {
395 podHost = this.Author.Pod.host 410 podHost = this.Author.Pod.host
396 } else { 411 } else {
397 // It means it's our video 412 // It means it's our video
398 podHost = constants.CONFIG.WEBSERVER.HOST 413 podHost = CONFIG.WEBSERVER.HOST
399 } 414 }
400 415
401 // Maybe our pod is not up to date and there are new categories since our version 416 // Maybe our pod is not up to date and there are new categories since our version
402 let categoryLabel = constants.VIDEO_CATEGORIES[this.category] 417 let categoryLabel = VIDEO_CATEGORIES[this.category]
403 if (!categoryLabel) categoryLabel = 'Misc' 418 if (!categoryLabel) categoryLabel = 'Misc'
404 419
405 // Maybe our pod is not up to date and there are new licences since our version 420 // Maybe our pod is not up to date and there are new licences since our version
406 let licenceLabel = constants.VIDEO_LICENCES[this.licence] 421 let licenceLabel = VIDEO_LICENCES[this.licence]
407 if (!licenceLabel) licenceLabel = 'Unknown' 422 if (!licenceLabel) licenceLabel = 'Unknown'
408 423
409 // Language is an optional attribute 424 // Language is an optional attribute
410 let languageLabel = constants.VIDEO_LANGUAGES[this.language] 425 let languageLabel = VIDEO_LANGUAGES[this.language]
411 if (!languageLabel) languageLabel = 'Unknown' 426 if (!languageLabel) languageLabel = 'Unknown'
412 427
413 const json = { 428 const json = {
@@ -430,7 +445,7 @@ function toFormatedJSON () {
430 likes: this.likes, 445 likes: this.likes,
431 dislikes: this.dislikes, 446 dislikes: this.dislikes,
432 tags: map(this.Tags, 'name'), 447 tags: map(this.Tags, 'name'),
433 thumbnailPath: pathUtils.join(constants.STATIC_PATHS.THUMBNAILS, this.getThumbnailName()), 448 thumbnailPath: join(STATIC_PATHS.THUMBNAILS, this.getThumbnailName()),
434 createdAt: this.createdAt, 449 createdAt: this.createdAt,
435 updatedAt: this.updatedAt 450 updatedAt: this.updatedAt
436 } 451 }
@@ -442,7 +457,7 @@ function toAddRemoteJSON (callback) {
442 const self = this 457 const self = this
443 458
444 // Get thumbnail data to send to the other pod 459 // Get thumbnail data to send to the other pod
445 const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) 460 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName())
446 fs.readFile(thumbnailPath, function (err, thumbnailData) { 461 fs.readFile(thumbnailPath, function (err, thumbnailData) {
447 if (err) { 462 if (err) {
448 logger.error('Cannot read the thumbnail of the video') 463 logger.error('Cannot read the thumbnail of the video')
@@ -501,15 +516,15 @@ function toUpdateRemoteJSON (callback) {
501function transcodeVideofile (finalCallback) { 516function transcodeVideofile (finalCallback) {
502 const video = this 517 const video = this
503 518
504 const videosDirectory = constants.CONFIG.STORAGE.VIDEOS_DIR 519 const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
505 const newExtname = '.mp4' 520 const newExtname = '.mp4'
506 const videoInputPath = pathUtils.join(videosDirectory, video.getVideoFilename()) 521 const videoInputPath = join(videosDirectory, video.getVideoFilename())
507 const videoOutputPath = pathUtils.join(videosDirectory, video.id + '-transcoded' + newExtname) 522 const videoOutputPath = join(videosDirectory, video.id + '-transcoded' + newExtname)
508 523
509 ffmpeg(videoInputPath) 524 ffmpeg(videoInputPath)
510 .output(videoOutputPath) 525 .output(videoOutputPath)
511 .videoCodec('libx264') 526 .videoCodec('libx264')
512 .outputOption('-threads ' + constants.CONFIG.TRANSCODING.THREADS) 527 .outputOption('-threads ' + CONFIG.TRANSCODING.THREADS)
513 .outputOption('-movflags faststart') 528 .outputOption('-movflags faststart')
514 .on('error', finalCallback) 529 .on('error', finalCallback)
515 .on('end', function () { 530 .on('end', function () {
@@ -522,12 +537,12 @@ function transcodeVideofile (finalCallback) {
522 // Important to do this before getVideoFilename() to take in account the new file extension 537 // Important to do this before getVideoFilename() to take in account the new file extension
523 video.set('extname', newExtname) 538 video.set('extname', newExtname)
524 539
525 const newVideoPath = pathUtils.join(videosDirectory, video.getVideoFilename()) 540 const newVideoPath = join(videosDirectory, video.getVideoFilename())
526 fs.rename(videoOutputPath, newVideoPath, callback) 541 fs.rename(videoOutputPath, newVideoPath, callback)
527 }, 542 },
528 543
529 function torrent (callback) { 544 function torrent (callback) {
530 const newVideoPath = pathUtils.join(videosDirectory, video.getVideoFilename()) 545 const newVideoPath = join(videosDirectory, video.getVideoFilename())
531 createTorrentFromVideo(video, newVideoPath, callback) 546 createTorrentFromVideo(video, newVideoPath, callback)
532 }, 547 },
533 548
@@ -557,7 +572,7 @@ function generateThumbnailFromData (video, thumbnailData, callback) {
557 // Creating the thumbnail for a remote video 572 // Creating the thumbnail for a remote video
558 573
559 const thumbnailName = video.getThumbnailName() 574 const thumbnailName = video.getThumbnailName()
560 const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName) 575 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName)
561 fs.writeFile(thumbnailPath, Buffer.from(thumbnailData, 'binary'), function (err) { 576 fs.writeFile(thumbnailPath, Buffer.from(thumbnailData, 'binary'), function (err) {
562 if (err) return callback(err) 577 if (err) return callback(err)
563 578
@@ -583,7 +598,7 @@ function listForApi (start, count, sort, callback) {
583 offset: start, 598 offset: start,
584 limit: count, 599 limit: count,
585 distinct: true, // For the count, a video can have many tags 600 distinct: true, // For the count, a video can have many tags
586 order: [ modelUtils.getSort(sort), [ this.sequelize.models.Tag, 'name', 'ASC' ] ], 601 order: [ getSort(sort), [ this.sequelize.models.Tag, 'name', 'ASC' ] ],
587 include: [ 602 include: [
588 { 603 {
589 model: this.sequelize.models.Author, 604 model: this.sequelize.models.Author,
@@ -683,28 +698,28 @@ function loadAndPopulateAuthorAndPodAndTags (id, callback) {
683} 698}
684 699
685function searchAndPopulateAuthorAndPodAndTags (value, field, start, count, sort, callback) { 700function searchAndPopulateAuthorAndPodAndTags (value, field, start, count, sort, callback) {
686 const podInclude = { 701 const podInclude: any = {
687 model: this.sequelize.models.Pod, 702 model: this.sequelize.models.Pod,
688 required: false 703 required: false
689 } 704 }
690 705
691 const authorInclude = { 706 const authorInclude: any = {
692 model: this.sequelize.models.Author, 707 model: this.sequelize.models.Author,
693 include: [ 708 include: [
694 podInclude 709 podInclude
695 ] 710 ]
696 } 711 }
697 712
698 const tagInclude = { 713 const tagInclude: any = {
699 model: this.sequelize.models.Tag 714 model: this.sequelize.models.Tag
700 } 715 }
701 716
702 const query = { 717 const query: any = {
703 where: createBaseVideosWhere.call(this), 718 where: createBaseVideosWhere.call(this),
704 offset: start, 719 offset: start,
705 limit: count, 720 limit: count,
706 distinct: true, // For the count, a video can have many tags 721 distinct: true, // For the count, a video can have many tags
707 order: [ modelUtils.getSort(sort), [ this.sequelize.models.Tag, 'name', 'ASC' ] ] 722 order: [ getSort(sort), [ this.sequelize.models.Tag, 'name', 'ASC' ] ]
708 } 723 }
709 724
710 // Make an exact search with the magnet 725 // Make an exact search with the magnet
@@ -766,39 +781,39 @@ function createBaseVideosWhere () {
766} 781}
767 782
768function removeThumbnail (video, callback) { 783function removeThumbnail (video, callback) {
769 const thumbnailPath = pathUtils.join(constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName()) 784 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName())
770 fs.unlink(thumbnailPath, callback) 785 fs.unlink(thumbnailPath, callback)
771} 786}
772 787
773function removeFile (video, callback) { 788function removeFile (video, callback) {
774 const filePath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename()) 789 const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename())
775 fs.unlink(filePath, callback) 790 fs.unlink(filePath, callback)
776} 791}
777 792
778function removeTorrent (video, callback) { 793function removeTorrent (video, callback) {
779 const torrenPath = pathUtils.join(constants.CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName()) 794 const torrenPath = join(CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName())
780 fs.unlink(torrenPath, callback) 795 fs.unlink(torrenPath, callback)
781} 796}
782 797
783function removePreview (video, callback) { 798function removePreview (video, callback) {
784 // Same name than video thumnail 799 // Same name than video thumnail
785 fs.unlink(constants.CONFIG.STORAGE.PREVIEWS_DIR + video.getPreviewName(), callback) 800 fs.unlink(CONFIG.STORAGE.PREVIEWS_DIR + video.getPreviewName(), callback)
786} 801}
787 802
788function createTorrentFromVideo (video, videoPath, callback) { 803function createTorrentFromVideo (video, videoPath, callback) {
789 const options = { 804 const options = {
790 announceList: [ 805 announceList: [
791 [ constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT + '/tracker/socket' ] 806 [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ]
792 ], 807 ],
793 urlList: [ 808 urlList: [
794 constants.CONFIG.WEBSERVER.URL + constants.STATIC_PATHS.WEBSEED + video.getVideoFilename() 809 CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + video.getVideoFilename()
795 ] 810 ]
796 } 811 }
797 812
798 createTorrent(videoPath, options, function (err, torrent) { 813 createTorrent(videoPath, options, function (err, torrent) {
799 if (err) return callback(err) 814 if (err) return callback(err)
800 815
801 const filePath = pathUtils.join(constants.CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName()) 816 const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName())
802 fs.writeFile(filePath, torrent, function (err) { 817 fs.writeFile(filePath, torrent, function (err) {
803 if (err) return callback(err) 818 if (err) return callback(err)
804 819
@@ -810,15 +825,15 @@ function createTorrentFromVideo (video, videoPath, callback) {
810} 825}
811 826
812function createPreview (video, videoPath, callback) { 827function createPreview (video, videoPath, callback) {
813 generateImage(video, videoPath, constants.CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName(), callback) 828 generateImage(video, videoPath, CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName(), callback)
814} 829}
815 830
816function createThumbnail (video, videoPath, callback) { 831function createThumbnail (video, videoPath, callback) {
817 generateImage(video, videoPath, constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), constants.THUMBNAILS_SIZE, callback) 832 generateImage(video, videoPath, CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), THUMBNAILS_SIZE, callback)
818} 833}
819 834
820function generateImage (video, videoPath, folder, imageName, size, callback) { 835function generateImage (video, videoPath, folder, imageName, size, callback?) {
821 const options = { 836 const options: any = {
822 filename: imageName, 837 filename: imageName,
823 count: 1, 838 count: 1,
824 folder 839 folder