X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-channel.ts;h=6d70f2aa2e77f23b4570bc474491fa3945a2ed29;hb=e34c85e527100c0b5c44567bd951e95be41b8d7e;hp=93a611fa03373154736a528beae477c30d760394;hpb=0d0e8dd0904b380b70e19ebcb4763d65601c4632;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 93a611fa0..6d70f2aa2 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -1,7 +1,6 @@ import * as Sequelize from 'sequelize' import { isVideoChannelNameValid, isVideoChannelDescriptionValid } from '../../helpers' -import { removeVideoChannelToFriends } from '../../lib' import { addMethodsToModel, getSort } from '../utils' import { @@ -10,6 +9,9 @@ import { 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' let VideoChannel: Sequelize.Model let toFormattedJSON: VideoChannelMethods.ToFormattedJSON @@ -65,10 +67,13 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da defaultValue: false }, url: { - type: DataTypes.STRING, + type: DataTypes.STRING(CONSTRAINTS_FIELDS.VIDEO_CHANNELS.URL.max), allowNull: false, validate: { - isUrl: true + urlValid: value => { + const res = isVideoChannelUrlValid(value) + if (res === false) throw new Error('Video channel URL is not valid.') + } } } }, @@ -143,12 +148,13 @@ toFormattedJSON = function (this: VideoChannelInstance) { toActivityPubObject = function (this: VideoChannelInstance) { const json = { + type: 'VideoChannel' as 'VideoChannel', + id: this.url, uuid: this.uuid, + content: this.description, name: this.name, - description: this.description, - createdAt: this.createdAt, - updatedAt: this.updatedAt, - ownerUUID: this.Account.uuid + published: this.createdAt, + updated: this.updatedAt } return json @@ -176,11 +182,7 @@ function associate (models) { function afterDestroy (videoChannel: VideoChannelInstance) { if (videoChannel.isOwned()) { - const removeVideoChannelToFriendsParams = { - uuid: videoChannel.uuid - } - - return removeVideoChannelToFriends(removeVideoChannelToFriendsParams) + return sendDeleteVideoChannel(videoChannel, undefined) } return undefined @@ -277,7 +279,7 @@ loadByUUIDOrUrl = function (uuid: string, url: string, t?: Sequelize.Transaction { uuid }, { url } ] - }, + } } if (t !== undefined) query.transaction = t