aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
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
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')
-rw-r--r--server/controllers/api/users.ts16
-rw-r--r--server/controllers/api/videos/channel.ts23
-rw-r--r--server/controllers/api/videos/index.ts2
3 files changed, 27 insertions, 14 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index e3067584e..583376c38 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -9,7 +9,7 @@ import { logger } from '../../helpers/logger'
9import { createReqFiles, getFormattedObjects } from '../../helpers/utils' 9import { createReqFiles, getFormattedObjects } from '../../helpers/utils'
10import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers' 10import { AVATARS_SIZE, CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers'
11import { updateActorAvatarInstance } from '../../lib/activitypub' 11import { updateActorAvatarInstance } from '../../lib/activitypub'
12import { sendUpdateUser } from '../../lib/activitypub/send' 12import { sendUpdateActor } from '../../lib/activitypub/send'
13import { Emailer } from '../../lib/emailer' 13import { Emailer } from '../../lib/emailer'
14import { Redis } from '../../lib/redis' 14import { Redis } from '../../lib/redis'
15import { createUserAccountAndChannel } from '../../lib/user' 15import { createUserAccountAndChannel } from '../../lib/user'
@@ -270,15 +270,21 @@ async function removeUser (req: express.Request, res: express.Response, next: ex
270async function updateMe (req: express.Request, res: express.Response, next: express.NextFunction) { 270async function updateMe (req: express.Request, res: express.Response, next: express.NextFunction) {
271 const body: UserUpdateMe = req.body 271 const body: UserUpdateMe = req.body
272 272
273 const user = res.locals.oauth.token.user 273 const user: UserModel = res.locals.oauth.token.user
274 274
275 if (body.password !== undefined) user.password = body.password 275 if (body.password !== undefined) user.password = body.password
276 if (body.email !== undefined) user.email = body.email 276 if (body.email !== undefined) user.email = body.email
277 if (body.displayNSFW !== undefined) user.displayNSFW = body.displayNSFW 277 if (body.displayNSFW !== undefined) user.displayNSFW = body.displayNSFW
278 if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo 278 if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
279 279
280 await user.save() 280 await sequelizeTypescript.transaction(async t => {
281 await sendUpdateUser(user, undefined) 281 await user.save({ transaction: t })
282
283 if (body.description !== undefined) user.Account.description = body.description
284 await user.Account.save({ transaction: t })
285
286 await sendUpdateActor(user.Account, t)
287 })
282 288
283 return res.sendStatus(204) 289 return res.sendStatus(204)
284} 290}
@@ -297,7 +303,7 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next
297 const updatedActor = await updateActorAvatarInstance(actor, avatarName, t) 303 const updatedActor = await updateActorAvatarInstance(actor, avatarName, t)
298 await updatedActor.save({ transaction: t }) 304 await updatedActor.save({ transaction: t })
299 305
300 await sendUpdateUser(user, t) 306 await sendUpdateActor(user.Account, t)
301 307
302 return updatedActor.Avatar 308 return updatedActor.Avatar
303 }) 309 })
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