aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/video-channel.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-29 11:29:23 +0200
committerChocobozzz <me@florianbigard.com>2018-06-29 11:29:23 +0200
commit4bbfc6c606c8d3794bae25c64c516120af41f4eb (patch)
tree8d6012f3c04e55e7325e3f00eb9061776cc7a953 /server/controllers/api/video-channel.ts
parent3ff5a19b4c988d6c712b7ce63c4cf04f99d047ce (diff)
downloadPeerTube-4bbfc6c606c8d3794bae25c64c516120af41f4eb.tar.gz
PeerTube-4bbfc6c606c8d3794bae25c64c516120af41f4eb.tar.zst
PeerTube-4bbfc6c606c8d3794bae25c64c516120af41f4eb.zip
API: Add ability to update video channel avatar
Diffstat (limited to 'server/controllers/api/video-channel.ts')
-rw-r--r--server/controllers/api/video-channel.ts30
1 files changed, 28 insertions, 2 deletions
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts
index 61e72125f..1707732ee 100644
--- a/server/controllers/api/video-channel.ts
+++ b/server/controllers/api/video-channel.ts
@@ -19,12 +19,16 @@ import { videosSortValidator } from '../../middlewares/validators'
19import { sendUpdateActor } from '../../lib/activitypub/send' 19import { sendUpdateActor } from '../../lib/activitypub/send'
20import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' 20import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
21import { createVideoChannel } from '../../lib/video-channel' 21import { createVideoChannel } from '../../lib/video-channel'
22import { isNSFWHidden } from '../../helpers/express-utils' 22import { createReqFiles, isNSFWHidden } from '../../helpers/express-utils'
23import { setAsyncActorKeys } from '../../lib/activitypub' 23import { setAsyncActorKeys } from '../../lib/activitypub'
24import { AccountModel } from '../../models/account/account' 24import { AccountModel } from '../../models/account/account'
25import { sequelizeTypescript } from '../../initializers' 25import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers'
26import { logger } from '../../helpers/logger' 26import { logger } from '../../helpers/logger'
27import { VideoModel } from '../../models/video/video' 27import { VideoModel } from '../../models/video/video'
28import { updateAvatarValidator } from '../../middlewares/validators/avatar'
29import { updateActorAvatarFile } from '../../lib/avatar'
30
31const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR })
28 32
29const videoChannelRouter = express.Router() 33const videoChannelRouter = express.Router()
30 34
@@ -42,6 +46,15 @@ videoChannelRouter.post('/',
42 asyncRetryTransactionMiddleware(addVideoChannel) 46 asyncRetryTransactionMiddleware(addVideoChannel)
43) 47)
44 48
49videoChannelRouter.post('/:id/avatar/pick',
50 authenticate,
51 reqAvatarFile,
52 // Check the rights
53 asyncMiddleware(videoChannelsUpdateValidator),
54 updateAvatarValidator,
55 asyncMiddleware(updateVideoChannelAvatar)
56)
57
45videoChannelRouter.put('/:id', 58videoChannelRouter.put('/:id',
46 authenticate, 59 authenticate,
47 asyncMiddleware(videoChannelsUpdateValidator), 60 asyncMiddleware(videoChannelsUpdateValidator),
@@ -83,6 +96,19 @@ async function listVideoChannels (req: express.Request, res: express.Response, n
83 return res.json(getFormattedObjects(resultList.data, resultList.total)) 96 return res.json(getFormattedObjects(resultList.data, resultList.total))
84} 97}
85 98
99async function updateVideoChannelAvatar (req: express.Request, res: express.Response, next: express.NextFunction) {
100 const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
101 const videoChannel = res.locals.videoChannel
102
103 const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel.Actor, videoChannel)
104
105 return res
106 .json({
107 avatar: avatar.toFormattedJSON()
108 })
109 .end()
110}
111
86async function addVideoChannel (req: express.Request, res: express.Response) { 112async function addVideoChannel (req: express.Request, res: express.Response) {
87 const videoChannelInfo: VideoChannelCreate = req.body 113 const videoChannelInfo: VideoChannelCreate = req.body
88 const account: AccountModel = res.locals.oauth.token.User.Account 114 const account: AccountModel = res.locals.oauth.token.User.Account