aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/application-interface.ts7
-rw-r--r--server/models/application.ts13
-rw-r--r--server/models/author-interface.ts8
-rw-r--r--server/models/author.ts15
-rw-r--r--server/models/job-interface.ts3
-rw-r--r--server/models/job.ts2
-rw-r--r--server/models/oauth-client-interface.ts8
-rw-r--r--server/models/oauth-client.ts6
-rw-r--r--server/models/oauth-token-interface.ts20
-rw-r--r--server/models/oauth-token.ts13
-rw-r--r--server/models/pod-interface.ts41
-rw-r--r--server/models/pod.ts34
-rw-r--r--server/models/request-interface.ts27
-rw-r--r--server/models/request-to-pod-interface.ts5
-rw-r--r--server/models/request-to-pod.ts2
-rw-r--r--server/models/request-video-event-interface.ts32
-rw-r--r--server/models/request-video-event.ts19
-rw-r--r--server/models/request-video-qadu-interface.ts31
-rw-r--r--server/models/request-video-qadu.ts17
-rw-r--r--server/models/request.ts22
-rw-r--r--server/models/tag-interface.ts3
-rw-r--r--server/models/tag.ts9
-rw-r--r--server/models/user-interface.ts36
-rw-r--r--server/models/user-video-rate-interface.ts3
-rw-r--r--server/models/user-video-rate.ts2
-rw-r--r--server/models/user.ts18
-rw-r--r--server/models/utils.ts6
-rw-r--r--server/models/video-abuse-interface.ts10
-rw-r--r--server/models/video-blacklist-interface.ts24
-rw-r--r--server/models/video-blacklist.ts10
-rw-r--r--server/models/video-interface.ts118
-rw-r--r--server/models/video-tag-interface.ts2
-rw-r--r--server/models/video.ts79
33 files changed, 429 insertions, 216 deletions
diff --git a/server/models/application-interface.ts b/server/models/application-interface.ts
index 826d25df0..c03513db1 100644
--- a/server/models/application-interface.ts
+++ b/server/models/application-interface.ts
@@ -1,8 +1,11 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3export namespace ApplicationMethods { 3export namespace ApplicationMethods {
4 export type LoadMigrationVersion = (callback: (err: Error, version: number) => void) => void 4 export type LoadMigrationVersionCallback = (err: Error, version: number) => void
5 export type UpdateMigrationVersion = (newVersion: number, transaction: any, callback: any) => void 5 export type LoadMigrationVersion = (callback: LoadMigrationVersionCallback) => void
6
7 export type UpdateMigrationVersionCallback = (err: Error, applicationInstance: ApplicationAttributes) => void
8 export type UpdateMigrationVersion = (newVersion: number, transaction: Sequelize.Transaction, callback: UpdateMigrationVersionCallback) => void
6} 9}
7 10
8export interface ApplicationClass { 11export interface ApplicationClass {
diff --git a/server/models/application.ts b/server/models/application.ts
index acd0dfbf2..14b87777a 100644
--- a/server/models/application.ts
+++ b/server/models/application.ts
@@ -35,7 +35,7 @@ export default function defineApplication (sequelize: Sequelize.Sequelize, DataT
35 35
36// --------------------------------------------------------------------------- 36// ---------------------------------------------------------------------------
37 37
38loadMigrationVersion = function (callback: (err: Error, version: number) => void) { 38loadMigrationVersion = function (callback: ApplicationMethods.LoadMigrationVersionCallback) {
39 const query = { 39 const query = {
40 attributes: [ 'migrationVersion' ] 40 attributes: [ 'migrationVersion' ]
41 } 41 }
@@ -47,15 +47,10 @@ loadMigrationVersion = function (callback: (err: Error, version: number) => void
47 }) 47 })
48} 48}
49 49
50updateMigrationVersion = function (newVersion: number, transaction: any, callback: any) { 50updateMigrationVersion = function (newVersion: number, transaction: Sequelize.Transaction, callback: ApplicationMethods.UpdateMigrationVersionCallback) {
51 const options: Sequelize.UpdateOptions = { 51 const options: Sequelize.UpdateOptions = {
52 where: {} 52 where: {},
53 } 53 transaction: transaction
54
55 if (!callback) {
56 transaction = callback
57 } else {
58 options.transaction = transaction
59 } 54 }
60 55
61 return Application.update({ migrationVersion: newVersion }, options).asCallback(callback) 56 return Application.update({ migrationVersion: newVersion }, options).asCallback(callback)
diff --git a/server/models/author-interface.ts b/server/models/author-interface.ts
index d2475c3bd..b57ce2a6b 100644
--- a/server/models/author-interface.ts
+++ b/server/models/author-interface.ts
@@ -1,7 +1,10 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3import { PodInstance } from './pod-interface'
4
3export namespace AuthorMethods { 5export namespace AuthorMethods {
4 export type FindOrCreateAuthor = (name, podId, userId, transaction, callback) => void 6 export type FindOrCreateAuthorCallback = (err: Error, authorInstance?: AuthorInstance) => void
7 export type FindOrCreateAuthor = (name: string, podId: number, userId: number, transaction: Sequelize.Transaction, callback: FindOrCreateAuthorCallback) => void
5} 8}
6 9
7export interface AuthorClass { 10export interface AuthorClass {
@@ -16,6 +19,9 @@ export interface AuthorInstance extends AuthorClass, AuthorAttributes, Sequelize
16 id: number 19 id: number
17 createdAt: Date 20 createdAt: Date
18 updatedAt: Date 21 updatedAt: Date
22
23 podId: number
24 Pod: PodInstance
19} 25}
20 26
21export interface AuthorModel extends AuthorClass, Sequelize.Model<AuthorInstance, AuthorAttributes> {} 27export interface AuthorModel extends AuthorClass, Sequelize.Model<AuthorInstance, AuthorAttributes> {}
diff --git a/server/models/author.ts b/server/models/author.ts
index b543d17a0..3264d3a88 100644
--- a/server/models/author.ts
+++ b/server/models/author.ts
@@ -74,12 +74,13 @@ function associate (models) {
74 }) 74 })
75} 75}
76 76
77findOrCreateAuthor = function (name, podId, userId, transaction, callback) { 77findOrCreateAuthor = function (
78 if (!callback) { 78 name: string,
79 callback = transaction 79 podId: number,
80 transaction = null 80 userId: number,
81 } 81 transaction: Sequelize.Transaction,
82 82 callback: AuthorMethods.FindOrCreateAuthorCallback
83) {
83 const author = { 84 const author = {
84 name, 85 name,
85 podId, 86 podId,
@@ -91,7 +92,7 @@ findOrCreateAuthor = function (name, podId, userId, transaction, callback) {
91 defaults: author 92 defaults: author
92 } 93 }
93 94
94 if (transaction) query.transaction = transaction 95 if (transaction !== null) query.transaction = transaction
95 96
96 Author.findOrCreate(query).asCallback(function (err, result) { 97 Author.findOrCreate(query).asCallback(function (err, result) {
97 if (err) return callback(err) 98 if (err) return callback(err)
diff --git a/server/models/job-interface.ts b/server/models/job-interface.ts
index ad4e2d2b0..ab6678257 100644
--- a/server/models/job-interface.ts
+++ b/server/models/job-interface.ts
@@ -1,7 +1,8 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3export namespace JobMethods { 3export namespace JobMethods {
4 export type ListWithLimit = (limit, state, callback) => void 4 export type ListWithLimitCallback = (err: Error, jobInstances: JobInstance[]) => void
5 export type ListWithLimit = (limit: number, state: string, callback: ListWithLimitCallback) => void
5} 6}
6 7
7export interface JobClass { 8export interface JobClass {
diff --git a/server/models/job.ts b/server/models/job.ts
index 982b51499..1afae8f08 100644
--- a/server/models/job.ts
+++ b/server/models/job.ts
@@ -48,7 +48,7 @@ export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes) {
48 48
49// --------------------------------------------------------------------------- 49// ---------------------------------------------------------------------------
50 50
51listWithLimit = function (limit, state, callback) { 51listWithLimit = function (limit: number, state: string, callback: JobMethods.ListWithLimitCallback) {
52 const query = { 52 const query = {
53 order: [ 53 order: [
54 [ 'id', 'ASC' ] 54 [ 'id', 'ASC' ]
diff --git a/server/models/oauth-client-interface.ts b/server/models/oauth-client-interface.ts
index 4efd6212a..3b4325740 100644
--- a/server/models/oauth-client-interface.ts
+++ b/server/models/oauth-client-interface.ts
@@ -1,8 +1,12 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3export namespace OAuthClientMethods { 3export namespace OAuthClientMethods {
4 export type CountTotal = (callback) => void 4 export type CountTotalCallback = (err: Error, total: number) => void
5 export type LoadFirstClient = (callback) => void 5 export type CountTotal = (callback: CountTotalCallback) => void
6
7 export type LoadFirstClientCallback = (err: Error, client: OAuthClientInstance) => void
8 export type LoadFirstClient = (callback: LoadFirstClientCallback) => void
9
6 export type GetByIdAndSecret = (clientId, clientSecret) => void 10 export type GetByIdAndSecret = (clientId, clientSecret) => void
7} 11}
8 12
diff --git a/server/models/oauth-client.ts b/server/models/oauth-client.ts
index 2cefb5cb9..22fae2842 100644
--- a/server/models/oauth-client.ts
+++ b/server/models/oauth-client.ts
@@ -67,15 +67,15 @@ function associate (models) {
67 }) 67 })
68} 68}
69 69
70countTotal = function (callback) { 70countTotal = function (callback: OAuthClientMethods.CountTotalCallback) {
71 return OAuthClient.count().asCallback(callback) 71 return OAuthClient.count().asCallback(callback)
72} 72}
73 73
74loadFirstClient = function (callback) { 74loadFirstClient = function (callback: OAuthClientMethods.LoadFirstClientCallback) {
75 return OAuthClient.findOne().asCallback(callback) 75 return OAuthClient.findOne().asCallback(callback)
76} 76}
77 77
78getByIdAndSecret = function (clientId, clientSecret) { 78getByIdAndSecret = function (clientId: string, clientSecret: string) {
79 const query = { 79 const query = {
80 where: { 80 where: {
81 clientId: clientId, 81 clientId: clientId,
diff --git a/server/models/oauth-token-interface.ts b/server/models/oauth-token-interface.ts
index a0cd1ffe7..88526697e 100644
--- a/server/models/oauth-token-interface.ts
+++ b/server/models/oauth-token-interface.ts
@@ -1,11 +1,25 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import * as Bluebird from 'bluebird'
2 3
3import { UserModel } from './user-interface' 4import { UserModel } from './user-interface'
4 5
6export type OAuthTokenInfo = {
7 refreshToken: string
8 refreshTokenExpiresAt: Date,
9 client: {
10 id: number
11 },
12 user: {
13 id: number
14 }
15}
16
5export namespace OAuthTokenMethods { 17export namespace OAuthTokenMethods {
6 export type GetByRefreshTokenAndPopulateClient = (refreshToken) => void 18 export type GetByRefreshTokenAndPopulateClient = (refreshToken: string) => Bluebird<OAuthTokenInfo>
7 export type GetByTokenAndPopulateUser = (bearerToken) => void 19 export type GetByTokenAndPopulateUser = (bearerToken: string) => Bluebird<OAuthTokenInstance>
8 export type GetByRefreshTokenAndPopulateUser = (refreshToken) => any 20 export type GetByRefreshTokenAndPopulateUser = (refreshToken: string) => Bluebird<OAuthTokenInstance>
21
22 export type RemoveByUserIdCallback = (err: Error) => void
9 export type RemoveByUserId = (userId, callback) => void 23 export type RemoveByUserId = (userId, callback) => void
10} 24}
11 25
diff --git a/server/models/oauth-token.ts b/server/models/oauth-token.ts
index 567df1c12..d70bd2bce 100644
--- a/server/models/oauth-token.ts
+++ b/server/models/oauth-token.ts
@@ -8,7 +8,8 @@ import {
8 OAuthTokenInstance, 8 OAuthTokenInstance,
9 OAuthTokenAttributes, 9 OAuthTokenAttributes,
10 10
11 OAuthTokenMethods 11 OAuthTokenMethods,
12 OAuthTokenInfo
12} from './oauth-token-interface' 13} from './oauth-token-interface'
13 14
14let OAuthToken: Sequelize.Model<OAuthTokenInstance, OAuthTokenAttributes> 15let OAuthToken: Sequelize.Model<OAuthTokenInstance, OAuthTokenAttributes>
@@ -90,7 +91,7 @@ function associate (models) {
90 }) 91 })
91} 92}
92 93
93getByRefreshTokenAndPopulateClient = function (refreshToken) { 94getByRefreshTokenAndPopulateClient = function (refreshToken: string) {
94 const query = { 95 const query = {
95 where: { 96 where: {
96 refreshToken: refreshToken 97 refreshToken: refreshToken
@@ -99,9 +100,9 @@ getByRefreshTokenAndPopulateClient = function (refreshToken) {
99 } 100 }
100 101
101 return OAuthToken.findOne(query).then(function (token) { 102 return OAuthToken.findOne(query).then(function (token) {
102 if (!token) return token 103 if (!token) return null
103 104
104 const tokenInfos = { 105 const tokenInfos: OAuthTokenInfo = {
105 refreshToken: token.refreshToken, 106 refreshToken: token.refreshToken,
106 refreshTokenExpiresAt: token.refreshTokenExpiresAt, 107 refreshTokenExpiresAt: token.refreshTokenExpiresAt,
107 client: { 108 client: {
@@ -118,7 +119,7 @@ getByRefreshTokenAndPopulateClient = function (refreshToken) {
118 }) 119 })
119} 120}
120 121
121getByTokenAndPopulateUser = function (bearerToken) { 122getByTokenAndPopulateUser = function (bearerToken: string) {
122 const query = { 123 const query = {
123 where: { 124 where: {
124 accessToken: bearerToken 125 accessToken: bearerToken
@@ -133,7 +134,7 @@ getByTokenAndPopulateUser = function (bearerToken) {
133 }) 134 })
134} 135}
135 136
136getByRefreshTokenAndPopulateUser = function (refreshToken) { 137getByRefreshTokenAndPopulateUser = function (refreshToken: string) {
137 const query = { 138 const query = {
138 where: { 139 where: {
139 refreshToken: refreshToken 140 refreshToken: refreshToken
diff --git a/server/models/pod-interface.ts b/server/models/pod-interface.ts
index 14c88bec6..8f362bd5c 100644
--- a/server/models/pod-interface.ts
+++ b/server/models/pod-interface.ts
@@ -1,18 +1,39 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3// Don't use barrel, import just what we need
4import { Pod as FormatedPod } from '../../shared/models/pod.model'
5
3export namespace PodMethods { 6export namespace PodMethods {
4 export type ToFormatedJSON = () => void 7 export type ToFormatedJSON = () => FormatedPod
5 8
9 export type CountAllCallback = (err: Error, total: number) => void
6 export type CountAll = (callback) => void 10 export type CountAll = (callback) => void
7 export type IncrementScores = (ids, value, callback) => void 11
8 export type List = (callback) => void 12 export type IncrementScoresCallback = (err: Error) => void
9 export type ListAllIds = (transaction, callback) => void 13 export type IncrementScores = (ids: number[], value: number, callback?: IncrementScoresCallback) => void
10 export type ListRandomPodIdsWithRequest = (limit, tableWithPods, tableWithPodsJoins, callback) => void 14
11 export type ListBadPods = (callback) => void 15 export type ListCallback = (err: Error, podInstances?: PodInstance[]) => void
12 export type Load = (id, callback) => void 16 export type List = (callback: ListCallback) => void
13 export type LoadByHost = (host, callback) => void 17
14 export type RemoveAll = (callback) => void 18 export type ListAllIdsCallback = (err: Error, ids?: number[]) => void
15 export type UpdatePodsScore = (goodPods, badPods) => void 19 export type ListAllIds = (transaction: Sequelize.Transaction, callback: ListAllIdsCallback) => void
20
21 export type ListRandomPodIdsWithRequestCallback = (err: Error, podInstanceIds?: number[]) => void
22 export type ListRandomPodIdsWithRequest = (limit: number, tableWithPods: string, tableWithPodsJoins: string, callback: ListRandomPodIdsWithRequestCallback) => void
23
24 export type ListBadPodsCallback = (err: Error, podInstances?: PodInstance[]) => void
25 export type ListBadPods = (callback: ListBadPodsCallback) => void
26
27 export type LoadCallback = (err: Error, podInstance: PodInstance) => void
28 export type Load = (id: number, callback: LoadCallback) => void
29
30 export type LoadByHostCallback = (err: Error, podInstance: PodInstance) => void
31 export type LoadByHost = (host: string, callback: LoadByHostCallback) => void
32
33 export type RemoveAllCallback = (err: Error) => void
34 export type RemoveAll = (callback: RemoveAllCallback) => void
35
36 export type UpdatePodsScore = (goodPods: number[], badPods: number[]) => void
16} 37}
17 38
18export interface PodClass { 39export interface PodClass {
diff --git a/server/models/pod.ts b/server/models/pod.ts
index 2df32e4a4..107744c43 100644
--- a/server/models/pod.ts
+++ b/server/models/pod.ts
@@ -118,11 +118,11 @@ function associate (models) {
118 }) 118 })
119} 119}
120 120
121countAll = function (callback) { 121countAll = function (callback: PodMethods.CountAllCallback) {
122 return Pod.count().asCallback(callback) 122 return Pod.count().asCallback(callback)
123} 123}
124 124
125incrementScores = function (ids, value, callback) { 125incrementScores = function (ids: number[], value: number, callback?: PodMethods.IncrementScoresCallback) {
126 if (!callback) callback = function () { /* empty */ } 126 if (!callback) callback = function () { /* empty */ }
127 127
128 const update = { 128 const update = {
@@ -142,35 +142,25 @@ incrementScores = function (ids, value, callback) {
142 return Pod.update(update, options).asCallback(callback) 142 return Pod.update(update, options).asCallback(callback)
143} 143}
144 144
145list = function (callback) { 145list = function (callback: PodMethods.ListCallback) {
146 return Pod.findAll().asCallback(callback) 146 return Pod.findAll().asCallback(callback)
147} 147}
148 148
149listAllIds = function (transaction, callback) { 149listAllIds = function (transaction: Sequelize.Transaction, callback: PodMethods.ListAllIdsCallback) {
150 if (!callback) {
151 callback = transaction
152 transaction = null
153 }
154
155 const query: any = { 150 const query: any = {
156 attributes: [ 'id' ] 151 attributes: [ 'id' ]
157 } 152 }
158 153
159 if (transaction) query.transaction = transaction 154 if (transaction !== null) query.transaction = transaction
160 155
161 return Pod.findAll(query).asCallback(function (err, pods) { 156 return Pod.findAll(query).asCallback(function (err: Error, pods) {
162 if (err) return callback(err) 157 if (err) return callback(err)
163 158
164 return callback(null, map(pods, 'id')) 159 return callback(null, map(pods, 'id'))
165 }) 160 })
166} 161}
167 162
168listRandomPodIdsWithRequest = function (limit, tableWithPods, tableWithPodsJoins, callback) { 163listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, tableWithPodsJoins: string, callback: PodMethods.ListRandomPodIdsWithRequestCallback) {
169 if (!callback) {
170 callback = tableWithPodsJoins
171 tableWithPodsJoins = ''
172 }
173
174 Pod.count().asCallback(function (err, count) { 164 Pod.count().asCallback(function (err, count) {
175 if (err) return callback(err) 165 if (err) return callback(err)
176 166
@@ -204,7 +194,7 @@ listRandomPodIdsWithRequest = function (limit, tableWithPods, tableWithPodsJoins
204 }) 194 })
205} 195}
206 196
207listBadPods = function (callback) { 197listBadPods = function (callback: PodMethods.ListBadPodsCallback) {
208 const query = { 198 const query = {
209 where: { 199 where: {
210 score: { $lte: 0 } 200 score: { $lte: 0 }
@@ -214,11 +204,11 @@ listBadPods = function (callback) {
214 return Pod.findAll(query).asCallback(callback) 204 return Pod.findAll(query).asCallback(callback)
215} 205}
216 206
217load = function (id, callback) { 207load = function (id: number, callback: PodMethods.LoadCallback) {
218 return Pod.findById(id).asCallback(callback) 208 return Pod.findById(id).asCallback(callback)
219} 209}
220 210
221loadByHost = function (host, callback) { 211loadByHost = function (host: string, callback: PodMethods.LoadByHostCallback) {
222 const query = { 212 const query = {
223 where: { 213 where: {
224 host: host 214 host: host
@@ -228,11 +218,11 @@ loadByHost = function (host, callback) {
228 return Pod.findOne(query).asCallback(callback) 218 return Pod.findOne(query).asCallback(callback)
229} 219}
230 220
231removeAll = function (callback) { 221removeAll = function (callback: PodMethods.RemoveAllCallback) {
232 return Pod.destroy().asCallback(callback) 222 return Pod.destroy().asCallback(callback)
233} 223}
234 224
235updatePodsScore = function (goodPods, badPods) { 225updatePodsScore = function (goodPods: number[], badPods: number[]) {
236 logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length) 226 logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length)
237 227
238 if (goodPods.length !== 0) { 228 if (goodPods.length !== 0) {
diff --git a/server/models/request-interface.ts b/server/models/request-interface.ts
index 2bba8ce7f..4bbd79966 100644
--- a/server/models/request-interface.ts
+++ b/server/models/request-interface.ts
@@ -1,12 +1,26 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3import { PodAttributes } from './pod-interface' 3import { PodInstance, PodAttributes } from './pod-interface'
4
5export type RequestsGrouped = {
6 [ podId: number ]: {
7 request: RequestInstance,
8 pod: PodInstance
9 }[]
10}
4 11
5export namespace RequestMethods { 12export namespace RequestMethods {
6 export type CountTotalRequests = (callback) => void 13 export type CountTotalRequestsCallback = (err: Error, total: number) => void
7 export type ListWithLimitAndRandom = (limitPods, limitRequestsPerPod, callback) => void 14 export type CountTotalRequests = (callback: CountTotalRequestsCallback) => void
8 export type RemoveWithEmptyTo = (callback) => void 15
9 export type RemoveAll = (callback) => void 16 export type ListWithLimitAndRandomCallback = (err: Error, requestsGrouped?: RequestsGrouped) => void
17 export type ListWithLimitAndRandom = (limitPods, limitRequestsPerPod, callback: ListWithLimitAndRandomCallback) => void
18
19 export type RemoveWithEmptyToCallback = (err: Error) => void
20 export type RemoveWithEmptyTo = (callback: RemoveWithEmptyToCallback) => void
21
22 export type RemoveAllCallback = (err: Error) => void
23 export type RemoveAll = (callback: RemoveAllCallback) => void
10} 24}
11 25
12export interface RequestClass { 26export interface RequestClass {
@@ -21,12 +35,13 @@ export interface RequestAttributes {
21 endpoint: string 35 endpoint: string
22} 36}
23 37
24export interface RequestInstance extends Sequelize.Instance<RequestAttributes> { 38export interface RequestInstance extends RequestClass, RequestAttributes, Sequelize.Instance<RequestAttributes> {
25 id: number 39 id: number
26 createdAt: Date 40 createdAt: Date
27 updatedAt: Date 41 updatedAt: Date
28 42
29 setPods: Sequelize.HasManySetAssociationsMixin<PodAttributes, number> 43 setPods: Sequelize.HasManySetAssociationsMixin<PodAttributes, number>
44 Pods: PodInstance[]
30} 45}
31 46
32export interface RequestModel extends RequestClass, Sequelize.Model<RequestInstance, RequestAttributes> {} 47export interface RequestModel extends RequestClass, Sequelize.Model<RequestInstance, RequestAttributes> {}
diff --git a/server/models/request-to-pod-interface.ts b/server/models/request-to-pod-interface.ts
index 52116d6c4..6d75ca6e5 100644
--- a/server/models/request-to-pod-interface.ts
+++ b/server/models/request-to-pod-interface.ts
@@ -1,7 +1,8 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3export namespace RequestToPodMethods { 3export namespace RequestToPodMethods {
4 export type RemoveByRequestIdsAndPod = (requestsIds, podId, callback) => void 4 export type RemoveByRequestIdsAndPodCallback = (err: Error) => void
5 export type RemoveByRequestIdsAndPod = (requestsIds: number[], podId: number, callback?: RemoveByRequestIdsAndPodCallback) => void
5} 6}
6 7
7export interface RequestToPodClass { 8export interface RequestToPodClass {
@@ -11,7 +12,7 @@ export interface RequestToPodClass {
11export interface RequestToPodAttributes { 12export interface RequestToPodAttributes {
12} 13}
13 14
14export interface RequestToPodInstance extends Sequelize.Instance<RequestToPodAttributes> { 15export interface RequestToPodInstance extends RequestToPodClass, RequestToPodAttributes, Sequelize.Instance<RequestToPodAttributes> {
15 id: number 16 id: number
16 createdAt: Date 17 createdAt: Date
17 updatedAt: Date 18 updatedAt: Date
diff --git a/server/models/request-to-pod.ts b/server/models/request-to-pod.ts
index 681f808b7..3562069cc 100644
--- a/server/models/request-to-pod.ts
+++ b/server/models/request-to-pod.ts
@@ -38,7 +38,7 @@ export default function (sequelize, DataTypes) {
38 38
39// --------------------------------------------------------------------------- 39// ---------------------------------------------------------------------------
40 40
41removeByRequestIdsAndPod = function (requestsIds, podId, callback) { 41removeByRequestIdsAndPod = function (requestsIds: number[], podId: number, callback?: RequestToPodMethods.RemoveByRequestIdsAndPodCallback) {
42 if (!callback) callback = function () { /* empty */ } 42 if (!callback) callback = function () { /* empty */ }
43 43
44 const query = { 44 const query = {
diff --git a/server/models/request-video-event-interface.ts b/server/models/request-video-event-interface.ts
index a31c7108f..ad576a2b1 100644
--- a/server/models/request-video-event-interface.ts
+++ b/server/models/request-video-event-interface.ts
@@ -1,10 +1,30 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3import { VideoInstance } from './video-interface'
4import { PodInstance } from './pod-interface'
5
6export type RequestsVideoEventGrouped = {
7 [ podId: number ]: {
8 id: number
9 type: string
10 count: number
11 video: VideoInstance
12 pod: PodInstance
13 }[]
14}
15
3export namespace RequestVideoEventMethods { 16export namespace RequestVideoEventMethods {
4 export type CountTotalRequests = (callback) => void 17 export type CountTotalRequestsCallback = (err: Error, total: number) => void
5 export type ListWithLimitAndRandom = (limitPods, limitRequestsPerPod, callback) => void 18 export type CountTotalRequests = (callback: CountTotalRequestsCallback) => void
6 export type RemoveByRequestIdsAndPod = (ids, podId, callback) => void 19
7 export type RemoveAll = (callback) => void 20 export type ListWithLimitAndRandomCallback = (err: Error, requestsGrouped?: RequestsVideoEventGrouped) => void
21 export type ListWithLimitAndRandom = (limitPods: number, limitRequestsPerPod: number, callback: ListWithLimitAndRandomCallback) => void
22
23 export type RemoveByRequestIdsAndPodCallback = () => void
24 export type RemoveByRequestIdsAndPod = (ids: number[], podId: number, callback: RemoveByRequestIdsAndPodCallback) => void
25
26 export type RemoveAllCallback = () => void
27 export type RemoveAll = (callback: RemoveAllCallback) => void
8} 28}
9 29
10export interface RequestVideoEventClass { 30export interface RequestVideoEventClass {
@@ -19,8 +39,10 @@ export interface RequestVideoEventAttributes {
19 count: number 39 count: number
20} 40}
21 41
22export interface RequestVideoEventInstance extends Sequelize.Instance<RequestVideoEventAttributes> { 42export interface RequestVideoEventInstance extends RequestVideoEventClass, RequestVideoEventAttributes, Sequelize.Instance<RequestVideoEventAttributes> {
23 id: number 43 id: number
44
45 Video: VideoInstance
24} 46}
25 47
26export interface RequestVideoEventModel extends RequestVideoEventClass, Sequelize.Model<RequestVideoEventInstance, RequestVideoEventAttributes> {} 48export interface RequestVideoEventModel extends RequestVideoEventClass, Sequelize.Model<RequestVideoEventInstance, RequestVideoEventAttributes> {}
diff --git a/server/models/request-video-event.ts b/server/models/request-video-event.ts
index 234e2a8a9..e422649af 100644
--- a/server/models/request-video-event.ts
+++ b/server/models/request-video-event.ts
@@ -5,16 +5,17 @@
5import { values } from 'lodash' 5import { values } from 'lodash'
6import * as Sequelize from 'sequelize' 6import * as Sequelize from 'sequelize'
7 7
8import { database as db } from '../initializers/database'
8import { REQUEST_VIDEO_EVENT_TYPES } from '../initializers' 9import { REQUEST_VIDEO_EVENT_TYPES } from '../initializers'
9import { isVideoEventCountValid } from '../helpers' 10import { isVideoEventCountValid } from '../helpers'
10
11import { addMethodsToModel } from './utils' 11import { addMethodsToModel } from './utils'
12import { 12import {
13 RequestVideoEventClass, 13 RequestVideoEventClass,
14 RequestVideoEventInstance, 14 RequestVideoEventInstance,
15 RequestVideoEventAttributes, 15 RequestVideoEventAttributes,
16 16
17 RequestVideoEventMethods 17 RequestVideoEventMethods,
18 RequestsVideoEventGrouped
18} from './request-video-event-interface' 19} from './request-video-event-interface'
19 20
20let RequestVideoEvent: Sequelize.Model<RequestVideoEventInstance, RequestVideoEventAttributes> 21let RequestVideoEvent: Sequelize.Model<RequestVideoEventInstance, RequestVideoEventAttributes>
@@ -76,13 +77,13 @@ function associate (models) {
76 }) 77 })
77} 78}
78 79
79countTotalRequests = function (callback) { 80countTotalRequests = function (callback: RequestVideoEventMethods.CountTotalRequestsCallback) {
80 const query = {} 81 const query = {}
81 return RequestVideoEvent.count(query).asCallback(callback) 82 return RequestVideoEvent.count(query).asCallback(callback)
82} 83}
83 84
84listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) { 85listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: number, callback: RequestVideoEventMethods.ListWithLimitAndRandomCallback) {
85 const Pod = RequestVideoEvent['sequelize'].models.Pod 86 const Pod = db.Pod
86 87
87 // We make a join between videos and authors to find the podId of our video event requests 88 // We make a join between videos and authors to find the podId of our video event requests
88 const podJoins = 'INNER JOIN "Videos" ON "Videos"."authorId" = "Authors"."id" ' + 89 const podJoins = 'INNER JOIN "Videos" ON "Videos"."authorId" = "Authors"."id" ' +
@@ -129,7 +130,7 @@ listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) {
129 }) 130 })
130} 131}
131 132
132removeByRequestIdsAndPod = function (ids, podId, callback) { 133removeByRequestIdsAndPod = function (ids: number[], podId: number, callback: RequestVideoEventMethods.RemoveByRequestIdsAndPodCallback) {
133 const query = { 134 const query = {
134 where: { 135 where: {
135 id: { 136 id: {
@@ -154,15 +155,15 @@ removeByRequestIdsAndPod = function (ids, podId, callback) {
154 RequestVideoEvent.destroy(query).asCallback(callback) 155 RequestVideoEvent.destroy(query).asCallback(callback)
155} 156}
156 157
157removeAll = function (callback) { 158removeAll = function (callback: RequestVideoEventMethods.RemoveAllCallback) {
158 // Delete all requests 159 // Delete all requests
159 RequestVideoEvent.truncate({ cascade: true }).asCallback(callback) 160 RequestVideoEvent.truncate({ cascade: true }).asCallback(callback)
160} 161}
161 162
162// --------------------------------------------------------------------------- 163// ---------------------------------------------------------------------------
163 164
164function groupAndTruncateRequests (events, limitRequestsPerPod) { 165function groupAndTruncateRequests (events: RequestVideoEventInstance[], limitRequestsPerPod: number) {
165 const eventsGrouped = {} 166 const eventsGrouped: RequestsVideoEventGrouped = {}
166 167
167 events.forEach(function (event) { 168 events.forEach(function (event) {
168 const pod = event.Video.Author.Pod 169 const pod = event.Video.Author.Pod
diff --git a/server/models/request-video-qadu-interface.ts b/server/models/request-video-qadu-interface.ts
index 6fe34ee91..04de7f159 100644
--- a/server/models/request-video-qadu-interface.ts
+++ b/server/models/request-video-qadu-interface.ts
@@ -1,10 +1,28 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3import { VideoInstance } from './video-interface'
4import { PodInstance } from './pod-interface'
5
6export type RequestsVideoQaduGrouped = {
7 [ podId: number ]: {
8 request: RequestVideoQaduInstance
9 video: VideoInstance
10 pod: PodInstance
11 }
12}
13
3export namespace RequestVideoQaduMethods { 14export namespace RequestVideoQaduMethods {
4 export type CountTotalRequests = (callback) => void 15 export type CountTotalRequestsCallback = (err: Error, total: number) => void
5 export type ListWithLimitAndRandom = (limitPods, limitRequestsPerPod, callback) => void 16 export type CountTotalRequests = (callback: CountTotalRequestsCallback) => void
6 export type RemoveByRequestIdsAndPod = (ids, podId, callback) => void 17
7 export type RemoveAll = (callback) => void 18 export type ListWithLimitAndRandomCallback = (err: Error, requestsGrouped?: RequestsVideoQaduGrouped) => void
19 export type ListWithLimitAndRandom = (limitPods: number, limitRequestsPerPod: number, callback: ListWithLimitAndRandomCallback) => void
20
21 export type RemoveByRequestIdsAndPodCallback = () => void
22 export type RemoveByRequestIdsAndPod = (ids: number[], podId: number, callback: RemoveByRequestIdsAndPodCallback) => void
23
24 export type RemoveAllCallback = () => void
25 export type RemoveAll = (callback: RemoveAllCallback) => void
8} 26}
9 27
10export interface RequestVideoQaduClass { 28export interface RequestVideoQaduClass {
@@ -18,8 +36,11 @@ export interface RequestVideoQaduAttributes {
18 type: string 36 type: string
19} 37}
20 38
21export interface RequestVideoQaduInstance extends Sequelize.Instance<RequestVideoQaduAttributes> { 39export interface RequestVideoQaduInstance extends RequestVideoQaduClass, RequestVideoQaduAttributes, Sequelize.Instance<RequestVideoQaduAttributes> {
22 id: number 40 id: number
41
42 Pod: PodInstance
43 Video: VideoInstance
23} 44}
24 45
25export interface RequestVideoQaduModel extends RequestVideoQaduClass, Sequelize.Model<RequestVideoQaduInstance, RequestVideoQaduAttributes> {} 46export interface RequestVideoQaduModel extends RequestVideoQaduClass, Sequelize.Model<RequestVideoQaduInstance, RequestVideoQaduAttributes> {}
diff --git a/server/models/request-video-qadu.ts b/server/models/request-video-qadu.ts
index e914e06cd..38627ad55 100644
--- a/server/models/request-video-qadu.ts
+++ b/server/models/request-video-qadu.ts
@@ -12,8 +12,8 @@
12import { values } from 'lodash' 12import { values } from 'lodash'
13import * as Sequelize from 'sequelize' 13import * as Sequelize from 'sequelize'
14 14
15import { database as db } from '../initializers/database'
15import { REQUEST_VIDEO_QADU_TYPES } from '../initializers' 16import { REQUEST_VIDEO_QADU_TYPES } from '../initializers'
16
17import { addMethodsToModel } from './utils' 17import { addMethodsToModel } from './utils'
18import { 18import {
19 RequestVideoQaduClass, 19 RequestVideoQaduClass,
@@ -83,15 +83,16 @@ function associate (models) {
83 }) 83 })
84} 84}
85 85
86countTotalRequests = function (callback) { 86countTotalRequests = function (callback: RequestVideoQaduMethods.CountTotalRequestsCallback) {
87 const query = {} 87 const query = {}
88 return RequestVideoQadu.count(query).asCallback(callback) 88 return RequestVideoQadu.count(query).asCallback(callback)
89} 89}
90 90
91listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) { 91listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: number, callback: RequestVideoQaduMethods.ListWithLimitAndRandomCallback) {
92 const Pod = RequestVideoQadu['sequelize'].models.Pod 92 const Pod = db.Pod
93 const tableJoin = ''
93 94
94 Pod.listRandomPodIdsWithRequest(limitPods, 'RequestVideoQadus', function (err, podIds) { 95 Pod.listRandomPodIdsWithRequest(limitPods, 'RequestVideoQadus', tableJoin, function (err, podIds) {
95 if (err) return callback(err) 96 if (err) return callback(err)
96 97
97 // We don't have friends that have requests 98 // We don't have friends that have requests
@@ -122,7 +123,7 @@ listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) {
122 }) 123 })
123} 124}
124 125
125removeByRequestIdsAndPod = function (ids, podId, callback) { 126removeByRequestIdsAndPod = function (ids: number[], podId: number, callback: RequestVideoQaduMethods.RemoveByRequestIdsAndPodCallback) {
126 const query = { 127 const query = {
127 where: { 128 where: {
128 id: { 129 id: {
@@ -135,14 +136,14 @@ removeByRequestIdsAndPod = function (ids, podId, callback) {
135 RequestVideoQadu.destroy(query).asCallback(callback) 136 RequestVideoQadu.destroy(query).asCallback(callback)
136} 137}
137 138
138removeAll = function (callback) { 139removeAll = function (callback: RequestVideoQaduMethods.RemoveAllCallback) {
139 // Delete all requests 140 // Delete all requests
140 RequestVideoQadu.truncate({ cascade: true }).asCallback(callback) 141 RequestVideoQadu.truncate({ cascade: true }).asCallback(callback)
141} 142}
142 143
143// --------------------------------------------------------------------------- 144// ---------------------------------------------------------------------------
144 145
145function groupAndTruncateRequests (requests, limitRequestsPerPod) { 146function groupAndTruncateRequests (requests: RequestVideoQaduInstance[], limitRequestsPerPod: number) {
146 const requestsGrouped = {} 147 const requestsGrouped = {}
147 148
148 requests.forEach(function (request) { 149 requests.forEach(function (request) {
diff --git a/server/models/request.ts b/server/models/request.ts
index 18fa291fa..71f81ae66 100644
--- a/server/models/request.ts
+++ b/server/models/request.ts
@@ -1,15 +1,16 @@
1import { values } from 'lodash' 1import { values } from 'lodash'
2import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
3 3
4import { database as db } from '../initializers/database'
4import { REQUEST_ENDPOINTS } from '../initializers' 5import { REQUEST_ENDPOINTS } from '../initializers'
5
6import { addMethodsToModel } from './utils' 6import { addMethodsToModel } from './utils'
7import { 7import {
8 RequestClass, 8 RequestClass,
9 RequestInstance, 9 RequestInstance,
10 RequestAttributes, 10 RequestAttributes,
11 11
12 RequestMethods 12 RequestMethods,
13 RequestsGrouped
13} from './request-interface' 14} from './request-interface'
14 15
15let Request: Sequelize.Model<RequestInstance, RequestAttributes> 16let Request: Sequelize.Model<RequestInstance, RequestAttributes>
@@ -59,7 +60,7 @@ function associate (models) {
59 }) 60 })
60} 61}
61 62
62countTotalRequests = function (callback) { 63countTotalRequests = function (callback: RequestMethods.CountTotalRequestsCallback) {
63 // We need to include Pod because there are no cascade delete when a pod is removed 64 // We need to include Pod because there are no cascade delete when a pod is removed
64 // So we could count requests that do not have existing pod anymore 65 // So we could count requests that do not have existing pod anymore
65 const query = { 66 const query = {
@@ -69,10 +70,11 @@ countTotalRequests = function (callback) {
69 return Request.count(query).asCallback(callback) 70 return Request.count(query).asCallback(callback)
70} 71}
71 72
72listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) { 73listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: number, callback: RequestMethods.ListWithLimitAndRandomCallback) {
73 const Pod = Request['sequelize'].models.Pod 74 const Pod = db.Pod
75 const tableJoin = ''
74 76
75 Pod.listRandomPodIdsWithRequest(limitPods, 'RequestToPods', function (err, podIds) { 77 Pod.listRandomPodIdsWithRequest(limitPods, 'RequestToPods', '', function (err, podIds) {
76 if (err) return callback(err) 78 if (err) return callback(err)
77 79
78 // We don't have friends that have requests 80 // We don't have friends that have requests
@@ -105,12 +107,12 @@ listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) {
105 }) 107 })
106} 108}
107 109
108removeAll = function (callback) { 110removeAll = function (callback: RequestMethods.RemoveAllCallback) {
109 // Delete all requests 111 // Delete all requests
110 Request.truncate({ cascade: true }).asCallback(callback) 112 Request.truncate({ cascade: true }).asCallback(callback)
111} 113}
112 114
113removeWithEmptyTo = function (callback) { 115removeWithEmptyTo = function (callback?: RequestMethods.RemoveWithEmptyToCallback) {
114 if (!callback) callback = function () { /* empty */ } 116 if (!callback) callback = function () { /* empty */ }
115 117
116 const query = { 118 const query = {
@@ -128,8 +130,8 @@ removeWithEmptyTo = function (callback) {
128 130
129// --------------------------------------------------------------------------- 131// ---------------------------------------------------------------------------
130 132
131function groupAndTruncateRequests (requests, limitRequestsPerPod) { 133function groupAndTruncateRequests (requests: RequestInstance[], limitRequestsPerPod: number) {
132 const requestsGrouped = {} 134 const requestsGrouped: RequestsGrouped = {}
133 135
134 requests.forEach(function (request) { 136 requests.forEach(function (request) {
135 request.Pods.forEach(function (pod) { 137 request.Pods.forEach(function (pod) {
diff --git a/server/models/tag-interface.ts b/server/models/tag-interface.ts
index f96e1e9c5..e045e7ca5 100644
--- a/server/models/tag-interface.ts
+++ b/server/models/tag-interface.ts
@@ -1,7 +1,8 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3export namespace TagMethods { 3export namespace TagMethods {
4 export type FindOrCreateTags = (tags, transaction, callback) => void 4 export type FindOrCreateTagsCallback = (err: Error, tagInstances: TagInstance[]) => void
5 export type FindOrCreateTags = (tags: string[], transaction: Sequelize.Transaction, callback: FindOrCreateTagsCallback) => void
5} 6}
6 7
7export interface TagClass { 8export interface TagClass {
diff --git a/server/models/tag.ts b/server/models/tag.ts
index b2a9c9f81..c4402e83c 100644
--- a/server/models/tag.ts
+++ b/server/models/tag.ts
@@ -52,15 +52,10 @@ function associate (models) {
52 }) 52 })
53} 53}
54 54
55findOrCreateTags = function (tags, transaction, callback) { 55findOrCreateTags = function (tags: string[], transaction: Sequelize.Transaction, callback: TagMethods.FindOrCreateTagsCallback) {
56 if (!callback) {
57 callback = transaction
58 transaction = null
59 }
60
61 const tagInstances = [] 56 const tagInstances = []
62 57
63 each(tags, function (tag, callbackEach) { 58 each<string, Error>(tags, function (tag, callbackEach) {
64 const query: any = { 59 const query: any = {
65 where: { 60 where: {
66 name: tag 61 name: tag
diff --git a/server/models/user-interface.ts b/server/models/user-interface.ts
index a504f42a1..98963b743 100644
--- a/server/models/user-interface.ts
+++ b/server/models/user-interface.ts
@@ -1,17 +1,35 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import * as Bluebird from 'bluebird'
3
4// Don't use barrel, import just what we need
5import { User as FormatedUser } from '../../shared/models/user.model'
2 6
3export namespace UserMethods { 7export namespace UserMethods {
4 export type IsPasswordMatch = (password, callback) => void 8 export type IsPasswordMatchCallback = (err: Error, same: boolean) => void
5 export type ToFormatedJSON = () => void 9 export type IsPasswordMatch = (password: string, callback: IsPasswordMatchCallback) => void
10
11 export type ToFormatedJSON = () => FormatedUser
6 export type IsAdmin = () => boolean 12 export type IsAdmin = () => boolean
7 13
8 export type CountTotal = (callback) => void 14 export type CountTotalCallback = (err: Error, total: number) => void
9 export type GetByUsername = (username) => any 15 export type CountTotal = (callback: CountTotalCallback) => void
10 export type List = (callback) => void 16
11 export type ListForApi = (start, count, sort, callback) => void 17 export type GetByUsername = (username: string) => Bluebird<UserInstance>
12 export type LoadById = (id, callback) => void 18
13 export type LoadByUsername = (username, callback) => void 19 export type ListCallback = (err: Error, userInstances: UserInstance[]) => void
14 export type LoadByUsernameOrEmail = (username, email, callback) => void 20 export type List = (callback: ListCallback) => void
21
22 export type ListForApiCallback = (err: Error, userInstances?: UserInstance[], total?: number) => void
23 export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void
24
25 export type LoadByIdCallback = (err: Error, userInstance: UserInstance) => void
26 export type LoadById = (id: number, callback: LoadByIdCallback) => void
27
28 export type LoadByUsernameCallback = (err: Error, userInstance: UserInstance) => void
29 export type LoadByUsername = (username: string, callback: LoadByUsernameCallback) => void
30
31 export type LoadByUsernameOrEmailCallback = (err: Error, userInstance: UserInstance) => void
32 export type LoadByUsernameOrEmail = (username: string, email: string, callback: LoadByUsernameOrEmailCallback) => void
15} 33}
16 34
17export interface UserClass { 35export interface UserClass {
diff --git a/server/models/user-video-rate-interface.ts b/server/models/user-video-rate-interface.ts
index 57d2e2b91..e48869fd2 100644
--- a/server/models/user-video-rate-interface.ts
+++ b/server/models/user-video-rate-interface.ts
@@ -1,6 +1,7 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3export namespace UserVideoRateMethods { 3export namespace UserVideoRateMethods {
4 export type LoadCallback = (err: Error, userVideoRateInstance: UserVideoRateInstance) => void
4 export type Load = (userId, videoId, transaction, callback) => void 5 export type Load = (userId, videoId, transaction, callback) => void
5} 6}
6 7
@@ -12,7 +13,7 @@ export interface UserVideoRateAttributes {
12 type: string 13 type: string
13} 14}
14 15
15export interface UserVideoRateInstance extends Sequelize.Instance<UserVideoRateAttributes> { 16export interface UserVideoRateInstance extends UserVideoRateClass, UserVideoRateAttributes, Sequelize.Instance<UserVideoRateAttributes> {
16 id: number 17 id: number
17 createdAt: Date 18 createdAt: Date
18 updatedAt: Date 19 updatedAt: Date
diff --git a/server/models/user-video-rate.ts b/server/models/user-video-rate.ts
index 87886d8d0..6b71e8412 100644
--- a/server/models/user-video-rate.ts
+++ b/server/models/user-video-rate.ts
@@ -67,7 +67,7 @@ function associate (models) {
67 }) 67 })
68} 68}
69 69
70load = function (userId, videoId, transaction, callback) { 70load = function (userId: number, videoId: number, transaction: Sequelize.Transaction, callback: UserVideoRateMethods.LoadCallback) {
71 const options: Sequelize.FindOptions = { 71 const options: Sequelize.FindOptions = {
72 where: { 72 where: {
73 userId, 73 userId,
diff --git a/server/models/user.ts b/server/models/user.ts
index 12ddaaeb7..0fbfdda50 100644
--- a/server/models/user.ts
+++ b/server/models/user.ts
@@ -117,7 +117,7 @@ export default function (sequelize, DataTypes) {
117 return User 117 return User
118} 118}
119 119
120function beforeCreateOrUpdate (user, options) { 120function beforeCreateOrUpdate (user: UserInstance) {
121 return new Promise(function (resolve, reject) { 121 return new Promise(function (resolve, reject) {
122 cryptPassword(user.password, function (err, hash) { 122 cryptPassword(user.password, function (err, hash) {
123 if (err) return reject(err) 123 if (err) return reject(err)
@@ -131,7 +131,7 @@ function beforeCreateOrUpdate (user, options) {
131 131
132// ------------------------------ METHODS ------------------------------ 132// ------------------------------ METHODS ------------------------------
133 133
134isPasswordMatch = function (password, callback) { 134isPasswordMatch = function (password: string, callback: UserMethods.IsPasswordMatchCallback) {
135 return comparePassword(password, this.password, callback) 135 return comparePassword(password, this.password, callback)
136} 136}
137 137
@@ -164,11 +164,11 @@ function associate (models) {
164 }) 164 })
165} 165}
166 166
167countTotal = function (callback) { 167countTotal = function (callback: UserMethods.CountTotalCallback) {
168 return this.count().asCallback(callback) 168 return this.count().asCallback(callback)
169} 169}
170 170
171getByUsername = function (username) { 171getByUsername = function (username: string) {
172 const query = { 172 const query = {
173 where: { 173 where: {
174 username: username 174 username: username
@@ -178,11 +178,11 @@ getByUsername = function (username) {
178 return User.findOne(query) 178 return User.findOne(query)
179} 179}
180 180
181list = function (callback) { 181list = function (callback: UserMethods.ListCallback) {
182 return User.find().asCallback(callback) 182 return User.find().asCallback(callback)
183} 183}
184 184
185listForApi = function (start, count, sort, callback) { 185listForApi = function (start: number, count: number, sort: string, callback: UserMethods.ListForApiCallback) {
186 const query = { 186 const query = {
187 offset: start, 187 offset: start,
188 limit: count, 188 limit: count,
@@ -196,11 +196,11 @@ listForApi = function (start, count, sort, callback) {
196 }) 196 })
197} 197}
198 198
199loadById = function (id, callback) { 199loadById = function (id: number, callback: UserMethods.LoadByIdCallback) {
200 return User.findById(id).asCallback(callback) 200 return User.findById(id).asCallback(callback)
201} 201}
202 202
203loadByUsername = function (username, callback) { 203loadByUsername = function (username: string, callback: UserMethods.LoadByUsernameCallback) {
204 const query = { 204 const query = {
205 where: { 205 where: {
206 username: username 206 username: username
@@ -210,7 +210,7 @@ loadByUsername = function (username, callback) {
210 return User.findOne(query).asCallback(callback) 210 return User.findOne(query).asCallback(callback)
211} 211}
212 212
213loadByUsernameOrEmail = function (username, email, callback) { 213loadByUsernameOrEmail = function (username: string, email: string, callback: UserMethods.LoadByUsernameOrEmailCallback) {
214 const query = { 214 const query = {
215 where: { 215 where: {
216 $or: [ { username }, { email } ] 216 $or: [ { username }, { email } ]
diff --git a/server/models/utils.ts b/server/models/utils.ts
index fd84a9239..7ba96815e 100644
--- a/server/models/utils.ts
+++ b/server/models/utils.ts
@@ -1,7 +1,7 @@
1// Translate for example "-name" to [ 'name', 'DESC' ] 1// Translate for example "-name" to [ 'name', 'DESC' ]
2function getSort (value) { 2function getSort (value: string) {
3 let field 3 let field: string
4 let direction 4 let direction: 'ASC' | 'DESC'
5 5
6 if (value.substring(0, 1) === '-') { 6 if (value.substring(0, 1) === '-') {
7 direction = 'DESC' 7 direction = 'DESC'
diff --git a/server/models/video-abuse-interface.ts b/server/models/video-abuse-interface.ts
index 9b77fc6f5..d9cb93b42 100644
--- a/server/models/video-abuse-interface.ts
+++ b/server/models/video-abuse-interface.ts
@@ -1,9 +1,13 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3// Don't use barrel, import just what we need
4import { VideoAbuse as FormatedVideoAbuse } from '../../shared/models/video-abuse.model'
5
3export namespace VideoAbuseMethods { 6export namespace VideoAbuseMethods {
4 export type toFormatedJSON = () => void 7 export type toFormatedJSON = () => FormatedVideoAbuse
5 8
6 export type ListForApi = (start, count, sort, callback) => void 9 export type ListForApiCallback = (err: Error, videoAbuseInstances?: VideoAbuseInstance[], total?: number) => void
10 export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void
7} 11}
8 12
9export interface VideoAbuseClass { 13export interface VideoAbuseClass {
@@ -15,7 +19,7 @@ export interface VideoAbuseAttributes {
15 reason: string 19 reason: string
16} 20}
17 21
18export interface VideoAbuseInstance extends Sequelize.Instance<VideoAbuseAttributes> { 22export interface VideoAbuseInstance extends VideoAbuseClass, VideoAbuseAttributes, Sequelize.Instance<VideoAbuseAttributes> {
19 id: number 23 id: number
20 createdAt: Date 24 createdAt: Date
21 updatedAt: Date 25 updatedAt: Date
diff --git a/server/models/video-blacklist-interface.ts b/server/models/video-blacklist-interface.ts
index ae2cd6748..974718192 100644
--- a/server/models/video-blacklist-interface.ts
+++ b/server/models/video-blacklist-interface.ts
@@ -1,13 +1,25 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3// Don't use barrel, import just what we need
4import { BlacklistedVideo as FormatedBlacklistedVideo } from '../../shared/models/video-blacklist.model'
5
3export namespace BlacklistedVideoMethods { 6export namespace BlacklistedVideoMethods {
4 export type ToFormatedJSON = () => void 7 export type ToFormatedJSON = () => FormatedBlacklistedVideo
8
9 export type CountTotalCallback = (err: Error, total: number) => void
10 export type CountTotal = (callback: CountTotalCallback) => void
11
12 export type ListCallback = (err: Error, backlistedVideoInstances: BlacklistedVideoInstance[]) => void
13 export type List = (callback: ListCallback) => void
14
15 export type ListForApiCallback = (err: Error, blacklistedVIdeoInstances?: BlacklistedVideoInstance[], total?: number) => void
16 export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void
17
18 export type LoadByIdCallback = (err: Error, blacklistedVideoInstance: BlacklistedVideoInstance) => void
19 export type LoadById = (id: number, callback: LoadByIdCallback) => void
5 20
6 export type CountTotal = (callback) => void 21 export type LoadByVideoIdCallback = (err: Error, blacklistedVideoInstance: BlacklistedVideoInstance) => void
7 export type List = (callback) => void 22 export type LoadByVideoId = (id: string, callback: LoadByVideoIdCallback) => void
8 export type ListForApi = (start, count, sort, callback) => void
9 export type LoadById = (id, callback) => void
10 export type LoadByVideoId = (id, callback) => void
11} 23}
12 24
13export interface BlacklistedVideoClass { 25export interface BlacklistedVideoClass {
diff --git a/server/models/video-blacklist.ts b/server/models/video-blacklist.ts
index fe72d5d46..f36756085 100644
--- a/server/models/video-blacklist.ts
+++ b/server/models/video-blacklist.ts
@@ -66,15 +66,15 @@ function associate (models) {
66 }) 66 })
67} 67}
68 68
69countTotal = function (callback) { 69countTotal = function (callback: BlacklistedVideoMethods.CountTotalCallback) {
70 return BlacklistedVideo.count().asCallback(callback) 70 return BlacklistedVideo.count().asCallback(callback)
71} 71}
72 72
73list = function (callback) { 73list = function (callback: BlacklistedVideoMethods.ListCallback) {
74 return BlacklistedVideo.findAll().asCallback(callback) 74 return BlacklistedVideo.findAll().asCallback(callback)
75} 75}
76 76
77listForApi = function (start, count, sort, callback) { 77listForApi = function (start: number, count: number, sort: string, callback: BlacklistedVideoMethods.ListForApiCallback) {
78 const query = { 78 const query = {
79 offset: start, 79 offset: start,
80 limit: count, 80 limit: count,
@@ -88,11 +88,11 @@ listForApi = function (start, count, sort, callback) {
88 }) 88 })
89} 89}
90 90
91loadById = function (id, callback) { 91loadById = function (id: number, callback: BlacklistedVideoMethods.LoadByIdCallback) {
92 return BlacklistedVideo.findById(id).asCallback(callback) 92 return BlacklistedVideo.findById(id).asCallback(callback)
93} 93}
94 94
95loadByVideoId = function (id, callback) { 95loadByVideoId = function (id: string, callback: BlacklistedVideoMethods.LoadByIdCallback) {
96 const query = { 96 const query = {
97 where: { 97 where: {
98 videoId: id 98 videoId: id
diff --git a/server/models/video-interface.ts b/server/models/video-interface.ts
index b8dbeea35..7005f213c 100644
--- a/server/models/video-interface.ts
+++ b/server/models/video-interface.ts
@@ -1,28 +1,101 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3import { AuthorInstance } from './author-interface'
4import { VideoTagInstance } from './video-tag-interface'
5
6// Don't use barrel, import just what we need
7import { Video as FormatedVideo } from '../../shared/models/video.model'
8
9export type FormatedAddRemoteVideo = {
10 name: string
11 category: number
12 licence: number
13 language: number
14 nsfw: boolean
15 description: string
16 infoHash: string
17 remoteId: string
18 author: string
19 duration: number
20 thumbnailData: string
21 tags: string[]
22 createdAt: Date
23 updatedAt: Date
24 extname: string
25 views: number
26 likes: number
27 dislikes: number
28}
29
30export type FormatedUpdateRemoteVideo = {
31 name: string
32 category: number
33 licence: number
34 language: number
35 nsfw: boolean
36 description: string
37 infoHash: string
38 remoteId: string
39 author: string
40 duration: number
41 tags: string[]
42 createdAt: Date
43 updatedAt: Date
44 extname: string
45 views: number
46 likes: number
47 dislikes: number
48}
49
3export namespace VideoMethods { 50export namespace VideoMethods {
4 export type GenerateMagnetUri = () => void 51 export type GenerateMagnetUri = () => string
5 export type GetVideoFilename = () => void 52 export type GetVideoFilename = () => string
6 export type GetThumbnailName = () => void 53 export type GetThumbnailName = () => string
7 export type GetPreviewName = () => void 54 export type GetPreviewName = () => string
8 export type GetTorrentName = () => void 55 export type GetTorrentName = () => string
9 export type IsOwned = () => void 56 export type IsOwned = () => boolean
10 export type ToFormatedJSON = () => void 57 export type ToFormatedJSON = () => FormatedVideo
11 export type ToAddRemoteJSON = (callback) => void 58
12 export type ToUpdateRemoteJSON = (callback) => void 59 export type ToAddRemoteJSONCallback = (err: Error, videoFormated?: FormatedAddRemoteVideo) => void
13 export type TranscodeVideofile = (callback) => void 60 export type ToAddRemoteJSON = (callback: ToAddRemoteJSONCallback) => void
14 61
15 export type GenerateThumbnailFromData = (video, thumbnailData, callback) => void 62 export type ToUpdateRemoteJSON = () => FormatedUpdateRemoteVideo
63
64 export type TranscodeVideofileCallback = (err: Error) => void
65 export type TranscodeVideofile = (callback: TranscodeVideofileCallback) => void
66
67 export type GenerateThumbnailFromDataCallback = (err: Error, thumbnailName?: string) => void
68 export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string, callback: GenerateThumbnailFromDataCallback) => void
69
70 export type GetDurationFromFileCallback = (err: Error, duration?: number) => void
16 export type GetDurationFromFile = (videoPath, callback) => void 71 export type GetDurationFromFile = (videoPath, callback) => void
17 export type List = (callback) => void 72
18 export type ListForApi = (start, count, sort, callback) => void 73 export type ListCallback = () => void
19 export type LoadByHostAndRemoteId = (fromHost, remoteId, callback) => void 74 export type List = (callback: ListCallback) => void
20 export type ListOwnedAndPopulateAuthorAndTags = (callback) => void 75
21 export type ListOwnedByAuthor = (author, callback) => void 76 export type ListForApiCallback = (err: Error, videoInstances?: VideoInstance[], total?: number) => void
22 export type Load = (id, callback) => void 77 export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void
23 export type LoadAndPopulateAuthor = (id, callback) => void 78
24 export type LoadAndPopulateAuthorAndPodAndTags = (id, callback) => void 79 export type LoadByHostAndRemoteIdCallback = (err: Error, videoInstance: VideoInstance) => void
25 export type SearchAndPopulateAuthorAndPodAndTags = (value, field, start, count, sort, callback) => void 80 export type LoadByHostAndRemoteId = (fromHost: string, remoteId: string, callback: LoadByHostAndRemoteIdCallback) => void
81
82 export type ListOwnedAndPopulateAuthorAndTagsCallback = (err: Error, videoInstances: VideoInstance[]) => void
83 export type ListOwnedAndPopulateAuthorAndTags = (callback: ListOwnedAndPopulateAuthorAndTagsCallback) => void
84
85 export type ListOwnedByAuthorCallback = (err: Error, videoInstances: VideoInstance[]) => void
86 export type ListOwnedByAuthor = (author: string, callback: ListOwnedByAuthorCallback) => void
87
88 export type LoadCallback = (err: Error, videoInstance: VideoInstance) => void
89 export type Load = (id: string, callback: LoadCallback) => void
90
91 export type LoadAndPopulateAuthorCallback = (err: Error, videoInstance: VideoInstance) => void
92 export type LoadAndPopulateAuthor = (id: string, callback: LoadAndPopulateAuthorCallback) => void
93
94 export type LoadAndPopulateAuthorAndPodAndTagsCallback = (err: Error, videoInstance: VideoInstance) => void
95 export type LoadAndPopulateAuthorAndPodAndTags = (id: string, callback: LoadAndPopulateAuthorAndPodAndTagsCallback) => void
96
97 export type SearchAndPopulateAuthorAndPodAndTagsCallback = (err: Error, videoInstances?: VideoInstance[], total?: number) => void
98 export type SearchAndPopulateAuthorAndPodAndTags = (value: string, field: string, start: number, count: number, sort: string, callback: SearchAndPopulateAuthorAndPodAndTagsCallback) => void
26} 99}
27 100
28export interface VideoClass { 101export interface VideoClass {
@@ -64,6 +137,9 @@ export interface VideoAttributes {
64 views?: number 137 views?: number
65 likes?: number 138 likes?: number
66 dislikes?: number 139 dislikes?: number
140
141 Author?: AuthorInstance
142 Tags?: VideoTagInstance[]
67} 143}
68 144
69export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> { 145export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
diff --git a/server/models/video-tag-interface.ts b/server/models/video-tag-interface.ts
index 468827b8c..f928cecff 100644
--- a/server/models/video-tag-interface.ts
+++ b/server/models/video-tag-interface.ts
@@ -9,7 +9,7 @@ export interface VideoTagClass {
9export interface VideoTagAttributes { 9export interface VideoTagAttributes {
10} 10}
11 11
12export interface VideoTagInstance extends Sequelize.Instance<VideoTagAttributes> { 12export interface VideoTagInstance extends VideoTagClass, VideoTagAttributes, Sequelize.Instance<VideoTagAttributes> {
13 id: number 13 id: number
14 createdAt: Date 14 createdAt: Date
15 updatedAt: Date 15 updatedAt: Date
diff --git a/server/models/video.ts b/server/models/video.ts
index 5558a7c3b..3f808b811 100644
--- a/server/models/video.ts
+++ b/server/models/video.ts
@@ -11,6 +11,7 @@ import { join } from 'path'
11import * as Sequelize from 'sequelize' 11import * as Sequelize from 'sequelize'
12 12
13import { database as db } from '../initializers/database' 13import { database as db } from '../initializers/database'
14import { VideoTagInstance } from './video-tag-interface'
14import { 15import {
15 logger, 16 logger,
16 isVideoNameValid, 17 isVideoNameValid,
@@ -266,7 +267,7 @@ export default function (sequelize, DataTypes) {
266 return Video 267 return Video
267} 268}
268 269
269function beforeValidate (video, options) { 270function beforeValidate (video: VideoInstance) {
270 // Put a fake infoHash if it does not exists yet 271 // Put a fake infoHash if it does not exists yet
271 if (video.isOwned() && !video.infoHash) { 272 if (video.isOwned() && !video.infoHash) {
272 // 40 hexa length 273 // 40 hexa length
@@ -274,7 +275,7 @@ function beforeValidate (video, options) {
274 } 275 }
275} 276}
276 277
277function beforeCreate (video, options) { 278function beforeCreate (video: VideoInstance, options: { transaction: Sequelize.Transaction }) {
278 return new Promise(function (resolve, reject) { 279 return new Promise(function (resolve, reject) {
279 const tasks = [] 280 const tasks = []
280 281
@@ -318,7 +319,7 @@ function beforeCreate (video, options) {
318 }) 319 })
319} 320}
320 321
321function afterDestroy (video, options) { 322function afterDestroy (video: VideoInstance) {
322 return new Promise(function (resolve, reject) { 323 return new Promise(function (resolve, reject) {
323 const tasks = [] 324 const tasks = []
324 325
@@ -401,7 +402,7 @@ generateMagnetUri = function () {
401 } 402 }
402 403
403 const xs = baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentName() 404 const xs = baseUrlHttp + STATIC_PATHS.TORRENTS + this.getTorrentName()
404 const announce = baseUrlWs + '/tracker/socket' 405 const announce = [ baseUrlWs + '/tracker/socket' ]
405 const urlList = [ baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename() ] 406 const urlList = [ baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename() ]
406 407
407 const magnetHash = { 408 const magnetHash = {
@@ -496,7 +497,7 @@ toFormatedJSON = function () {
496 return json 497 return json
497} 498}
498 499
499toAddRemoteJSON = function (callback) { 500toAddRemoteJSON = function (callback: VideoMethods.ToAddRemoteJSONCallback) {
500 // Get thumbnail data to send to the other pod 501 // Get thumbnail data to send to the other pod
501 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName()) 502 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, this.getThumbnailName())
502 fs.readFile(thumbnailPath, (err, thumbnailData) => { 503 fs.readFile(thumbnailPath, (err, thumbnailData) => {
@@ -517,7 +518,7 @@ toAddRemoteJSON = function (callback) {
517 author: this.Author.name, 518 author: this.Author.name,
518 duration: this.duration, 519 duration: this.duration,
519 thumbnailData: thumbnailData.toString('binary'), 520 thumbnailData: thumbnailData.toString('binary'),
520 tags: map(this.Tags, 'name'), 521 tags: map<VideoTagInstance, string>(this.Tags, 'name'),
521 createdAt: this.createdAt, 522 createdAt: this.createdAt,
522 updatedAt: this.updatedAt, 523 updatedAt: this.updatedAt,
523 extname: this.extname, 524 extname: this.extname,
@@ -530,7 +531,7 @@ toAddRemoteJSON = function (callback) {
530 }) 531 })
531} 532}
532 533
533toUpdateRemoteJSON = function (callback) { 534toUpdateRemoteJSON = function () {
534 const json = { 535 const json = {
535 name: this.name, 536 name: this.name,
536 category: this.category, 537 category: this.category,
@@ -542,7 +543,7 @@ toUpdateRemoteJSON = function (callback) {
542 remoteId: this.id, 543 remoteId: this.id,
543 author: this.Author.name, 544 author: this.Author.name,
544 duration: this.duration, 545 duration: this.duration,
545 tags: map(this.Tags, 'name'), 546 tags: map<VideoTagInstance, string>(this.Tags, 'name'),
546 createdAt: this.createdAt, 547 createdAt: this.createdAt,
547 updatedAt: this.updatedAt, 548 updatedAt: this.updatedAt,
548 extname: this.extname, 549 extname: this.extname,
@@ -554,7 +555,7 @@ toUpdateRemoteJSON = function (callback) {
554 return json 555 return json
555} 556}
556 557
557transcodeVideofile = function (finalCallback) { 558transcodeVideofile = function (finalCallback: VideoMethods.TranscodeVideofileCallback) {
558 const video = this 559 const video = this
559 560
560 const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR 561 const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
@@ -591,9 +592,9 @@ transcodeVideofile = function (finalCallback) {
591 video.save().asCallback(callback) 592 video.save().asCallback(callback)
592 } 593 }
593 594
594 ], function (err) { 595 ], function (err: Error) {
595 if (err) { 596 if (err) {
596 // Autodescruction... 597 // Autodesctruction...
597 video.destroy().asCallback(function (err) { 598 video.destroy().asCallback(function (err) {
598 if (err) logger.error('Cannot destruct video after transcoding failure.', { error: err }) 599 if (err) logger.error('Cannot destruct video after transcoding failure.', { error: err })
599 }) 600 })
@@ -609,7 +610,7 @@ transcodeVideofile = function (finalCallback) {
609 610
610// ------------------------------ STATICS ------------------------------ 611// ------------------------------ STATICS ------------------------------
611 612
612generateThumbnailFromData = function (video, thumbnailData, callback) { 613generateThumbnailFromData = function (video: VideoInstance, thumbnailData: string, callback: VideoMethods.GenerateThumbnailFromDataCallback) {
613 // Creating the thumbnail for a remote video 614 // Creating the thumbnail for a remote video
614 615
615 const thumbnailName = video.getThumbnailName() 616 const thumbnailName = video.getThumbnailName()
@@ -621,7 +622,7 @@ generateThumbnailFromData = function (video, thumbnailData, callback) {
621 }) 622 })
622} 623}
623 624
624getDurationFromFile = function (videoPath, callback) { 625getDurationFromFile = function (videoPath: string, callback: VideoMethods.GetDurationFromFileCallback) {
625 ffmpeg.ffprobe(videoPath, function (err, metadata) { 626 ffmpeg.ffprobe(videoPath, function (err, metadata) {
626 if (err) return callback(err) 627 if (err) return callback(err)
627 628
@@ -629,11 +630,11 @@ getDurationFromFile = function (videoPath, callback) {
629 }) 630 })
630} 631}
631 632
632list = function (callback) { 633list = function (callback: VideoMethods.ListCallback) {
633 return Video.findAll().asCallback(callback) 634 return Video.findAll().asCallback(callback)
634} 635}
635 636
636listForApi = function (start, count, sort, callback) { 637listForApi = function (start: number, count: number, sort: string, callback: VideoMethods.ListForApiCallback) {
637 // Exclude Blakclisted videos from the list 638 // Exclude Blakclisted videos from the list
638 const query = { 639 const query = {
639 distinct: true, 640 distinct: true,
@@ -658,7 +659,7 @@ listForApi = function (start, count, sort, callback) {
658 }) 659 })
659} 660}
660 661
661loadByHostAndRemoteId = function (fromHost, remoteId, callback) { 662loadByHostAndRemoteId = function (fromHost: string, remoteId: string, callback: VideoMethods.LoadByHostAndRemoteIdCallback) {
662 const query = { 663 const query = {
663 where: { 664 where: {
664 remoteId: remoteId 665 remoteId: remoteId
@@ -682,7 +683,7 @@ loadByHostAndRemoteId = function (fromHost, remoteId, callback) {
682 return Video.findOne(query).asCallback(callback) 683 return Video.findOne(query).asCallback(callback)
683} 684}
684 685
685listOwnedAndPopulateAuthorAndTags = function (callback) { 686listOwnedAndPopulateAuthorAndTags = function (callback: VideoMethods.ListOwnedAndPopulateAuthorAndTagsCallback) {
686 // If remoteId is null this is *our* video 687 // If remoteId is null this is *our* video
687 const query = { 688 const query = {
688 where: { 689 where: {
@@ -694,7 +695,7 @@ listOwnedAndPopulateAuthorAndTags = function (callback) {
694 return Video.findAll(query).asCallback(callback) 695 return Video.findAll(query).asCallback(callback)
695} 696}
696 697
697listOwnedByAuthor = function (author, callback) { 698listOwnedByAuthor = function (author: string, callback: VideoMethods.ListOwnedByAuthorCallback) {
698 const query = { 699 const query = {
699 where: { 700 where: {
700 remoteId: null 701 remoteId: null
@@ -712,11 +713,11 @@ listOwnedByAuthor = function (author, callback) {
712 return Video.findAll(query).asCallback(callback) 713 return Video.findAll(query).asCallback(callback)
713} 714}
714 715
715load = function (id, callback) { 716load = function (id: string, callback: VideoMethods.LoadCallback) {
716 return Video.findById(id).asCallback(callback) 717 return Video.findById(id).asCallback(callback)
717} 718}
718 719
719loadAndPopulateAuthor = function (id, callback) { 720loadAndPopulateAuthor = function (id: string, callback: VideoMethods.LoadAndPopulateAuthorCallback) {
720 const options = { 721 const options = {
721 include: [ Video['sequelize'].models.Author ] 722 include: [ Video['sequelize'].models.Author ]
722 } 723 }
@@ -724,7 +725,7 @@ loadAndPopulateAuthor = function (id, callback) {
724 return Video.findById(id, options).asCallback(callback) 725 return Video.findById(id, options).asCallback(callback)
725} 726}
726 727
727loadAndPopulateAuthorAndPodAndTags = function (id, callback) { 728loadAndPopulateAuthorAndPodAndTags = function (id: string, callback: VideoMethods.LoadAndPopulateAuthorAndPodAndTagsCallback) {
728 const options = { 729 const options = {
729 include: [ 730 include: [
730 { 731 {
@@ -738,7 +739,14 @@ loadAndPopulateAuthorAndPodAndTags = function (id, callback) {
738 return Video.findById(id, options).asCallback(callback) 739 return Video.findById(id, options).asCallback(callback)
739} 740}
740 741
741searchAndPopulateAuthorAndPodAndTags = function (value, field, start, count, sort, callback) { 742searchAndPopulateAuthorAndPodAndTags = function (
743 value: string,
744 field: string,
745 start: number,
746 count: number,
747 sort: string,
748 callback: VideoMethods.SearchAndPopulateAuthorAndPodAndTagsCallback
749) {
742 const podInclude: any = { 750 const podInclude: any = {
743 model: Video['sequelize'].models.Pod, 751 model: Video['sequelize'].models.Pod,
744 required: false 752 required: false
@@ -821,27 +829,27 @@ function createBaseVideosWhere () {
821 } 829 }
822} 830}
823 831
824function removeThumbnail (video, callback) { 832function removeThumbnail (video: VideoInstance, callback: (err: Error) => void) {
825 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName()) 833 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName())
826 fs.unlink(thumbnailPath, callback) 834 fs.unlink(thumbnailPath, callback)
827} 835}
828 836
829function removeFile (video, callback) { 837function removeFile (video: VideoInstance, callback: (err: Error) => void) {
830 const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename()) 838 const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename())
831 fs.unlink(filePath, callback) 839 fs.unlink(filePath, callback)
832} 840}
833 841
834function removeTorrent (video, callback) { 842function removeTorrent (video: VideoInstance, callback: (err: Error) => void) {
835 const torrenPath = join(CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName()) 843 const torrenPath = join(CONFIG.STORAGE.TORRENTS_DIR, video.getTorrentName())
836 fs.unlink(torrenPath, callback) 844 fs.unlink(torrenPath, callback)
837} 845}
838 846
839function removePreview (video, callback) { 847function removePreview (video: VideoInstance, callback: (err: Error) => void) {
840 // Same name than video thumnail 848 // Same name than video thumnail
841 fs.unlink(CONFIG.STORAGE.PREVIEWS_DIR + video.getPreviewName(), callback) 849 fs.unlink(CONFIG.STORAGE.PREVIEWS_DIR + video.getPreviewName(), callback)
842} 850}
843 851
844function createTorrentFromVideo (video, videoPath, callback) { 852function createTorrentFromVideo (video: VideoInstance, videoPath: string, callback: (err: Error) => void) {
845 const options = { 853 const options = {
846 announceList: [ 854 announceList: [
847 [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ] 855 [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ]
@@ -865,24 +873,23 @@ function createTorrentFromVideo (video, videoPath, callback) {
865 }) 873 })
866} 874}
867 875
868function createPreview (video, videoPath, callback) { 876function createPreview (video: VideoInstance, videoPath: string, callback: (err: Error) => void) {
869 generateImage(video, videoPath, CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName(), callback) 877 generateImage(video, videoPath, CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName(), null, callback)
870} 878}
871 879
872function createThumbnail (video, videoPath, callback) { 880function createThumbnail (video: VideoInstance, videoPath: string, callback: (err: Error) => void) {
873 generateImage(video, videoPath, CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), THUMBNAILS_SIZE, callback) 881 generateImage(video, videoPath, CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), THUMBNAILS_SIZE, callback)
874} 882}
875 883
876function generateImage (video, videoPath, folder, imageName, size, callback?) { 884type GenerateImageCallback = (err: Error, imageName: string) => void
885function generateImage (video: VideoInstance, videoPath: string, folder: string, imageName: string, size: string, callback?: GenerateImageCallback) {
877 const options: any = { 886 const options: any = {
878 filename: imageName, 887 filename: imageName,
879 count: 1, 888 count: 1,
880 folder 889 folder
881 } 890 }
882 891
883 if (!callback) { 892 if (size) {
884 callback = size
885 } else {
886 options.size = size 893 options.size = size
887 } 894 }
888 895
@@ -894,7 +901,7 @@ function generateImage (video, videoPath, folder, imageName, size, callback?) {
894 .thumbnail(options) 901 .thumbnail(options)
895} 902}
896 903
897function removeFromBlacklist (video, callback) { 904function removeFromBlacklist (video: VideoInstance, callback: (err: Error) => void) {
898 // Find the blacklisted video 905 // Find the blacklisted video
899 db.BlacklistedVideo.loadByVideoId(video.id, function (err, video) { 906 db.BlacklistedVideo.loadByVideoId(video.id, function (err, video) {
900 // If an error occured, stop here 907 // If an error occured, stop here
@@ -908,7 +915,7 @@ function removeFromBlacklist (video, callback) {
908 video.destroy().asCallback(callback) 915 video.destroy().asCallback(callback)
909 } else { 916 } else {
910 // If haven't found it, simply ignore it and do nothing 917 // If haven't found it, simply ignore it and do nothing
911 return callback() 918 return callback(null)
912 } 919 }
913 }) 920 })
914} 921}