aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
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
parent51548b31815c6f96f314ae96588a9adca150519d (diff)
downloadPeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.tar.gz
PeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.tar.zst
PeerTube-608624252466acf9f1d9ee1c1170bd4fe4d18d18.zip
Rename Pod -> Server
Diffstat (limited to 'server/models/account')
-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
3 files changed, 30 insertions, 22 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