aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-channel.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-24 19:41:09 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 09:11:38 +0200
commit72c7248b6fdcdb2175e726ff51b42e7555f2bd84 (patch)
tree1bfdee99dbe2392cc997edba8e314e2a8a401c72 /server/lib/video-channel.ts
parent8113a93a0d9f31aa9e23702bbc31b8a76275ae22 (diff)
downloadPeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.tar.gz
PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.tar.zst
PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.zip
Add video channels
Diffstat (limited to 'server/lib/video-channel.ts')
-rw-r--r--server/lib/video-channel.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts
new file mode 100644
index 000000000..224179973
--- /dev/null
+++ b/server/lib/video-channel.ts
@@ -0,0 +1,42 @@
1import * as Sequelize from 'sequelize'
2
3import { addVideoChannelToFriends } from './friends'
4import { database as db } from '../initializers'
5import { AuthorInstance } from '../models'
6import { VideoChannelCreate } from '../../shared/models'
7
8function createVideoChannel (videoChannelInfo: VideoChannelCreate, author: AuthorInstance, t: Sequelize.Transaction) {
9 let videoChannelUUID = ''
10
11 const videoChannelData = {
12 name: videoChannelInfo.name,
13 description: videoChannelInfo.description,
14 remote: false,
15 authorId: author.id
16 }
17
18 const videoChannel = db.VideoChannel.build(videoChannelData)
19 const options = { transaction: t }
20
21 return videoChannel.save(options)
22 .then(videoChannelCreated => {
23 // Do not forget to add Author information to the created video channel
24 videoChannelCreated.Author = author
25 videoChannelUUID = videoChannelCreated.uuid
26
27 return videoChannelCreated
28 })
29 .then(videoChannel => {
30 const remoteVideoChannel = videoChannel.toAddRemoteJSON()
31
32 // Now we'll add the video channel's meta data to our friends
33 return addVideoChannelToFriends(remoteVideoChannel, t)
34 })
35 .then(() => videoChannelUUID) // Return video channel UUID
36}
37
38// ---------------------------------------------------------------------------
39
40export {
41 createVideoChannel
42}