]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/video-channel.ts
Optimize account creation
[github/Chocobozzz/PeerTube.git] / server / lib / video-channel.ts
... / ...
CommitLineData
1import * as Sequelize from 'sequelize'
2
3import { database as db } from '../initializers'
4import { logger } from '../helpers'
5import { AccountInstance } from '../models'
6import { VideoChannelCreate } from '../../shared/models'
7import { sendCreateVideoChannel } from './activitypub/send-request'
8import { getActivityPubUrl, shareVideoChannelByServer } from '../helpers/activitypub'
9
10async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) {
11 const videoChannelData = {
12 name: videoChannelInfo.name,
13 description: videoChannelInfo.description,
14 remote: false,
15 accountId: account.id
16 }
17
18 const videoChannel = db.VideoChannel.build(videoChannelData)
19 videoChannel.set('url', getActivityPubUrl('videoChannel', videoChannel.uuid))
20
21 const options = { transaction: t }
22
23 const videoChannelCreated = await videoChannel.save(options)
24
25 // Do not forget to add Account information to the created video channel
26 videoChannelCreated.Account = account
27
28 // No need to seed this empty video channel to followers
29 return videoChannelCreated
30}
31
32async function fetchVideoChannelByHostAndUUID (serverHost: string, uuid: string, t: Sequelize.Transaction) {
33 try {
34 const videoChannel = await db.VideoChannel.loadByHostAndUUID(serverHost, uuid, t)
35 if (!videoChannel) throw new Error('Video channel not found')
36
37 return videoChannel
38 } catch (err) {
39 logger.error('Cannot load video channel from host and uuid.', { error: err.stack, serverHost, uuid })
40 throw err
41 }
42}
43
44// ---------------------------------------------------------------------------
45
46export {
47 createVideoChannel,
48 fetchVideoChannelByHostAndUUID
49}