import * as Sequelize from 'sequelize'
import { isVideoChannelNameValid, isVideoChannelDescriptionValid } from '../../helpers'
-import { removeVideoChannelToFriends } from '../../lib'
import { addMethodsToModel, getSort } from '../utils'
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<VideoChannelInstance, VideoChannelAttributes>
let toFormattedJSON: VideoChannelMethods.ToFormattedJSON
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.')
+ }
}
}
},
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
function afterDestroy (videoChannel: VideoChannelInstance) {
if (videoChannel.isOwned()) {
- const removeVideoChannelToFriendsParams = {
- uuid: videoChannel.uuid
- }
-
- return removeVideoChannelToFriends(removeVideoChannelToFriendsParams)
+ return sendDeleteVideoChannel(videoChannel, undefined)
}
return undefined
{ uuid },
{ url }
]
- },
+ }
}
if (t !== undefined) query.transaction = t