]>
Commit | Line | Data |
---|---|---|
72c7248b C |
1 | import * as Sequelize from 'sequelize' |
2 | ||
3 | import { addVideoChannelToFriends } from './friends' | |
4 | import { database as db } from '../initializers' | |
eb080476 | 5 | import { logger } from '../helpers' |
e4f97bab | 6 | import { AccountInstance } from '../models' |
72c7248b C |
7 | import { VideoChannelCreate } from '../../shared/models' |
8 | ||
e4f97bab | 9 | async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) { |
72c7248b C |
10 | const videoChannelData = { |
11 | name: videoChannelInfo.name, | |
12 | description: videoChannelInfo.description, | |
13 | remote: false, | |
38fa2065 | 14 | accountId: account.id |
72c7248b C |
15 | } |
16 | ||
17 | const videoChannel = db.VideoChannel.build(videoChannelData) | |
18 | const options = { transaction: t } | |
19 | ||
eb080476 C |
20 | const videoChannelCreated = await videoChannel.save(options) |
21 | ||
e4f97bab C |
22 | // Do not forget to add Account information to the created video channel |
23 | videoChannelCreated.Account = account | |
eb080476 C |
24 | |
25 | const remoteVideoChannel = videoChannelCreated.toAddRemoteJSON() | |
26 | ||
27 | // Now we'll add the video channel's meta data to our friends | |
28 | await addVideoChannelToFriends(remoteVideoChannel, t) | |
29 | ||
30 | return videoChannelCreated | |
31 | } | |
32 | ||
33 | async function fetchVideoChannelByHostAndUUID (podHost: string, uuid: string, t: Sequelize.Transaction) { | |
34 | try { | |
35 | const videoChannel = await db.VideoChannel.loadByHostAndUUID(podHost, uuid, t) | |
36 | if (!videoChannel) throw new Error('Video channel not found') | |
37 | ||
38 | return videoChannel | |
39 | } catch (err) { | |
40 | logger.error('Cannot load video channel from host and uuid.', { error: err.stack, podHost, uuid }) | |
41 | throw err | |
42 | } | |
72c7248b C |
43 | } |
44 | ||
45 | // --------------------------------------------------------------------------- | |
46 | ||
47 | export { | |
eb080476 C |
48 | createVideoChannel, |
49 | fetchVideoChannelByHostAndUUID | |
72c7248b | 50 | } |