X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fvideo-channel.ts;h=6f9ae2d95472fe06b5cd163a2c026db18de3b081;hb=47e0652b4a98916d4a1d012fbec61afd73a30565;hp=2241799737b8c80d97be7d44e4a0f2df4e9c8b07;hpb=72c7248b6fdcdb2175e726ff51b42e7555f2bd84;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts index 224179973..6f9ae2d95 100644 --- a/server/lib/video-channel.ts +++ b/server/lib/video-channel.ts @@ -1,42 +1,49 @@ import * as Sequelize from 'sequelize' -import { addVideoChannelToFriends } from './friends' import { database as db } from '../initializers' -import { AuthorInstance } from '../models' +import { logger } from '../helpers' +import { AccountInstance } from '../models' import { VideoChannelCreate } from '../../shared/models' +import { sendCreateVideoChannel } from './activitypub/send-request' +import { getActivityPubUrl, shareVideoChannelByServer } from '../helpers/activitypub' -function createVideoChannel (videoChannelInfo: VideoChannelCreate, author: AuthorInstance, t: Sequelize.Transaction) { - let videoChannelUUID = '' - +async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) { const videoChannelData = { name: videoChannelInfo.name, description: videoChannelInfo.description, remote: false, - authorId: author.id + accountId: account.id } const videoChannel = db.VideoChannel.build(videoChannelData) + videoChannel.set('url', getActivityPubUrl('videoChannel', videoChannel.uuid)) + const options = { transaction: t } - return videoChannel.save(options) - .then(videoChannelCreated => { - // Do not forget to add Author information to the created video channel - videoChannelCreated.Author = author - videoChannelUUID = videoChannelCreated.uuid - - return videoChannelCreated - }) - .then(videoChannel => { - const remoteVideoChannel = videoChannel.toAddRemoteJSON() - - // Now we'll add the video channel's meta data to our friends - return addVideoChannelToFriends(remoteVideoChannel, t) - }) - .then(() => videoChannelUUID) // Return video channel UUID + const videoChannelCreated = await videoChannel.save(options) + + // Do not forget to add Account information to the created video channel + videoChannelCreated.Account = account + + // No need to seed this empty video channel to followers + return videoChannelCreated +} + +async function fetchVideoChannelByHostAndUUID (serverHost: string, uuid: string, t: Sequelize.Transaction) { + try { + const videoChannel = await db.VideoChannel.loadByHostAndUUID(serverHost, uuid, t) + if (!videoChannel) throw new Error('Video channel not found') + + return videoChannel + } catch (err) { + logger.error('Cannot load video channel from host and uuid.', { error: err.stack, serverHost, uuid }) + throw err + } } // --------------------------------------------------------------------------- export { - createVideoChannel + createVideoChannel, + fetchVideoChannelByHostAndUUID }