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