X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-channel.ts;h=54f12dce3216273d17925ea1e2eaca21e1f9ebc2;hb=c893d4514e6ecbf282c7985fe5f82b8acd8a1137;hp=1f4604f1dc5b038177a0d19a8f6c6a9a81c52663;hpb=efc32059d980c51793e8e9ac0fb6a885a8026f94;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 1f4604f1d..54f12dce3 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -1,24 +1,19 @@ import * as Sequelize from 'sequelize' - -import { isVideoChannelNameValid, isVideoChannelDescriptionValid } from '../../helpers' +import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers' +import { CONSTRAINTS_FIELDS } from '../../initializers/constants' +import { sendDeleteVideoChannel } from '../../lib/activitypub/send/send-delete' import { addMethodsToModel, getSort } from '../utils' -import { - VideoChannelInstance, - VideoChannelAttributes, - - VideoChannelMethods -} from './video-channel-interface' -import { sendDeleteVideoChannel } from '../../lib/activitypub/send-request' -import { isVideoChannelUrlValid } from '../../helpers/custom-validators/video-channels' -import { CONSTRAINTS_FIELDS } from '../../initializers/constants' +import { VideoChannelAttributes, VideoChannelInstance, VideoChannelMethods } from './video-channel-interface' +import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' +import { activityPubCollection } from '../../helpers/activitypub' +import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' let VideoChannel: Sequelize.Model let toFormattedJSON: VideoChannelMethods.ToFormattedJSON let toActivityPubObject: VideoChannelMethods.ToActivityPubObject let isOwned: VideoChannelMethods.IsOwned let countByAccount: VideoChannelMethods.CountByAccount -let listOwned: VideoChannelMethods.ListOwned let listForApi: VideoChannelMethods.ListForApi let listByAccount: VideoChannelMethods.ListByAccount let loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount @@ -71,7 +66,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da allowNull: false, validate: { urlValid: value => { - const res = isVideoChannelUrlValid(value) + const res = isActivityPubUrlValid(value) if (res === false) throw new Error('Video channel URL is not valid.') } } @@ -94,7 +89,6 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da listForApi, listByAccount, - listOwned, loadByIdAndAccount, loadAndPopulateAccount, loadByUUIDAndPopulateAccount, @@ -147,6 +141,18 @@ toFormattedJSON = function (this: VideoChannelInstance) { } toActivityPubObject = function (this: VideoChannelInstance) { + let sharesObject + if (Array.isArray(this.VideoChannelShares)) { + const shares: string[] = [] + + for (const videoChannelShare of this.VideoChannelShares) { + const shareUrl = getAnnounceActivityPubUrl(this.url, videoChannelShare.Account) + shares.push(shareUrl) + } + + sharesObject = activityPubCollection(shares) + } + const json = { type: 'VideoChannel' as 'VideoChannel', id: this.url, @@ -154,7 +160,8 @@ toActivityPubObject = function (this: VideoChannelInstance) { content: this.description, name: this.name, published: this.createdAt.toISOString(), - updated: this.updatedAt.toISOString() + updated: this.updatedAt.toISOString(), + shares: sharesObject } return json @@ -198,17 +205,6 @@ countByAccount = function (accountId: number) { return VideoChannel.count(query) } -listOwned = function () { - const query = { - where: { - remote: false - }, - include: [ VideoChannel['sequelize'].models.Account ] - } - - return VideoChannel.findAll(query) -} - listForApi = function (start: number, count: number, sort: string) { const query = { offset: start, @@ -264,7 +260,8 @@ loadByUrl = function (url: string, t?: Sequelize.Transaction) { const query: Sequelize.FindOptions = { where: { url - } + }, + include: [ VideoChannel['sequelize'].models.Account ] } if (t !== undefined) query.transaction = t