diff options
Diffstat (limited to 'server/models/video/video-channel.ts')
-rw-r--r-- | server/models/video/video-channel.ts | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index d0dba18d5..0273fab13 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -1,14 +1,27 @@ | |||
1 | import { | 1 | import { |
2 | AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table, | 2 | AllowNull, |
3 | UpdatedAt, Default, DataType | 3 | BeforeDestroy, |
4 | BelongsTo, | ||
5 | Column, | ||
6 | CreatedAt, | ||
7 | DataType, | ||
8 | Default, | ||
9 | DefaultScope, | ||
10 | ForeignKey, | ||
11 | HasMany, | ||
12 | Is, | ||
13 | Model, | ||
14 | Scopes, | ||
15 | Table, | ||
16 | UpdatedAt | ||
4 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
5 | import { ActivityPubActor } from '../../../shared/models/activitypub' | 18 | import { ActivityPubActor } from '../../../shared/models/activitypub' |
6 | import { VideoChannel } from '../../../shared/models/videos' | 19 | import { VideoChannel } from '../../../shared/models/videos' |
7 | import { | 20 | import { |
8 | isVideoChannelDescriptionValid, isVideoChannelNameValid, | 21 | isVideoChannelDescriptionValid, |
22 | isVideoChannelNameValid, | ||
9 | isVideoChannelSupportValid | 23 | isVideoChannelSupportValid |
10 | } from '../../helpers/custom-validators/video-channels' | 24 | } from '../../helpers/custom-validators/video-channels' |
11 | import { logger } from '../../helpers/logger' | ||
12 | import { sendDeleteActor } from '../../lib/activitypub/send' | 25 | import { sendDeleteActor } from '../../lib/activitypub/send' |
13 | import { AccountModel } from '../account/account' | 26 | import { AccountModel } from '../account/account' |
14 | import { ActorModel } from '../activitypub/actor' | 27 | import { ActorModel } from '../activitypub/actor' |
@@ -241,6 +254,23 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
241 | .findById(id, options) | 254 | .findById(id, options) |
242 | } | 255 | } |
243 | 256 | ||
257 | static loadLocalByName (name: string) { | ||
258 | const query = { | ||
259 | include: [ | ||
260 | { | ||
261 | model: ActorModel, | ||
262 | required: true, | ||
263 | where: { | ||
264 | preferredUsername: name, | ||
265 | serverId: null | ||
266 | } | ||
267 | } | ||
268 | ] | ||
269 | } | ||
270 | |||
271 | return VideoChannelModel.findOne(query) | ||
272 | } | ||
273 | |||
244 | toFormattedJSON (): VideoChannel { | 274 | toFormattedJSON (): VideoChannel { |
245 | const actor = this.Actor.toFormattedJSON() | 275 | const actor = this.Actor.toFormattedJSON() |
246 | const videoChannel = { | 276 | const videoChannel = { |
@@ -251,8 +281,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
251 | isLocal: this.Actor.isOwned(), | 281 | isLocal: this.Actor.isOwned(), |
252 | createdAt: this.createdAt, | 282 | createdAt: this.createdAt, |
253 | updatedAt: this.updatedAt, | 283 | updatedAt: this.updatedAt, |
254 | ownerAccount: undefined, | 284 | ownerAccount: undefined |
255 | videos: undefined | ||
256 | } | 285 | } |
257 | 286 | ||
258 | if (this.Account) videoChannel.ownerAccount = this.Account.toFormattedJSON() | 287 | if (this.Account) videoChannel.ownerAccount = this.Account.toFormattedJSON() |