aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-15 11:00:25 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit608624252466acf9f1d9ee1c1170bd4fe4d18d18 (patch)
tree47eab55bb5421b7fe88e0b2ac743a436fd9561cf /server/models
parent51548b31815c6f96f314ae96588a9adca150519d (diff)
downloadPeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.tar.gz
PeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.tar.zst
PeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.zip
Rename Pod -> Server
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account-follow.ts4
-rw-r--r--server/models/account/account-interface.ts11
-rw-r--r--server/models/account/account.ts37
-rw-r--r--server/models/index.ts2
-rw-r--r--server/models/pod/index.ts1
-rw-r--r--server/models/pod/pod-interface.ts61
-rw-r--r--server/models/pod/pod.ts248
-rw-r--r--server/models/server/index.ts1
-rw-r--r--server/models/server/server-interface.ts56
-rw-r--r--server/models/server/server.ts233
-rw-r--r--server/models/video/video-abuse-interface.ts4
-rw-r--r--server/models/video/video-abuse.ts18
-rw-r--r--server/models/video/video-channel-interface.ts2
-rw-r--r--server/models/video/video-channel.ts14
-rw-r--r--server/models/video/video-interface.ts12
-rw-r--r--server/models/video/video.ts58
16 files changed, 375 insertions, 387 deletions
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts
index 6d7592326..c940d7cd4 100644
--- a/server/models/account/account-follow.ts
+++ b/server/models/account/account-follow.ts
@@ -101,7 +101,7 @@ listFollowingForApi = function (id: number, start: number, count: number, sort:
101 model: AccountFollow['sequelize'].models.Account, 101 model: AccountFollow['sequelize'].models.Account,
102 as: 'AccountFollowing', 102 as: 'AccountFollowing',
103 required: true, 103 required: true,
104 include: [ AccountFollow['sequelize'].models.Pod ] 104 include: [ AccountFollow['sequelize'].models.Server ]
105 } 105 }
106 ] 106 ]
107 } 107 }
@@ -125,7 +125,7 @@ listFollowersForApi = function (id: number, start: number, count: number, sort:
125 model: AccountFollow[ 'sequelize' ].models.Account, 125 model: AccountFollow[ 'sequelize' ].models.Account,
126 required: true, 126 required: true,
127 as: 'AccountFollower', 127 as: 'AccountFollower',
128 include: [ AccountFollow['sequelize'].models.Pod ] 128 include: [ AccountFollow['sequelize'].models.Server ]
129 }, 129 },
130 { 130 {
131 model: AccountFollow['sequelize'].models.Account, 131 model: AccountFollow['sequelize'].models.Account,
diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.ts
index ce1afec02..1a567fb7a 100644
--- a/server/models/account/account-interface.ts
+++ b/server/models/account/account-interface.ts
@@ -1,8 +1,7 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
3import { Account as FormattedAccount, ActivityPubActor } from '../../../shared' 3import { Account as FormattedAccount, ActivityPubActor } from '../../../shared'
4import { ResultList } from '../../../shared/models/result-list.model' 4import { ServerInstance } from '../server/server-interface'
5import { PodInstance } from '../pod/pod-interface'
6import { VideoChannelInstance } from '../video/video-channel-interface' 5import { VideoChannelInstance } from '../video/video-channel-interface'
7 6
8export namespace AccountMethods { 7export namespace AccountMethods {
@@ -11,7 +10,7 @@ export namespace AccountMethods {
11 export type Load = (id: number) => Bluebird<AccountInstance> 10 export type Load = (id: number) => Bluebird<AccountInstance>
12 export type LoadByUUID = (uuid: string) => Bluebird<AccountInstance> 11 export type LoadByUUID = (uuid: string) => Bluebird<AccountInstance>
13 export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance> 12 export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance>
14 export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance> 13 export type LoadAccountByServerAndUUID = (uuid: string, serverId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance>
15 export type LoadLocalByName = (name: string) => Bluebird<AccountInstance> 14 export type LoadLocalByName = (name: string) => Bluebird<AccountInstance>
16 export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance> 15 export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance>
17 export type ListOwned = () => Bluebird<AccountInstance[]> 16 export type ListOwned = () => Bluebird<AccountInstance[]>
@@ -27,7 +26,7 @@ export namespace AccountMethods {
27 26
28export interface AccountClass { 27export interface AccountClass {
29 loadApplication: AccountMethods.LoadApplication 28 loadApplication: AccountMethods.LoadApplication
30 loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID 29 loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID
31 load: AccountMethods.Load 30 load: AccountMethods.Load
32 loadByUUID: AccountMethods.LoadByUUID 31 loadByUUID: AccountMethods.LoadByUUID
33 loadByUrl: AccountMethods.LoadByUrl 32 loadByUrl: AccountMethods.LoadByUrl
@@ -51,7 +50,7 @@ export interface AccountAttributes {
51 50
52 uuid?: string 51 uuid?: string
53 52
54 podId?: number 53 serverId?: number
55 userId?: number 54 userId?: number
56 applicationId?: number 55 applicationId?: number
57} 56}
@@ -69,7 +68,7 @@ export interface AccountInstance extends AccountClass, AccountAttributes, Sequel
69 createdAt: Date 68 createdAt: Date
70 updatedAt: Date 69 updatedAt: Date
71 70
72 Pod: PodInstance 71 Server: ServerInstance
73 VideoChannels: VideoChannelInstance[] 72 VideoChannels: VideoChannelInstance[]
74} 73}
75 74
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index e90eaae5e..ee00c5aef 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -26,7 +26,7 @@ import { sendDeleteAccount } from '../../lib/activitypub/send-request'
26import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants' 26import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants'
27 27
28let Account: Sequelize.Model<AccountInstance, AccountAttributes> 28let Account: Sequelize.Model<AccountInstance, AccountAttributes>
29let loadAccountByPodAndUUID: AccountMethods.LoadAccountByPodAndUUID 29let loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID
30let load: AccountMethods.Load 30let load: AccountMethods.Load
31let loadApplication: AccountMethods.LoadApplication 31let loadApplication: AccountMethods.LoadApplication
32let loadByUUID: AccountMethods.LoadByUUID 32let loadByUUID: AccountMethods.LoadByUUID
@@ -170,7 +170,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
170 fields: [ 'name' ] 170 fields: [ 'name' ]
171 }, 171 },
172 { 172 {
173 fields: [ 'podId' ] 173 fields: [ 'serverId' ]
174 }, 174 },
175 { 175 {
176 fields: [ 'userId' ], 176 fields: [ 'userId' ],
@@ -181,7 +181,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
181 unique: true 181 unique: true
182 }, 182 },
183 { 183 {
184 fields: [ 'name', 'podId', 'applicationId' ], 184 fields: [ 'name', 'serverId', 'applicationId' ],
185 unique: true 185 unique: true
186 } 186 }
187 ], 187 ],
@@ -191,7 +191,7 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
191 191
192 const classMethods = [ 192 const classMethods = [
193 associate, 193 associate,
194 loadAccountByPodAndUUID, 194 loadAccountByServerAndUUID,
195 loadApplication, 195 loadApplication,
196 load, 196 load,
197 loadByUUID, 197 loadByUUID,
@@ -217,9 +217,9 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
217// --------------------------------------------------------------------------- 217// ---------------------------------------------------------------------------
218 218
219function associate (models) { 219function associate (models) {
220 Account.belongsTo(models.Pod, { 220 Account.belongsTo(models.Server, {
221 foreignKey: { 221 foreignKey: {
222 name: 'podId', 222 name: 'serverId',
223 allowNull: true 223 allowNull: true
224 }, 224 },
225 onDelete: 'cascade' 225 onDelete: 'cascade'
@@ -278,19 +278,28 @@ function afterDestroy (account: AccountInstance) {
278} 278}
279 279
280toFormattedJSON = function (this: AccountInstance) { 280toFormattedJSON = function (this: AccountInstance) {
281 let host = this.Pod ? this.Pod.host : CONFIG.WEBSERVER.HOST 281 let host = CONFIG.WEBSERVER.HOST
282 let score: number
283
284 if (this.Server) {
285 host = this.Server.host
286 score = this.Server.score as number
287 }
282 288
283 const json = { 289 const json = {
284 id: this.id, 290 id: this.id,
285 host, 291 host,
286 name: this.name 292 score,
293 name: this.name,
294 createdAt: this.createdAt,
295 updatedAt: this.updatedAt
287 } 296 }
288 297
289 return json 298 return json
290} 299}
291 300
292toActivityPubObject = function (this: AccountInstance) { 301toActivityPubObject = function (this: AccountInstance) {
293 const type = this.podId ? 'Application' as 'Application' : 'Person' as 'Person' 302 const type = this.serverId ? 'Application' as 'Application' : 'Person' as 'Person'
294 303
295 const json = { 304 const json = {
296 type, 305 type,
@@ -317,7 +326,7 @@ toActivityPubObject = function (this: AccountInstance) {
317} 326}
318 327
319isOwned = function (this: AccountInstance) { 328isOwned = function (this: AccountInstance) {
320 return this.podId === null 329 return this.serverId === null
321} 330}
322 331
323getFollowerSharedInboxUrls = function (this: AccountInstance) { 332getFollowerSharedInboxUrls = function (this: AccountInstance) {
@@ -356,7 +365,7 @@ getPublicKeyUrl = function (this: AccountInstance) {
356listOwned = function () { 365listOwned = function () {
357 const query: Sequelize.FindOptions<AccountAttributes> = { 366 const query: Sequelize.FindOptions<AccountAttributes> = {
358 where: { 367 where: {
359 podId: null 368 serverId: null
360 } 369 }
361 } 370 }
362 371
@@ -417,7 +426,7 @@ loadByNameAndHost = function (name: string, host: string) {
417 }, 426 },
418 include: [ 427 include: [
419 { 428 {
420 model: Account['sequelize'].models.Pod, 429 model: Account['sequelize'].models.Server,
421 required: true, 430 required: true,
422 where: { 431 where: {
423 host 432 host
@@ -440,10 +449,10 @@ loadByUrl = function (url: string, transaction?: Sequelize.Transaction) {
440 return Account.findOne(query) 449 return Account.findOne(query)
441} 450}
442 451
443loadAccountByPodAndUUID = function (uuid: string, podId: number, transaction: Sequelize.Transaction) { 452loadAccountByServerAndUUID = function (uuid: string, serverId: number, transaction: Sequelize.Transaction) {
444 const query: Sequelize.FindOptions<AccountAttributes> = { 453 const query: Sequelize.FindOptions<AccountAttributes> = {
445 where: { 454 where: {
446 podId, 455 serverId,
447 uuid 456 uuid
448 }, 457 },
449 transaction 458 transaction
diff --git a/server/models/index.ts b/server/models/index.ts
index 0aec2d3b1..65faa5294 100644
--- a/server/models/index.ts
+++ b/server/models/index.ts
@@ -1,6 +1,6 @@
1export * from './application' 1export * from './application'
2export * from './job' 2export * from './job'
3export * from './oauth' 3export * from './oauth'
4export * from './pod' 4export * from './server'
5export * from './account' 5export * from './account'
6export * from './video' 6export * from './video'
diff --git a/server/models/pod/index.ts b/server/models/pod/index.ts
deleted file mode 100644
index d2bf50d4d..000000000
--- a/server/models/pod/index.ts
+++ /dev/null
@@ -1 +0,0 @@
1export * from './pod-interface'
diff --git a/server/models/pod/pod-interface.ts b/server/models/pod/pod-interface.ts
deleted file mode 100644
index 6c5aab3fa..000000000
--- a/server/models/pod/pod-interface.ts
+++ /dev/null
@@ -1,61 +0,0 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3
4// Don't use barrel, import just what we need
5import { Pod as FormattedPod } from '../../../shared/models/pods/pod.model'
6import { ResultList } from '../../../shared/models/result-list.model'
7
8export namespace PodMethods {
9 export type ToFormattedJSON = (this: PodInstance) => FormattedPod
10
11 export type CountAll = () => Promise<number>
12
13 export type IncrementScores = (ids: number[], value: number) => Promise<[ number, PodInstance[] ]>
14
15 export type List = () => Promise<PodInstance[]>
16
17 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<PodInstance> >
18
19 export type ListAllIds = (transaction: Sequelize.Transaction) => Promise<number[]>
20
21 export type ListRandomPodIdsWithRequest = (limit: number, tableWithPods: string, tableWithPodsJoins: string) => Promise<number[]>
22
23 export type ListBadPods = () => Promise<PodInstance[]>
24
25 export type Load = (id: number) => Promise<PodInstance>
26
27 export type LoadByHost = (host: string) => Promise<PodInstance>
28
29 export type RemoveAll = () => Promise<number>
30
31 export type UpdatePodsScore = (goodPods: number[], badPods: number[]) => void
32}
33
34export interface PodClass {
35 countAll: PodMethods.CountAll
36 incrementScores: PodMethods.IncrementScores
37 list: PodMethods.List
38 listForApi: PodMethods.ListForApi
39 listAllIds: PodMethods.ListAllIds
40 listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest
41 listBadPods: PodMethods.ListBadPods
42 load: PodMethods.Load
43 loadByHost: PodMethods.LoadByHost
44 removeAll: PodMethods.RemoveAll
45 updatePodsScore: PodMethods.UpdatePodsScore
46}
47
48export interface PodAttributes {
49 id?: number
50 host?: string
51 score?: number | Sequelize.literal // Sequelize literal for 'score +' + value
52}
53
54export interface PodInstance extends PodClass, PodAttributes, Sequelize.Instance<PodAttributes> {
55 createdAt: Date
56 updatedAt: Date
57
58 toFormattedJSON: PodMethods.ToFormattedJSON,
59}
60
61export interface PodModel extends PodClass, Sequelize.Model<PodInstance, PodAttributes> {}
diff --git a/server/models/pod/pod.ts b/server/models/pod/pod.ts
deleted file mode 100644
index 6d270ad7f..000000000
--- a/server/models/pod/pod.ts
+++ /dev/null
@@ -1,248 +0,0 @@
1import { map } from 'lodash'
2import * as Sequelize from 'sequelize'
3
4import { FRIEND_SCORE, PODS_SCORE } from '../../initializers'
5import { logger, isHostValid } from '../../helpers'
6
7import { addMethodsToModel, getSort } from '../utils'
8import {
9 PodInstance,
10 PodAttributes,
11
12 PodMethods
13} from './pod-interface'
14
15let Pod: Sequelize.Model<PodInstance, PodAttributes>
16let toFormattedJSON: PodMethods.ToFormattedJSON
17let countAll: PodMethods.CountAll
18let incrementScores: PodMethods.IncrementScores
19let list: PodMethods.List
20let listForApi: PodMethods.ListForApi
21let listAllIds: PodMethods.ListAllIds
22let listRandomPodIdsWithRequest: PodMethods.ListRandomPodIdsWithRequest
23let listBadPods: PodMethods.ListBadPods
24let load: PodMethods.Load
25let loadByHost: PodMethods.LoadByHost
26let removeAll: PodMethods.RemoveAll
27let updatePodsScore: PodMethods.UpdatePodsScore
28
29export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
30 Pod = sequelize.define<PodInstance, PodAttributes>('Pod',
31 {
32 host: {
33 type: DataTypes.STRING,
34 allowNull: false,
35 validate: {
36 isHost: value => {
37 const res = isHostValid(value)
38 if (res === false) throw new Error('Host not valid.')
39 }
40 }
41 },
42 score: {
43 type: DataTypes.INTEGER,
44 defaultValue: FRIEND_SCORE.BASE,
45 allowNull: false,
46 validate: {
47 isInt: true,
48 max: FRIEND_SCORE.MAX
49 }
50 }
51 },
52 {
53 indexes: [
54 {
55 fields: [ 'host' ],
56 unique: true
57 },
58 {
59 fields: [ 'score' ]
60 }
61 ]
62 }
63 )
64
65 const classMethods = [
66 countAll,
67 incrementScores,
68 list,
69 listForApi,
70 listAllIds,
71 listRandomPodIdsWithRequest,
72 listBadPods,
73 load,
74 loadByHost,
75 updatePodsScore,
76 removeAll
77 ]
78 const instanceMethods = [ toFormattedJSON ]
79 addMethodsToModel(Pod, classMethods, instanceMethods)
80
81 return Pod
82}
83
84// ------------------------------ METHODS ------------------------------
85
86toFormattedJSON = function (this: PodInstance) {
87 const json = {
88 id: this.id,
89 host: this.host,
90 score: this.score as number,
91 createdAt: this.createdAt
92 }
93
94 return json
95}
96
97// ------------------------------ Statics ------------------------------
98
99countAll = function () {
100 return Pod.count()
101}
102
103incrementScores = function (ids: number[], value: number) {
104 const update = {
105 score: Sequelize.literal('score +' + value)
106 }
107
108 const options = {
109 where: {
110 id: {
111 [Sequelize.Op.in]: ids
112 }
113 },
114 // In this case score is a literal and not an integer so we do not validate it
115 validate: false
116 }
117
118 return Pod.update(update, options)
119}
120
121list = function () {
122 return Pod.findAll()
123}
124
125listForApi = function (start: number, count: number, sort: string) {
126 const query = {
127 offset: start,
128 limit: count,
129 order: [ getSort(sort) ]
130 }
131
132 return Pod.findAndCountAll(query).then(({ rows, count }) => {
133 return {
134 data: rows,
135 total: count
136 }
137 })
138}
139
140listAllIds = function (transaction: Sequelize.Transaction) {
141 const query = {
142 attributes: [ 'id' ],
143 transaction
144 }
145
146 return Pod.findAll(query).then(pods => {
147 return map(pods, 'id')
148 })
149}
150
151listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, tableWithPodsJoins: string) {
152 return Pod.count().then(count => {
153 // Optimization...
154 if (count === 0) return []
155
156 let start = Math.floor(Math.random() * count) - limit
157 if (start < 0) start = 0
158
159 const subQuery = `(SELECT DISTINCT "${tableWithPods}"."podId" FROM "${tableWithPods}" ${tableWithPodsJoins})`
160 const query = {
161 attributes: [ 'id' ],
162 order: [
163 [ 'id', 'ASC' ]
164 ],
165 offset: start,
166 limit: limit,
167 where: {
168 id: {
169 [Sequelize.Op.in]: Sequelize.literal(subQuery)
170 }
171 }
172 }
173
174 return Pod.findAll(query).then(pods => {
175 return map(pods, 'id')
176 })
177 })
178}
179
180listBadPods = function () {
181 const query = {
182 where: {
183 score: {
184 [Sequelize.Op.lte]: 0
185 }
186 }
187 }
188
189 return Pod.findAll(query)
190}
191
192load = function (id: number) {
193 return Pod.findById(id)
194}
195
196loadByHost = function (host: string) {
197 const query = {
198 where: {
199 host: host
200 }
201 }
202
203 return Pod.findOne(query)
204}
205
206removeAll = function () {
207 return Pod.destroy()
208}
209
210updatePodsScore = function (goodPods: number[], badPods: number[]) {
211 logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length)
212
213 if (goodPods.length !== 0) {
214 incrementScores(goodPods, PODS_SCORE.BONUS).catch(err => {
215 logger.error('Cannot increment scores of good pods.', err)
216 })
217 }
218
219 if (badPods.length !== 0) {
220 incrementScores(badPods, PODS_SCORE.PENALTY)
221 .then(() => removeBadPods())
222 .catch(err => {
223 if (err) logger.error('Cannot decrement scores of bad pods.', err)
224 })
225 }
226}
227
228// ---------------------------------------------------------------------------
229
230// Remove pods with a score of 0 (too many requests where they were unreachable)
231async function removeBadPods () {
232 try {
233 const pods = await listBadPods()
234
235 const podsRemovePromises = pods.map(pod => pod.destroy())
236 await Promise.all(podsRemovePromises)
237
238 const numberOfPodsRemoved = pods.length
239
240 if (numberOfPodsRemoved) {
241 logger.info('Removed %d pods.', numberOfPodsRemoved)
242 } else {
243 logger.info('No need to remove bad pods.')
244 }
245 } catch (err) {
246 logger.error('Cannot remove bad pods.', err)
247 }
248}
diff --git a/server/models/server/index.ts b/server/models/server/index.ts
new file mode 100644
index 000000000..4cb2994aa
--- /dev/null
+++ b/server/models/server/index.ts
@@ -0,0 +1 @@
export * from './server-interface'
diff --git a/server/models/server/server-interface.ts b/server/models/server/server-interface.ts
new file mode 100644
index 000000000..806d052cb
--- /dev/null
+++ b/server/models/server/server-interface.ts
@@ -0,0 +1,56 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3
4// Don't use barrel, import just what we need
5import { ResultList } from '../../../shared/models/result-list.model'
6
7export namespace ServerMethods {
8 export type CountAll = () => Promise<number>
9
10 export type IncrementScores = (ids: number[], value: number) => Promise<[ number, ServerInstance[] ]>
11
12 export type List = () => Promise<ServerInstance[]>
13
14 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<ServerInstance> >
15
16 export type ListAllIds = (transaction: Sequelize.Transaction) => Promise<number[]>
17
18 export type ListRandomServerIdsWithRequest = (limit: number, tableWithServers: string, tableWithServersJoins: string) => Promise<number[]>
19
20 export type ListBadServers = () => Promise<ServerInstance[]>
21
22 export type Load = (id: number) => Promise<ServerInstance>
23
24 export type LoadByHost = (host: string) => Promise<ServerInstance>
25
26 export type RemoveAll = () => Promise<number>
27
28 export type UpdateServersScore = (goodServers: number[], badServers: number[]) => void
29}
30
31export interface ServerClass {
32 countAll: ServerMethods.CountAll
33 incrementScores: ServerMethods.IncrementScores
34 list: ServerMethods.List
35 listForApi: ServerMethods.ListForApi
36 listAllIds: ServerMethods.ListAllIds
37 listRandomServerIdsWithRequest: ServerMethods.ListRandomServerIdsWithRequest
38 listBadServers: ServerMethods.ListBadServers
39 load: ServerMethods.Load
40 loadByHost: ServerMethods.LoadByHost
41 removeAll: ServerMethods.RemoveAll
42 updateServersScore: ServerMethods.UpdateServersScore
43}
44
45export interface ServerAttributes {
46 id?: number
47 host?: string
48 score?: number | Sequelize.literal // Sequelize literal for 'score +' + value
49}
50
51export interface ServerInstance extends ServerClass, ServerAttributes, Sequelize.Instance<ServerAttributes> {
52 createdAt: Date
53 updatedAt: Date
54}
55
56export interface ServerModel extends ServerClass, Sequelize.Model<ServerInstance, ServerAttributes> {}
diff --git a/server/models/server/server.ts b/server/models/server/server.ts
new file mode 100644
index 000000000..26fa87550
--- /dev/null
+++ b/server/models/server/server.ts
@@ -0,0 +1,233 @@
1import { map } from 'lodash'
2import * as Sequelize from 'sequelize'
3
4import { FRIEND_SCORE, SERVERS_SCORE } from '../../initializers'
5import { logger, isHostValid } from '../../helpers'
6
7import { addMethodsToModel, getSort } from '../utils'
8import {
9 ServerInstance,
10 ServerAttributes,
11
12 ServerMethods
13} from './server-interface'
14
15let Server: Sequelize.Model<ServerInstance, ServerAttributes>
16let countAll: ServerMethods.CountAll
17let incrementScores: ServerMethods.IncrementScores
18let list: ServerMethods.List
19let listForApi: ServerMethods.ListForApi
20let listAllIds: ServerMethods.ListAllIds
21let listRandomServerIdsWithRequest: ServerMethods.ListRandomServerIdsWithRequest
22let listBadServers: ServerMethods.ListBadServers
23let load: ServerMethods.Load
24let loadByHost: ServerMethods.LoadByHost
25let removeAll: ServerMethods.RemoveAll
26let updateServersScore: ServerMethods.UpdateServersScore
27
28export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
29 Server = sequelize.define<ServerInstance, ServerAttributes>('Server',
30 {
31 host: {
32 type: DataTypes.STRING,
33 allowNull: false,
34 validate: {
35 isHost: value => {
36 const res = isHostValid(value)
37 if (res === false) throw new Error('Host not valid.')
38 }
39 }
40 },
41 score: {
42 type: DataTypes.INTEGER,
43 defaultValue: FRIEND_SCORE.BASE,
44 allowNull: false,
45 validate: {
46 isInt: true,
47 max: FRIEND_SCORE.MAX
48 }
49 }
50 },
51 {
52 indexes: [
53 {
54 fields: [ 'host' ],
55 unique: true
56 },
57 {
58 fields: [ 'score' ]
59 }
60 ]
61 }
62 )
63
64 const classMethods = [
65 countAll,
66 incrementScores,
67 list,
68 listForApi,
69 listAllIds,
70 listRandomServerIdsWithRequest,
71 listBadServers,
72 load,
73 loadByHost,
74 updateServersScore,
75 removeAll
76 ]
77 addMethodsToModel(Server, classMethods)
78
79 return Server
80}
81
82// ------------------------------ Statics ------------------------------
83
84countAll = function () {
85 return Server.count()
86}
87
88incrementScores = function (ids: number[], value: number) {
89 const update = {
90 score: Sequelize.literal('score +' + value)
91 }
92
93 const options = {
94 where: {
95 id: {
96 [Sequelize.Op.in]: ids
97 }
98 },
99 // In this case score is a literal and not an integer so we do not validate it
100 validate: false
101 }
102
103 return Server.update(update, options)
104}
105
106list = function () {
107 return Server.findAll()
108}
109
110listForApi = function (start: number, count: number, sort: string) {
111 const query = {
112 offset: start,
113 limit: count,
114 order: [ getSort(sort) ]
115 }
116
117 return Server.findAndCountAll(query).then(({ rows, count }) => {
118 return {
119 data: rows,
120 total: count
121 }
122 })
123}
124
125listAllIds = function (transaction: Sequelize.Transaction) {
126 const query = {
127 attributes: [ 'id' ],
128 transaction
129 }
130
131 return Server.findAll(query).then(servers => {
132 return map(servers, 'id')
133 })
134}
135
136listRandomServerIdsWithRequest = function (limit: number, tableWithServers: string, tableWithServersJoins: string) {
137 return Server.count().then(count => {
138 // Optimization...
139 if (count === 0) return []
140
141 let start = Math.floor(Math.random() * count) - limit
142 if (start < 0) start = 0
143
144 const subQuery = `(SELECT DISTINCT "${tableWithServers}"."serverId" FROM "${tableWithServers}" ${tableWithServersJoins})`
145 const query = {
146 attributes: [ 'id' ],
147 order: [
148 [ 'id', 'ASC' ]
149 ],
150 offset: start,
151 limit: limit,
152 where: {
153 id: {
154 [Sequelize.Op.in]: Sequelize.literal(subQuery)
155 }
156 }
157 }
158
159 return Server.findAll(query).then(servers => {
160 return map(servers, 'id')
161 })
162 })
163}
164
165listBadServers = function () {
166 const query = {
167 where: {
168 score: {
169 [Sequelize.Op.lte]: 0
170 }
171 }
172 }
173
174 return Server.findAll(query)
175}
176
177load = function (id: number) {
178 return Server.findById(id)
179}
180
181loadByHost = function (host: string) {
182 const query = {
183 where: {
184 host: host
185 }
186 }
187
188 return Server.findOne(query)
189}
190
191removeAll = function () {
192 return Server.destroy()
193}
194
195updateServersScore = function (goodServers: number[], badServers: number[]) {
196 logger.info('Updating %d good servers and %d bad servers scores.', goodServers.length, badServers.length)
197
198 if (goodServers.length !== 0) {
199 incrementScores(goodServers, SERVERS_SCORE.BONUS).catch(err => {
200 logger.error('Cannot increment scores of good servers.', err)
201 })
202 }
203
204 if (badServers.length !== 0) {
205 incrementScores(badServers, SERVERS_SCORE.PENALTY)
206 .then(() => removeBadServers())
207 .catch(err => {
208 if (err) logger.error('Cannot decrement scores of bad servers.', err)
209 })
210 }
211}
212
213// ---------------------------------------------------------------------------
214
215// Remove servers with a score of 0 (too many requests where they were unreachable)
216async function removeBadServers () {
217 try {
218 const servers = await listBadServers()
219
220 const serversRemovePromises = servers.map(server => server.destroy())
221 await Promise.all(serversRemovePromises)
222
223 const numberOfServersRemoved = servers.length
224
225 if (numberOfServersRemoved) {
226 logger.info('Removed %d servers.', numberOfServersRemoved)
227 } else {
228 logger.info('No need to remove bad servers.')
229 }
230 } catch (err) {
231 logger.error('Cannot remove bad servers.', err)
232 }
233}
diff --git a/server/models/video/video-abuse-interface.ts b/server/models/video/video-abuse-interface.ts
index 978268926..16806cae2 100644
--- a/server/models/video/video-abuse-interface.ts
+++ b/server/models/video/video-abuse-interface.ts
@@ -1,7 +1,7 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird' 2import * as Promise from 'bluebird'
3 3
4import { PodInstance } from '../pod/pod-interface' 4import { ServerInstance } from '../server/server-interface'
5import { ResultList } from '../../../shared' 5import { ResultList } from '../../../shared'
6 6
7// Don't use barrel, import just what we need 7// Don't use barrel, import just what we need
@@ -28,7 +28,7 @@ export interface VideoAbuseInstance extends VideoAbuseClass, VideoAbuseAttribute
28 createdAt: Date 28 createdAt: Date
29 updatedAt: Date 29 updatedAt: Date
30 30
31 Pod: PodInstance 31 Server: ServerInstance
32 32
33 toFormattedJSON: VideoAbuseMethods.ToFormattedJSON 33 toFormattedJSON: VideoAbuseMethods.ToFormattedJSON
34} 34}
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index ebc63e7a0..c1d070ec0 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -45,7 +45,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
45 fields: [ 'videoId' ] 45 fields: [ 'videoId' ]
46 }, 46 },
47 { 47 {
48 fields: [ 'reporterPodId' ] 48 fields: [ 'reporterServerId' ]
49 } 49 }
50 ] 50 ]
51 } 51 }
@@ -67,18 +67,18 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
67// ------------------------------ METHODS ------------------------------ 67// ------------------------------ METHODS ------------------------------
68 68
69toFormattedJSON = function (this: VideoAbuseInstance) { 69toFormattedJSON = function (this: VideoAbuseInstance) {
70 let reporterPodHost 70 let reporterServerHost
71 71
72 if (this.Pod) { 72 if (this.Server) {
73 reporterPodHost = this.Pod.host 73 reporterServerHost = this.Server.host
74 } else { 74 } else {
75 // It means it's our video 75 // It means it's our video
76 reporterPodHost = CONFIG.WEBSERVER.HOST 76 reporterServerHost = CONFIG.WEBSERVER.HOST
77 } 77 }
78 78
79 const json = { 79 const json = {
80 id: this.id, 80 id: this.id,
81 reporterPodHost, 81 reporterServerHost,
82 reason: this.reason, 82 reason: this.reason,
83 reporterUsername: this.reporterUsername, 83 reporterUsername: this.reporterUsername,
84 videoId: this.videoId, 84 videoId: this.videoId,
@@ -91,9 +91,9 @@ toFormattedJSON = function (this: VideoAbuseInstance) {
91// ------------------------------ STATICS ------------------------------ 91// ------------------------------ STATICS ------------------------------
92 92
93function associate (models) { 93function associate (models) {
94 VideoAbuse.belongsTo(models.Pod, { 94 VideoAbuse.belongsTo(models.Server, {
95 foreignKey: { 95 foreignKey: {
96 name: 'reporterPodId', 96 name: 'reporterServerId',
97 allowNull: true 97 allowNull: true
98 }, 98 },
99 onDelete: 'CASCADE' 99 onDelete: 'CASCADE'
@@ -115,7 +115,7 @@ listForApi = function (start: number, count: number, sort: string) {
115 order: [ getSort(sort) ], 115 order: [ getSort(sort) ],
116 include: [ 116 include: [
117 { 117 {
118 model: VideoAbuse['sequelize'].models.Pod, 118 model: VideoAbuse['sequelize'].models.Server,
119 required: false 119 required: false
120 } 120 }
121 ] 121 ]
diff --git a/server/models/video/video-channel-interface.ts b/server/models/video/video-channel-interface.ts
index 55e772063..8ad3e5cb7 100644
--- a/server/models/video/video-channel-interface.ts
+++ b/server/models/video/video-channel-interface.ts
@@ -22,7 +22,7 @@ export namespace VideoChannelMethods {
22 export type LoadAndPopulateAccount = (id: number) => Promise<VideoChannelInstance> 22 export type LoadAndPopulateAccount = (id: number) => Promise<VideoChannelInstance>
23 export type LoadByUUIDAndPopulateAccount = (uuid: string) => Promise<VideoChannelInstance> 23 export type LoadByUUIDAndPopulateAccount = (uuid: string) => Promise<VideoChannelInstance>
24 export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance> 24 export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance>
25 export type LoadByHostAndUUID = (uuid: string, podHost: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance> 25 export type LoadByHostAndUUID = (uuid: string, serverHost: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance>
26 export type LoadAndPopulateAccountAndVideos = (id: number) => Promise<VideoChannelInstance> 26 export type LoadAndPopulateAccountAndVideos = (id: number) => Promise<VideoChannelInstance>
27 export type LoadByUrl = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance> 27 export type LoadByUrl = (uuid: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance>
28 export type LoadByUUIDOrUrl = (uuid: string, url: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance> 28 export type LoadByUUIDOrUrl = (uuid: string, url: string, t?: Sequelize.Transaction) => Promise<VideoChannelInstance>
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 6d70f2aa2..3cb4a33b9 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -218,7 +218,7 @@ listForApi = function (start: number, count: number, sort: string) {
218 { 218 {
219 model: VideoChannel['sequelize'].models.Account, 219 model: VideoChannel['sequelize'].models.Account,
220 required: true, 220 required: true,
221 include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] 221 include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ]
222 } 222 }
223 ] 223 ]
224 } 224 }
@@ -238,7 +238,7 @@ listByAccount = function (accountId: number) {
238 id: accountId 238 id: accountId
239 }, 239 },
240 required: true, 240 required: true,
241 include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] 241 include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ]
242 } 242 }
243 ] 243 ]
244 } 244 }
@@ -297,7 +297,7 @@ loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Tran
297 model: VideoChannel['sequelize'].models.Account, 297 model: VideoChannel['sequelize'].models.Account,
298 include: [ 298 include: [
299 { 299 {
300 model: VideoChannel['sequelize'].models.Pod, 300 model: VideoChannel['sequelize'].models.Server,
301 required: true, 301 required: true,
302 where: { 302 where: {
303 host: fromHost 303 host: fromHost
@@ -322,7 +322,7 @@ loadByIdAndAccount = function (id: number, accountId: number) {
322 include: [ 322 include: [
323 { 323 {
324 model: VideoChannel['sequelize'].models.Account, 324 model: VideoChannel['sequelize'].models.Account,
325 include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] 325 include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ]
326 } 326 }
327 ] 327 ]
328 } 328 }
@@ -335,7 +335,7 @@ loadAndPopulateAccount = function (id: number) {
335 include: [ 335 include: [
336 { 336 {
337 model: VideoChannel['sequelize'].models.Account, 337 model: VideoChannel['sequelize'].models.Account,
338 include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] 338 include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ]
339 } 339 }
340 ] 340 ]
341 } 341 }
@@ -351,7 +351,7 @@ loadByUUIDAndPopulateAccount = function (uuid: string) {
351 include: [ 351 include: [
352 { 352 {
353 model: VideoChannel['sequelize'].models.Account, 353 model: VideoChannel['sequelize'].models.Account,
354 include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] 354 include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ]
355 } 355 }
356 ] 356 ]
357 } 357 }
@@ -364,7 +364,7 @@ loadAndPopulateAccountAndVideos = function (id: number) {
364 include: [ 364 include: [
365 { 365 {
366 model: VideoChannel['sequelize'].models.Account, 366 model: VideoChannel['sequelize'].models.Account,
367 include: [ { model: VideoChannel['sequelize'].models.Pod, required: false } ] 367 include: [ { model: VideoChannel['sequelize'].models.Server, required: false } ]
368 }, 368 },
369 VideoChannel['sequelize'].models.Video 369 VideoChannel['sequelize'].models.Video
370 ] 370 ]
diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts
index 7243756d2..4df33f801 100644
--- a/server/models/video/video-interface.ts
+++ b/server/models/video/video-interface.ts
@@ -46,7 +46,7 @@ export namespace VideoMethods {
46 46
47 export type ListForApi = (start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> > 47 export type ListForApi = (start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> >
48 export type ListUserVideosForApi = (userId: number, start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> > 48 export type ListUserVideosForApi = (userId: number, start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> >
49 export type SearchAndPopulateAccountAndPodAndTags = ( 49 export type SearchAndPopulateAccountAndServerAndTags = (
50 value: string, 50 value: string,
51 field: string, 51 field: string,
52 start: number, 52 start: number,
@@ -60,8 +60,8 @@ export namespace VideoMethods {
60 export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> 60 export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
61 export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> 61 export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
62 export type LoadAndPopulateAccount = (id: number) => Bluebird<VideoInstance> 62 export type LoadAndPopulateAccount = (id: number) => Bluebird<VideoInstance>
63 export type LoadAndPopulateAccountAndPodAndTags = (id: number) => Bluebird<VideoInstance> 63 export type LoadAndPopulateAccountAndServerAndTags = (id: number) => Bluebird<VideoInstance>
64 export type LoadByUUIDAndPopulateAccountAndPodAndTags = (uuid: string) => Bluebird<VideoInstance> 64 export type LoadByUUIDAndPopulateAccountAndServerAndTags = (uuid: string) => Bluebird<VideoInstance>
65 export type LoadByUUIDOrURL = (uuid: string, url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> 65 export type LoadByUUIDOrURL = (uuid: string, url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
66 66
67 export type RemoveThumbnail = (this: VideoInstance) => Promise<void> 67 export type RemoveThumbnail = (this: VideoInstance) => Promise<void>
@@ -79,14 +79,14 @@ export interface VideoClass {
79 listOwnedByAccount: VideoMethods.ListOwnedByAccount 79 listOwnedByAccount: VideoMethods.ListOwnedByAccount
80 load: VideoMethods.Load 80 load: VideoMethods.Load
81 loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount 81 loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount
82 loadAndPopulateAccountAndPodAndTags: VideoMethods.LoadAndPopulateAccountAndPodAndTags 82 loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags
83 loadByHostAndUUID: VideoMethods.LoadByHostAndUUID 83 loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
84 loadByUUID: VideoMethods.LoadByUUID 84 loadByUUID: VideoMethods.LoadByUUID
85 loadByUrl: VideoMethods.LoadByUrl 85 loadByUrl: VideoMethods.LoadByUrl
86 loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL 86 loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
87 loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID 87 loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
88 loadByUUIDAndPopulateAccountAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndPodAndTags 88 loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags
89 searchAndPopulateAccountAndPodAndTags: VideoMethods.SearchAndPopulateAccountAndPodAndTags 89 searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags
90} 90}
91 91
92export interface VideoAttributes { 92export interface VideoAttributes {
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index dd73dd7ca..86800fb88 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -88,9 +88,9 @@ let loadByUUID: VideoMethods.LoadByUUID
88let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL 88let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
89let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID 89let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
90let loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount 90let loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount
91let loadAndPopulateAccountAndPodAndTags: VideoMethods.LoadAndPopulateAccountAndPodAndTags 91let loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags
92let loadByUUIDAndPopulateAccountAndPodAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndPodAndTags 92let loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags
93let searchAndPopulateAccountAndPodAndTags: VideoMethods.SearchAndPopulateAccountAndPodAndTags 93let searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags
94let removeThumbnail: VideoMethods.RemoveThumbnail 94let removeThumbnail: VideoMethods.RemoveThumbnail
95let removePreview: VideoMethods.RemovePreview 95let removePreview: VideoMethods.RemovePreview
96let removeFile: VideoMethods.RemoveFile 96let removeFile: VideoMethods.RemoveFile
@@ -275,13 +275,13 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
275 listOwnedByAccount, 275 listOwnedByAccount,
276 load, 276 load,
277 loadAndPopulateAccount, 277 loadAndPopulateAccount,
278 loadAndPopulateAccountAndPodAndTags, 278 loadAndPopulateAccountAndServerAndTags,
279 loadByHostAndUUID, 279 loadByHostAndUUID,
280 loadByUUIDOrURL, 280 loadByUUIDOrURL,
281 loadByUUID, 281 loadByUUID,
282 loadLocalVideoByUUID, 282 loadLocalVideoByUUID,
283 loadByUUIDAndPopulateAccountAndPodAndTags, 283 loadByUUIDAndPopulateAccountAndServerAndTags,
284 searchAndPopulateAccountAndPodAndTags 284 searchAndPopulateAccountAndServerAndTags
285 ] 285 ]
286 const instanceMethods = [ 286 const instanceMethods = [
287 createPreview, 287 createPreview,
@@ -477,13 +477,13 @@ getPreviewPath = function (this: VideoInstance) {
477} 477}
478 478
479toFormattedJSON = function (this: VideoInstance) { 479toFormattedJSON = function (this: VideoInstance) {
480 let podHost 480 let serverHost
481 481
482 if (this.VideoChannel.Account.Pod) { 482 if (this.VideoChannel.Account.Server) {
483 podHost = this.VideoChannel.Account.Pod.host 483 serverHost = this.VideoChannel.Account.Server.host
484 } else { 484 } else {
485 // It means it's our video 485 // It means it's our video
486 podHost = CONFIG.WEBSERVER.HOST 486 serverHost = CONFIG.WEBSERVER.HOST
487 } 487 }
488 488
489 const json = { 489 const json = {
@@ -498,7 +498,7 @@ toFormattedJSON = function (this: VideoInstance) {
498 languageLabel: this.getLanguageLabel(), 498 languageLabel: this.getLanguageLabel(),
499 nsfw: this.nsfw, 499 nsfw: this.nsfw,
500 description: this.getTruncatedDescription(), 500 description: this.getTruncatedDescription(),
501 podHost, 501 serverHost,
502 isLocal: this.isOwned(), 502 isLocal: this.isOwned(),
503 account: this.VideoChannel.Account.name, 503 account: this.VideoChannel.Account.name,
504 duration: this.duration, 504 duration: this.duration,
@@ -519,7 +519,7 @@ toFormattedJSON = function (this: VideoInstance) {
519toFormattedDetailsJSON = function (this: VideoInstance) { 519toFormattedDetailsJSON = function (this: VideoInstance) {
520 const formattedJson = this.toFormattedJSON() 520 const formattedJson = this.toFormattedJSON()
521 521
522 // Maybe our pod is not up to date and there are new privacy settings since our version 522 // Maybe our server is not up to date and there are new privacy settings since our version
523 let privacyLabel = VIDEO_PRIVACIES[this.privacy] 523 let privacyLabel = VIDEO_PRIVACIES[this.privacy]
524 if (!privacyLabel) privacyLabel = 'Unknown' 524 if (!privacyLabel) privacyLabel = 'Unknown'
525 525
@@ -721,7 +721,7 @@ getDescriptionPath = function (this: VideoInstance) {
721getCategoryLabel = function (this: VideoInstance) { 721getCategoryLabel = function (this: VideoInstance) {
722 let categoryLabel = VIDEO_CATEGORIES[this.category] 722 let categoryLabel = VIDEO_CATEGORIES[this.category]
723 723
724 // Maybe our pod is not up to date and there are new categories since our version 724 // Maybe our server is not up to date and there are new categories since our version
725 if (!categoryLabel) categoryLabel = 'Misc' 725 if (!categoryLabel) categoryLabel = 'Misc'
726 726
727 return categoryLabel 727 return categoryLabel
@@ -730,7 +730,7 @@ getCategoryLabel = function (this: VideoInstance) {
730getLicenceLabel = function (this: VideoInstance) { 730getLicenceLabel = function (this: VideoInstance) {
731 let licenceLabel = VIDEO_LICENCES[this.licence] 731 let licenceLabel = VIDEO_LICENCES[this.licence]
732 732
733 // Maybe our pod is not up to date and there are new licences since our version 733 // Maybe our server is not up to date and there are new licences since our version
734 if (!licenceLabel) licenceLabel = 'Unknown' 734 if (!licenceLabel) licenceLabel = 'Unknown'
735 735
736 return licenceLabel 736 return licenceLabel
@@ -830,7 +830,7 @@ listForApi = function (start: number, count: number, sort: string) {
830 model: Video['sequelize'].models.Account, 830 model: Video['sequelize'].models.Account,
831 include: [ 831 include: [
832 { 832 {
833 model: Video['sequelize'].models.Pod, 833 model: Video['sequelize'].models.Server,
834 required: false 834 required: false
835 } 835 }
836 ] 836 ]
@@ -866,7 +866,7 @@ loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Tran
866 model: Video['sequelize'].models.Account, 866 model: Video['sequelize'].models.Account,
867 include: [ 867 include: [
868 { 868 {
869 model: Video['sequelize'].models.Pod, 869 model: Video['sequelize'].models.Server,
870 required: true, 870 required: true,
871 where: { 871 where: {
872 host: fromHost 872 host: fromHost
@@ -989,7 +989,7 @@ loadAndPopulateAccount = function (id: number) {
989 return Video.findById(id, options) 989 return Video.findById(id, options)
990} 990}
991 991
992loadAndPopulateAccountAndPodAndTags = function (id: number) { 992loadAndPopulateAccountAndServerAndTags = function (id: number) {
993 const options = { 993 const options = {
994 include: [ 994 include: [
995 { 995 {
@@ -997,7 +997,7 @@ loadAndPopulateAccountAndPodAndTags = function (id: number) {
997 include: [ 997 include: [
998 { 998 {
999 model: Video['sequelize'].models.Account, 999 model: Video['sequelize'].models.Account,
1000 include: [ { model: Video['sequelize'].models.Pod, required: false } ] 1000 include: [ { model: Video['sequelize'].models.Server, required: false } ]
1001 } 1001 }
1002 ] 1002 ]
1003 }, 1003 },
@@ -1009,7 +1009,7 @@ loadAndPopulateAccountAndPodAndTags = function (id: number) {
1009 return Video.findById(id, options) 1009 return Video.findById(id, options)
1010} 1010}
1011 1011
1012loadByUUIDAndPopulateAccountAndPodAndTags = function (uuid: string) { 1012loadByUUIDAndPopulateAccountAndServerAndTags = function (uuid: string) {
1013 const options = { 1013 const options = {
1014 where: { 1014 where: {
1015 uuid 1015 uuid
@@ -1020,7 +1020,7 @@ loadByUUIDAndPopulateAccountAndPodAndTags = function (uuid: string) {
1020 include: [ 1020 include: [
1021 { 1021 {
1022 model: Video['sequelize'].models.Account, 1022 model: Video['sequelize'].models.Account,
1023 include: [ { model: Video['sequelize'].models.Pod, required: false } ] 1023 include: [ { model: Video['sequelize'].models.Server, required: false } ]
1024 } 1024 }
1025 ] 1025 ]
1026 }, 1026 },
@@ -1032,15 +1032,15 @@ loadByUUIDAndPopulateAccountAndPodAndTags = function (uuid: string) {
1032 return Video.findOne(options) 1032 return Video.findOne(options)
1033} 1033}
1034 1034
1035searchAndPopulateAccountAndPodAndTags = function (value: string, field: string, start: number, count: number, sort: string) { 1035searchAndPopulateAccountAndServerAndTags = function (value: string, field: string, start: number, count: number, sort: string) {
1036 const podInclude: Sequelize.IncludeOptions = { 1036 const serverInclude: Sequelize.IncludeOptions = {
1037 model: Video['sequelize'].models.Pod, 1037 model: Video['sequelize'].models.Server,
1038 required: false 1038 required: false
1039 } 1039 }
1040 1040
1041 const accountInclude: Sequelize.IncludeOptions = { 1041 const accountInclude: Sequelize.IncludeOptions = {
1042 model: Video['sequelize'].models.Account, 1042 model: Video['sequelize'].models.Account,
1043 include: [ podInclude ] 1043 include: [ serverInclude ]
1044 } 1044 }
1045 1045
1046 const videoChannelInclude: Sequelize.IncludeOptions = { 1046 const videoChannelInclude: Sequelize.IncludeOptions = {
@@ -1071,13 +1071,13 @@ searchAndPopulateAccountAndPodAndTags = function (value: string, field: string,
1071 )` 1071 )`
1072 ) 1072 )
1073 } else if (field === 'host') { 1073 } else if (field === 'host') {
1074 // FIXME: Include our pod? (not stored in the database) 1074 // FIXME: Include our server? (not stored in the database)
1075 podInclude.where = { 1075 serverInclude.where = {
1076 host: { 1076 host: {
1077 [Sequelize.Op.iLike]: '%' + value + '%' 1077 [Sequelize.Op.iLike]: '%' + value + '%'
1078 } 1078 }
1079 } 1079 }
1080 podInclude.required = true 1080 serverInclude.required = true
1081 } else if (field === 'account') { 1081 } else if (field === 'account') {
1082 accountInclude.where = { 1082 accountInclude.where = {
1083 name: { 1083 name: {
@@ -1123,8 +1123,8 @@ function getBaseUrls (video: VideoInstance) {
1123 baseUrlHttp = CONFIG.WEBSERVER.URL 1123 baseUrlHttp = CONFIG.WEBSERVER.URL
1124 baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT 1124 baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
1125 } else { 1125 } else {
1126 baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + video.VideoChannel.Account.Pod.host 1126 baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + video.VideoChannel.Account.Server.host
1127 baseUrlWs = REMOTE_SCHEME.WS + '://' + video.VideoChannel.Account.Pod.host 1127 baseUrlWs = REMOTE_SCHEME.WS + '://' + video.VideoChannel.Account.Server.host
1128 } 1128 }
1129 1129
1130 return { baseUrlHttp, baseUrlWs } 1130 return { baseUrlHttp, baseUrlWs }