aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-channel.ts
diff options
context:
space:
mode:
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}