aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-channel.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-25 11:55:06 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 09:11:38 +0200
commiteb08047657e739bcd9e592d76307befa3998482b (patch)
treefc309f51ece792fd4307c4af510710a853e1d6b2 /server/lib/video-channel.ts
parent5f04dd2f743961e0a06c29531cc3ccc9e4928d56 (diff)
downloadPeerTube-eb08047657e739bcd9e592d76307befa3998482b.tar.gz
PeerTube-eb08047657e739bcd9e592d76307befa3998482b.tar.zst
PeerTube-eb08047657e739bcd9e592d76307befa3998482b.zip
Use async/await in controllers
Diffstat (limited to 'server/lib/video-channel.ts')
-rw-r--r--server/lib/video-channel.ts46
1 files changed, 27 insertions, 19 deletions
diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts
index 224179973..678ffe643 100644
--- a/server/lib/video-channel.ts
+++ b/server/lib/video-channel.ts
@@ -2,12 +2,11 @@ import * as Sequelize from 'sequelize'
2 2
3import { addVideoChannelToFriends } from './friends' 3import { addVideoChannelToFriends } from './friends'
4import { database as db } from '../initializers' 4import { database as db } from '../initializers'
5import { logger } from '../helpers'
5import { AuthorInstance } from '../models' 6import { AuthorInstance } from '../models'
6import { VideoChannelCreate } from '../../shared/models' 7import { VideoChannelCreate } from '../../shared/models'
7 8
8function createVideoChannel (videoChannelInfo: VideoChannelCreate, author: AuthorInstance, t: Sequelize.Transaction) { 9async function createVideoChannel (videoChannelInfo: VideoChannelCreate, author: AuthorInstance, t: Sequelize.Transaction) {
9 let videoChannelUUID = ''
10
11 const videoChannelData = { 10 const videoChannelData = {
12 name: videoChannelInfo.name, 11 name: videoChannelInfo.name,
13 description: videoChannelInfo.description, 12 description: videoChannelInfo.description,
@@ -18,25 +17,34 @@ function createVideoChannel (videoChannelInfo: VideoChannelCreate, author: Autho
18 const videoChannel = db.VideoChannel.build(videoChannelData) 17 const videoChannel = db.VideoChannel.build(videoChannelData)
19 const options = { transaction: t } 18 const options = { transaction: t }
20 19
21 return videoChannel.save(options) 20 const videoChannelCreated = await videoChannel.save(options)
22 .then(videoChannelCreated => { 21
23 // Do not forget to add Author information to the created video channel 22 // Do not forget to add Author information to the created video channel
24 videoChannelCreated.Author = author 23 videoChannelCreated.Author = author
25 videoChannelUUID = videoChannelCreated.uuid 24
26 25 const remoteVideoChannel = videoChannelCreated.toAddRemoteJSON()
27 return videoChannelCreated 26
28 }) 27 // Now we'll add the video channel's meta data to our friends
29 .then(videoChannel => { 28 await addVideoChannelToFriends(remoteVideoChannel, t)
30 const remoteVideoChannel = videoChannel.toAddRemoteJSON() 29
31 30 return videoChannelCreated
32 // Now we'll add the video channel's meta data to our friends 31}
33 return addVideoChannelToFriends(remoteVideoChannel, t) 32
34 }) 33async function fetchVideoChannelByHostAndUUID (podHost: string, uuid: string, t: Sequelize.Transaction) {
35 .then(() => videoChannelUUID) // Return video channel UUID 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 }
36} 43}
37 44
38// --------------------------------------------------------------------------- 45// ---------------------------------------------------------------------------
39 46
40export { 47export {
41 createVideoChannel 48 createVideoChannel,
49 fetchVideoChannelByHostAndUUID
42} 50}