From 06a05d5f4784a7cbb27aa1188385b5679845dad8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Aug 2018 15:25:20 +0200 Subject: Add subscriptions endpoints to REST API --- server/models/video/video-channel.ts | 41 ++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'server/models/video/video-channel.ts') 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 @@ import { - AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table, - UpdatedAt, Default, DataType + AllowNull, + BeforeDestroy, + BelongsTo, + Column, + CreatedAt, + DataType, + Default, + DefaultScope, + ForeignKey, + HasMany, + Is, + Model, + Scopes, + Table, + UpdatedAt } from 'sequelize-typescript' import { ActivityPubActor } from '../../../shared/models/activitypub' import { VideoChannel } from '../../../shared/models/videos' import { - isVideoChannelDescriptionValid, isVideoChannelNameValid, + isVideoChannelDescriptionValid, + isVideoChannelNameValid, isVideoChannelSupportValid } from '../../helpers/custom-validators/video-channels' -import { logger } from '../../helpers/logger' import { sendDeleteActor } from '../../lib/activitypub/send' import { AccountModel } from '../account/account' import { ActorModel } from '../activitypub/actor' @@ -241,6 +254,23 @@ export class VideoChannelModel extends Model { .findById(id, options) } + static loadLocalByName (name: string) { + const query = { + include: [ + { + model: ActorModel, + required: true, + where: { + preferredUsername: name, + serverId: null + } + } + ] + } + + return VideoChannelModel.findOne(query) + } + toFormattedJSON (): VideoChannel { const actor = this.Actor.toFormattedJSON() const videoChannel = { @@ -251,8 +281,7 @@ export class VideoChannelModel extends Model { isLocal: this.Actor.isOwned(), createdAt: this.createdAt, updatedAt: this.updatedAt, - ownerAccount: undefined, - videos: undefined + ownerAccount: undefined } if (this.Account) videoChannel.ownerAccount = this.Account.toFormattedJSON() -- cgit v1.2.3