1
0
Fork 0
peertube/server/lib/video-channel.ts

41 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-10-24 17:41:09 +00:00
import * as Sequelize from 'sequelize'
2017-12-14 16:38:41 +00:00
import * as uuidv4 from 'uuid/v4'
2017-11-17 14:52:26 +00:00
import { VideoChannelCreate } from '../../shared/models'
2017-12-12 16:53:50 +00:00
import { AccountModel } from '../models/account/account'
import { VideoChannelModel } from '../models/video/video-channel'
2017-12-14 16:38:41 +00:00
import { buildActorInstance, getVideoChannelActivityPubUrl } from './activitypub'
2017-10-24 17:41:09 +00:00
2017-12-12 16:53:50 +00:00
async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) {
2017-12-14 16:38:41 +00:00
const uuid = uuidv4()
const url = getVideoChannelActivityPubUrl(uuid)
// We use the name as uuid
const actorInstance = buildActorInstance('Group', url, uuid, uuid)
const actorInstanceCreated = await actorInstance.save({ transaction: t })
2017-10-24 17:41:09 +00:00
const videoChannelData = {
name: videoChannelInfo.name,
description: videoChannelInfo.description,
2017-12-14 16:38:41 +00:00
accountId: account.id,
actorId: actorInstanceCreated.id
2017-10-24 17:41:09 +00:00
}
2017-12-12 16:53:50 +00:00
const videoChannel = VideoChannelModel.build(videoChannelData)
2017-11-14 09:57:56 +00:00
2017-10-24 17:41:09 +00:00
const options = { transaction: t }
2017-10-25 09:55:06 +00:00
const videoChannelCreated = await videoChannel.save(options)
2017-12-14 16:38:41 +00:00
// Do not forget to add Account/Actor information to the created video channel
2017-11-09 16:51:58 +00:00
videoChannelCreated.Account = account
2017-12-14 16:38:41 +00:00
videoChannelCreated.Actor = actorInstanceCreated
2017-10-25 09:55:06 +00:00
2017-11-16 17:40:50 +00:00
// No need to seed this empty video channel to followers
2017-10-25 09:55:06 +00:00
return videoChannelCreated
}
2017-10-24 17:41:09 +00:00
// ---------------------------------------------------------------------------
export {
2017-11-23 16:36:15 +00:00
createVideoChannel
2017-10-24 17:41:09 +00:00
}