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