PeerTube/server/lib/video-channel.ts

48 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-10-24 19:41:09 +02:00
import * as Sequelize from 'sequelize'
import { database as db } from '../initializers'
2017-10-25 11:55:06 +02:00
import { logger } from '../helpers'
2017-11-09 17:51:58 +01:00
import { AccountInstance } from '../models'
2017-10-24 19:41:09 +02:00
import { VideoChannelCreate } from '../../shared/models'
2017-11-10 17:27:49 +01:00
import { sendCreateVideoChannel } from './activitypub/send-request'
2017-10-24 19:41:09 +02:00
2017-11-09 17:51:58 +01:00
async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) {
2017-10-24 19:41:09 +02:00
const videoChannelData = {
name: videoChannelInfo.name,
description: videoChannelInfo.description,
remote: false,
2017-11-10 14:48:08 +01:00
accountId: account.id
2017-10-24 19:41:09 +02:00
}
const videoChannel = db.VideoChannel.build(videoChannelData)
const options = { transaction: t }
2017-10-25 11:55:06 +02:00
const videoChannelCreated = await videoChannel.save(options)
2017-11-09 17:51:58 +01:00
// Do not forget to add Account information to the created video channel
videoChannelCreated.Account = account
2017-10-25 11:55:06 +02:00
2017-11-10 17:27:49 +01:00
sendCreateVideoChannel(videoChannelCreated, t)
2017-10-25 11:55:06 +02:00
return videoChannelCreated
}
async function fetchVideoChannelByHostAndUUID (podHost: string, uuid: string, t: Sequelize.Transaction) {
try {
const videoChannel = await db.VideoChannel.loadByHostAndUUID(podHost, uuid, t)
if (!videoChannel) throw new Error('Video channel not found')
return videoChannel
} catch (err) {
logger.error('Cannot load video channel from host and uuid.', { error: err.stack, podHost, uuid })
throw err
}
2017-10-24 19:41:09 +02:00
}
// ---------------------------------------------------------------------------
export {
2017-10-25 11:55:06 +02:00
createVideoChannel,
fetchVideoChannelByHostAndUUID
2017-10-24 19:41:09 +02:00
}