]>
Commit | Line | Data |
---|---|---|
72c7248b | 1 | import * as Sequelize from 'sequelize' |
79d5caf9 | 2 | import { VideoChannelCreate } from '../../shared/models' |
eb080476 | 3 | import { logger } from '../helpers' |
79d5caf9 C |
4 | import { getActivityPubUrl } from '../helpers/activitypub' |
5 | import { database as db } from '../initializers' | |
e4f97bab | 6 | import { AccountInstance } from '../models' |
72c7248b | 7 | |
e4f97bab | 8 | async 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) | |
e34c85e5 C |
17 | videoChannel.set('url', getActivityPubUrl('videoChannel', videoChannel.uuid)) |
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 | 30 | async 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 | ||
44 | export { | |
eb080476 C |
45 | createVideoChannel, |
46 | fetchVideoChannelByHostAndUUID | |
72c7248b | 47 | } |