aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account.ts
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/account/account.ts
parent51548b31815c6f96f314ae96588a9adca150519d (diff)
downloadPeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.tar.gz
PeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.tar.zst
PeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.zip
Rename Pod -> Server
Diffstat (limited to 'server/models/account/account.ts')
-rw-r--r--server/models/account/account.ts37
1 files changed, 23 insertions, 14 deletions
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