aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-15 14:46:26 +0100
committerChocobozzz <me@florianbigard.com>2018-02-15 15:29:07 +0100
commit2422c46b27790d94fd29a7092170cee5a1b56008 (patch)
treed5c1942ce20cadb27a551d87c789edfe92f5b105 /server/controllers/api/videos
parent34cbef8c6cc912143a421413bdd832c4adcc556a (diff)
downloadPeerTube-2422c46b27790d94fd29a7092170cee5a1b56008.tar.gz
PeerTube-2422c46b27790d94fd29a7092170cee5a1b56008.tar.zst
PeerTube-2422c46b27790d94fd29a7092170cee5a1b56008.zip
Implement support field in video and video channel
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/channel.ts23
-rw-r--r--server/controllers/api/videos/index.ts2
2 files changed, 16 insertions, 9 deletions
diff --git a/server/controllers/api/videos/channel.ts b/server/controllers/api/videos/channel.ts
index 8ec53d9ae..fba5681de 100644
--- a/server/controllers/api/videos/channel.ts
+++ b/server/controllers/api/videos/channel.ts
@@ -5,6 +5,7 @@ import { logger } from '../../../helpers/logger'
5import { getFormattedObjects, resetSequelizeInstance } from '../../../helpers/utils' 5import { getFormattedObjects, resetSequelizeInstance } from '../../../helpers/utils'
6import { sequelizeTypescript } from '../../../initializers' 6import { sequelizeTypescript } from '../../../initializers'
7import { setAsyncActorKeys } from '../../../lib/activitypub' 7import { setAsyncActorKeys } from '../../../lib/activitypub'
8import { sendUpdateActor } from '../../../lib/activitypub/send'
8import { createVideoChannel } from '../../../lib/video-channel' 9import { createVideoChannel } from '../../../lib/video-channel'
9import { 10import {
10 asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setDefaultSort, setDefaultPagination, 11 asyncMiddleware, authenticate, listVideoAccountChannelsValidator, paginationValidator, setDefaultSort, setDefaultPagination,
@@ -80,23 +81,28 @@ async function addVideoChannelRetryWrapper (req: express.Request, res: express.R
80 errorMessage: 'Cannot insert the video video channel with many retries.' 81 errorMessage: 'Cannot insert the video video channel with many retries.'
81 } 82 }
82 83
83 await retryTransactionWrapper(addVideoChannel, options) 84 const videoChannel = await retryTransactionWrapper(addVideoChannel, options)
84 85 return res.json({
85 // TODO : include Location of the new video channel -> 201 86 videoChannel: {
86 return res.type('json').status(204).end() 87 id: videoChannel.id
88 }
89 }).end()
87} 90}
88 91
89async function addVideoChannel (req: express.Request, res: express.Response) { 92async function addVideoChannel (req: express.Request, res: express.Response) {
90 const videoChannelInfo: VideoChannelCreate = req.body 93 const videoChannelInfo: VideoChannelCreate = req.body
91 const account: AccountModel = res.locals.oauth.token.User.Account 94 const account: AccountModel = res.locals.oauth.token.User.Account
92 95
93 const videoChannelCreated = await sequelizeTypescript.transaction(async t => { 96 const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => {
94 return createVideoChannel(videoChannelInfo, account, t) 97 return createVideoChannel(videoChannelInfo, account, t)
95 }) 98 })
96 99
97 setAsyncActorKeys(videoChannelCreated.Actor) 100 setAsyncActorKeys(videoChannelCreated.Actor)
101 .catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, err))
98 102
99 logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid) 103 logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid)
104
105 return videoChannelCreated
100} 106}
101 107
102async function updateVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { 108async function updateVideoChannelRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -123,11 +129,10 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
123 129
124 if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name) 130 if (videoChannelInfoToUpdate.name !== undefined) videoChannelInstance.set('name', videoChannelInfoToUpdate.name)
125 if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description) 131 if (videoChannelInfoToUpdate.description !== undefined) videoChannelInstance.set('description', videoChannelInfoToUpdate.description)
132 if (videoChannelInfoToUpdate.support !== undefined) videoChannelInstance.set('support', videoChannelInfoToUpdate.support)
126 133
127 await videoChannelInstance.save(sequelizeOptions) 134 const videoChannelInstanceUpdated = await videoChannelInstance.save(sequelizeOptions)
128 135 await sendUpdateActor(videoChannelInstanceUpdated, t)
129 // TODO
130 // await sendUpdateVideoChannel(videoChannelInstanceUpdated, t)
131 }) 136 })
132 137
133 logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid) 138 logger.info('Video channel with name %s and uuid %s updated.', videoChannelInstance.name, videoChannelInstance.Actor.uuid)
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 564ccd3f8..c9334676e 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -178,6 +178,7 @@ async function addVideo (req: express.Request, res: express.Response, videoPhysi
178 commentsEnabled: videoInfo.commentsEnabled, 178 commentsEnabled: videoInfo.commentsEnabled,
179 nsfw: videoInfo.nsfw, 179 nsfw: videoInfo.nsfw,
180 description: videoInfo.description, 180 description: videoInfo.description,
181 support: videoInfo.support,
181 privacy: videoInfo.privacy, 182 privacy: videoInfo.privacy,
182 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware 183 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
183 channelId: res.locals.videoChannel.id 184 channelId: res.locals.videoChannel.id
@@ -306,6 +307,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
306 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language) 307 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
307 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw) 308 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
308 if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', parseInt(videoInfoToUpdate.privacy.toString(), 10)) 309 if (videoInfoToUpdate.privacy !== undefined) videoInstance.set('privacy', parseInt(videoInfoToUpdate.privacy.toString(), 10))
310 if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support)
309 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description) 311 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
310 if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled) 312 if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled)
311 313