aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-channel.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-14 11:18:49 +0100
committerChocobozzz <me@florianbigard.com>2017-12-19 10:51:09 +0100
commitfadf619ad61a016c1c7fc53de5a8f398a4f77519 (patch)
treebd449b9fe2353d812f4cf57f6dd03c2221b25607 /server/models/video/video-channel.ts
parent7efe153b0bc23e596d5019b9fb3e3e32b6cfeccd (diff)
downloadPeerTube-fadf619ad61a016c1c7fc53de5a8f398a4f77519.tar.gz
PeerTube-fadf619ad61a016c1c7fc53de5a8f398a4f77519.tar.zst
PeerTube-fadf619ad61a016c1c7fc53de5a8f398a4f77519.zip
Save
Diffstat (limited to 'server/models/video/video-channel.ts')
-rw-r--r--server/models/video/video-channel.ts60
1 files changed, 25 insertions, 35 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 068c8029d..fe44d3d53 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -11,18 +11,16 @@ import {
11 HasMany, 11 HasMany,
12 Is, 12 Is,
13 IsUUID, 13 IsUUID,
14 Model, Scopes, 14 Model,
15 Scopes,
15 Table, 16 Table,
16 UpdatedAt 17 UpdatedAt
17} from 'sequelize-typescript' 18} from 'sequelize-typescript'
18import { IFindOptions } from 'sequelize-typescript/lib/interfaces/IFindOptions' 19import { IFindOptions } from 'sequelize-typescript/lib/interfaces/IFindOptions'
19import { activityPubCollection } from '../../helpers'
20import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub'
21import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' 20import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels'
22import { CONSTRAINTS_FIELDS } from '../../initializers'
23import { getAnnounceActivityPubUrl } from '../../lib/activitypub'
24import { sendDeleteVideoChannel } from '../../lib/activitypub/send' 21import { sendDeleteVideoChannel } from '../../lib/activitypub/send'
25import { AccountModel } from '../account/account' 22import { AccountModel } from '../account/account'
23import { ActorModel } from '../activitypub/actor'
26import { ServerModel } from '../server/server' 24import { ServerModel } from '../server/server'
27import { getSort, throwIfNotValid } from '../utils' 25import { getSort, throwIfNotValid } from '../utils'
28import { VideoModel } from './video' 26import { VideoModel } from './video'
@@ -78,17 +76,24 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
78 @Column 76 @Column
79 remote: boolean 77 remote: boolean
80 78
81 @AllowNull(false)
82 @Is('VideoChannelUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
83 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_CHANNELS.URL.max))
84 url: string
85
86 @CreatedAt 79 @CreatedAt
87 createdAt: Date 80 createdAt: Date
88 81
89 @UpdatedAt 82 @UpdatedAt
90 updatedAt: Date 83 updatedAt: Date
91 84
85 @ForeignKey(() => ActorModel)
86 @Column
87 actorId: number
88
89 @BelongsTo(() => ActorModel, {
90 foreignKey: {
91 allowNull: false
92 },
93 onDelete: 'cascade'
94 })
95 Actor: ActorModel
96
92 @ForeignKey(() => AccountModel) 97 @ForeignKey(() => AccountModel)
93 @Column 98 @Column
94 accountId: number 99 accountId: number
@@ -174,9 +179,15 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
174 179
175 static loadByUrl (url: string, t?: Sequelize.Transaction) { 180 static loadByUrl (url: string, t?: Sequelize.Transaction) {
176 const query: IFindOptions<VideoChannelModel> = { 181 const query: IFindOptions<VideoChannelModel> = {
177 where: { 182 include: [
178 url 183 {
179 } 184 model: ActorModel,
185 required: true,
186 where: {
187 url
188 }
189 }
190 ]
180 } 191 }
181 192
182 if (t !== undefined) query.transaction = t 193 if (t !== undefined) query.transaction = t
@@ -264,27 +275,6 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
264 } 275 }
265 276
266 toActivityPubObject () { 277 toActivityPubObject () {
267 let sharesObject 278 return this.Actor.toActivityPubObject(this.name, this.uuid, 'VideoChannel')
268 if (Array.isArray(this.VideoChannelShares)) {
269 const shares: string[] = []
270
271 for (const videoChannelShare of this.VideoChannelShares) {
272 const shareUrl = getAnnounceActivityPubUrl(this.url, videoChannelShare.Account)
273 shares.push(shareUrl)
274 }
275
276 sharesObject = activityPubCollection(shares)
277 }
278
279 return {
280 type: 'VideoChannel' as 'VideoChannel',
281 id: this.url,
282 uuid: this.uuid,
283 content: this.description,
284 name: this.name,
285 published: this.createdAt.toISOString(),
286 updated: this.updatedAt.toISOString(),
287 shares: sharesObject
288 }
289 } 279 }
290} 280}