diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-26 10:55:40 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-03-18 11:17:59 +0100 |
commit | 418d092afa81e2c8fe8ac6838fc4b5eb0af6a782 (patch) | |
tree | 5e9bc5604fd5d66a006cfebb7acdbdd5486e5d1e /server/models/account | |
parent | b427febb4d5cebf03b815bca2c59af6e82491569 (diff) | |
download | PeerTube-418d092afa81e2c8fe8ac6838fc4b5eb0af6a782.tar.gz PeerTube-418d092afa81e2c8fe8ac6838fc4b5eb0af6a782.tar.zst PeerTube-418d092afa81e2c8fe8ac6838fc4b5eb0af6a782.zip |
Playlist server API
Diffstat (limited to 'server/models/account')
-rw-r--r-- | server/models/account/account.ts | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index ee22d8528..3fb766c8a 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts | |||
@@ -10,11 +10,11 @@ import { | |||
10 | ForeignKey, | 10 | ForeignKey, |
11 | HasMany, | 11 | HasMany, |
12 | Is, | 12 | Is, |
13 | Model, | 13 | Model, Scopes, |
14 | Table, | 14 | Table, |
15 | UpdatedAt | 15 | UpdatedAt |
16 | } from 'sequelize-typescript' | 16 | } from 'sequelize-typescript' |
17 | import { Account } from '../../../shared/models/actors' | 17 | import { Account, AccountSummary } from '../../../shared/models/actors' |
18 | import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts' | 18 | import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts' |
19 | import { sendDeleteActor } from '../../lib/activitypub/send' | 19 | import { sendDeleteActor } from '../../lib/activitypub/send' |
20 | import { ActorModel } from '../activitypub/actor' | 20 | import { ActorModel } from '../activitypub/actor' |
@@ -25,6 +25,13 @@ import { VideoChannelModel } from '../video/video-channel' | |||
25 | import { VideoCommentModel } from '../video/video-comment' | 25 | import { VideoCommentModel } from '../video/video-comment' |
26 | import { UserModel } from './user' | 26 | import { UserModel } from './user' |
27 | import { CONFIG } from '../../initializers' | 27 | import { CONFIG } from '../../initializers' |
28 | import { AvatarModel } from '../avatar/avatar' | ||
29 | import { WhereOptions } from 'sequelize' | ||
30 | import { VideoPlaylistModel } from '../video/video-playlist' | ||
31 | |||
32 | export enum ScopeNames { | ||
33 | SUMMARY = 'SUMMARY' | ||
34 | } | ||
28 | 35 | ||
29 | @DefaultScope({ | 36 | @DefaultScope({ |
30 | include: [ | 37 | include: [ |
@@ -34,6 +41,32 @@ import { CONFIG } from '../../initializers' | |||
34 | } | 41 | } |
35 | ] | 42 | ] |
36 | }) | 43 | }) |
44 | @Scopes({ | ||
45 | [ ScopeNames.SUMMARY ]: (whereActor?: WhereOptions<ActorModel>) => { | ||
46 | return { | ||
47 | attributes: [ 'id', 'name' ], | ||
48 | include: [ | ||
49 | { | ||
50 | attributes: [ 'id', 'uuid', 'preferredUsername', 'url', 'serverId', 'avatarId' ], | ||
51 | model: ActorModel.unscoped(), | ||
52 | required: true, | ||
53 | where: whereActor, | ||
54 | include: [ | ||
55 | { | ||
56 | attributes: [ 'host' ], | ||
57 | model: ServerModel.unscoped(), | ||
58 | required: false | ||
59 | }, | ||
60 | { | ||
61 | model: AvatarModel.unscoped(), | ||
62 | required: false | ||
63 | } | ||
64 | ] | ||
65 | } | ||
66 | ] | ||
67 | } | ||
68 | } | ||
69 | }) | ||
37 | @Table({ | 70 | @Table({ |
38 | tableName: 'account', | 71 | tableName: 'account', |
39 | indexes: [ | 72 | indexes: [ |
@@ -112,6 +145,15 @@ export class AccountModel extends Model<AccountModel> { | |||
112 | }) | 145 | }) |
113 | VideoChannels: VideoChannelModel[] | 146 | VideoChannels: VideoChannelModel[] |
114 | 147 | ||
148 | @HasMany(() => VideoPlaylistModel, { | ||
149 | foreignKey: { | ||
150 | allowNull: false | ||
151 | }, | ||
152 | onDelete: 'cascade', | ||
153 | hooks: true | ||
154 | }) | ||
155 | VideoPlaylists: VideoPlaylistModel[] | ||
156 | |||
115 | @HasMany(() => VideoCommentModel, { | 157 | @HasMany(() => VideoCommentModel, { |
116 | foreignKey: { | 158 | foreignKey: { |
117 | allowNull: false | 159 | allowNull: false |
@@ -285,6 +327,20 @@ export class AccountModel extends Model<AccountModel> { | |||
285 | return Object.assign(actor, account) | 327 | return Object.assign(actor, account) |
286 | } | 328 | } |
287 | 329 | ||
330 | toFormattedSummaryJSON (): AccountSummary { | ||
331 | const actor = this.Actor.toFormattedJSON() | ||
332 | |||
333 | return { | ||
334 | id: this.id, | ||
335 | uuid: actor.uuid, | ||
336 | name: actor.name, | ||
337 | displayName: this.getDisplayName(), | ||
338 | url: actor.url, | ||
339 | host: actor.host, | ||
340 | avatar: actor.avatar | ||
341 | } | ||
342 | } | ||
343 | |||
288 | toActivityPubObject () { | 344 | toActivityPubObject () { |
289 | const obj = this.Actor.toActivityPubObject(this.name, 'Account') | 345 | const obj = this.Actor.toActivityPubObject(this.name, 'Account') |
290 | 346 | ||