aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/video-channel.ts24
-rw-r--r--server/controllers/api/videos/index.ts9
2 files changed, 25 insertions, 8 deletions
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts
index 2454b1ec9..411ec8630 100644
--- a/server/controllers/api/video-channel.ts
+++ b/server/controllers/api/video-channel.ts
@@ -126,7 +126,7 @@ videoChannelRouter.delete('/:nameWithHost',
126 126
127videoChannelRouter.get('/:nameWithHost', 127videoChannelRouter.get('/:nameWithHost',
128 asyncMiddleware(videoChannelsNameWithHostValidator), 128 asyncMiddleware(videoChannelsNameWithHostValidator),
129 getVideoChannel 129 asyncMiddleware(getVideoChannel)
130) 130)
131 131
132videoChannelRouter.get('/:nameWithHost/video-playlists', 132videoChannelRouter.get('/:nameWithHost/video-playlists',
@@ -171,12 +171,19 @@ export {
171 171
172async function listVideoChannels (req: express.Request, res: express.Response) { 172async function listVideoChannels (req: express.Request, res: express.Response) {
173 const serverActor = await getServerActor() 173 const serverActor = await getServerActor()
174 const resultList = await VideoChannelModel.listForApi({ 174
175 const apiOptions = await Hooks.wrapObject({
175 actorId: serverActor.id, 176 actorId: serverActor.id,
176 start: req.query.start, 177 start: req.query.start,
177 count: req.query.count, 178 count: req.query.count,
178 sort: req.query.sort 179 sort: req.query.sort
179 }) 180 }, 'filter:api.video-channels.list.params')
181
182 const resultList = await Hooks.wrapPromiseFun(
183 VideoChannelModel.listForApi,
184 apiOptions,
185 'filter:api.video-channels.list.result'
186 )
180 187
181 return res.json(getFormattedObjects(resultList.data, resultList.total)) 188 return res.json(getFormattedObjects(resultList.data, resultList.total))
182} 189}
@@ -243,6 +250,8 @@ async function addVideoChannel (req: express.Request, res: express.Response) {
243 auditLogger.create(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelCreated.toFormattedJSON())) 250 auditLogger.create(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelCreated.toFormattedJSON()))
244 logger.info('Video channel %s created.', videoChannelCreated.Actor.url) 251 logger.info('Video channel %s created.', videoChannelCreated.Actor.url)
245 252
253 Hooks.runAction('action:api.video-channel.created', { videoChannel: videoChannelCreated, req, res })
254
246 return res.json({ 255 return res.json({
247 videoChannel: { 256 videoChannel: {
248 id: videoChannelCreated.id 257 id: videoChannelCreated.id
@@ -281,6 +290,8 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
281 oldVideoChannelAuditKeys 290 oldVideoChannelAuditKeys
282 ) 291 )
283 292
293 Hooks.runAction('action:api.video-channel.updated', { videoChannel: videoChannelInstanceUpdated, req, res })
294
284 logger.info('Video channel %s updated.', videoChannelInstance.Actor.url) 295 logger.info('Video channel %s updated.', videoChannelInstance.Actor.url)
285 }) 296 })
286 } catch (err) { 297 } catch (err) {
@@ -310,6 +321,8 @@ async function removeVideoChannel (req: express.Request, res: express.Response)
310 321
311 await videoChannelInstance.destroy({ transaction: t }) 322 await videoChannelInstance.destroy({ transaction: t })
312 323
324 Hooks.runAction('action:api.video-channel.deleted', { videoChannel: videoChannelInstance, req, res })
325
313 auditLogger.delete(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelInstance.toFormattedJSON())) 326 auditLogger.delete(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()))
314 logger.info('Video channel %s deleted.', videoChannelInstance.Actor.url) 327 logger.info('Video channel %s deleted.', videoChannelInstance.Actor.url)
315 }) 328 })
@@ -317,8 +330,9 @@ async function removeVideoChannel (req: express.Request, res: express.Response)
317 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() 330 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
318} 331}
319 332
320function getVideoChannel (req: express.Request, res: express.Response) { 333async function getVideoChannel (req: express.Request, res: express.Response) {
321 const videoChannel = res.locals.videoChannel 334 const id = res.locals.videoChannel.id
335 const videoChannel = await Hooks.wrapObject(res.locals.videoChannel, 'filter:api.video-channel.get.result', { id })
322 336
323 if (videoChannel.isOutdated()) { 337 if (videoChannel.isOutdated()) {
324 JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: videoChannel.Actor.url } }) 338 JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: videoChannel.Actor.url } })
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index d4e08293e..eca72c397 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -110,7 +110,7 @@ videosRouter.get('/:id',
110 optionalAuthenticate, 110 optionalAuthenticate,
111 asyncMiddleware(videosCustomGetValidator('for-api')), 111 asyncMiddleware(videosCustomGetValidator('for-api')),
112 asyncMiddleware(checkVideoFollowConstraints), 112 asyncMiddleware(checkVideoFollowConstraints),
113 getVideo 113 asyncMiddleware(getVideo)
114) 114)
115 115
116videosRouter.delete('/:id', 116videosRouter.delete('/:id',
@@ -144,8 +144,11 @@ function listVideoPrivacies (_req: express.Request, res: express.Response) {
144 res.json(VIDEO_PRIVACIES) 144 res.json(VIDEO_PRIVACIES)
145} 145}
146 146
147function getVideo (_req: express.Request, res: express.Response) { 147async function getVideo (_req: express.Request, res: express.Response) {
148 const video = res.locals.videoAPI 148 const videoId = res.locals.videoAPI.id
149 const userId = res.locals.oauth?.token.User.id
150
151 const video = await Hooks.wrapObject(res.locals.videoAPI, 'filter:api.video.get.result', { id: videoId, userId })
149 152
150 if (video.isOutdated()) { 153 if (video.isOutdated()) {
151 JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } }) 154 JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: video.url } })