aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorlutangar <johan.dufour@gmail.com>2021-11-24 14:33:14 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-11-25 09:54:22 +0100
commit7226e90fdc61a3c6cad5ccab18b6707d55cf0992 (patch)
tree0bdd7304352b1af2d9ae87439486a138e02d46e8 /server/controllers/api/videos
parent5098098d96164c93f84ec8419e98fbd83ba8dc71 (diff)
downloadPeerTube-7226e90fdc61a3c6cad5ccab18b6707d55cf0992.tar.gz
PeerTube-7226e90fdc61a3c6cad5ccab18b6707d55cf0992.tar.zst
PeerTube-7226e90fdc61a3c6cad5ccab18b6707d55cf0992.zip
Add `req` and `res` as controllers hooks parameters
Hooks prefixed by `action:api` now give access the original express req and res. Checkout guide.md for possible usage.
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/comment.ts6
-rw-r--r--server/controllers/api/videos/index.ts6
-rw-r--r--server/controllers/api/videos/live.ts2
-rw-r--r--server/controllers/api/videos/update.ts2
-rw-r--r--server/controllers/api/videos/upload.ts9
5 files changed, 13 insertions, 12 deletions
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index 23bba9089..47fa2f2e2 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -192,7 +192,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons
192 Notifier.Instance.notifyOnNewComment(comment) 192 Notifier.Instance.notifyOnNewComment(comment)
193 auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) 193 auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
194 194
195 Hooks.runAction('action:api.video-thread.created', { comment }) 195 Hooks.runAction('action:api.video-thread.created', { comment, req, res })
196 196
197 return res.json({ comment: comment.toFormattedJSON() }) 197 return res.json({ comment: comment.toFormattedJSON() })
198} 198}
@@ -214,7 +214,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response
214 Notifier.Instance.notifyOnNewComment(comment) 214 Notifier.Instance.notifyOnNewComment(comment)
215 auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) 215 auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
216 216
217 Hooks.runAction('action:api.video-comment-reply.created', { comment }) 217 Hooks.runAction('action:api.video-comment-reply.created', { comment, req, res })
218 218
219 return res.json({ comment: comment.toFormattedJSON() }) 219 return res.json({ comment: comment.toFormattedJSON() })
220} 220}
@@ -222,7 +222,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response
222async function removeVideoComment (req: express.Request, res: express.Response) { 222async function removeVideoComment (req: express.Request, res: express.Response) {
223 const videoCommentInstance = res.locals.videoCommentFull 223 const videoCommentInstance = res.locals.videoCommentFull
224 224
225 await removeComment(videoCommentInstance) 225 await removeComment(videoCommentInstance, req, res)
226 226
227 auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) 227 auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON()))
228 228
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index fc1bcc73d..61a030ba1 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -158,7 +158,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
158 const serverActor = await getServerActor() 158 const serverActor = await getServerActor()
159 await sendView(serverActor, video, undefined) 159 await sendView(serverActor, video, undefined)
160 160
161 Hooks.runAction('action:api.video.viewed', { video: video, ip }) 161 Hooks.runAction('action:api.video.viewed', { video: video, ip, req, res })
162 } 162 }
163 163
164 return res.status(HttpStatusCode.NO_CONTENT_204).end() 164 return res.status(HttpStatusCode.NO_CONTENT_204).end()
@@ -201,7 +201,7 @@ async function listVideos (req: express.Request, res: express.Response) {
201 return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query))) 201 return res.json(getFormattedObjects(resultList.data, resultList.total, guessAdditionalAttributesFromQuery(query)))
202} 202}
203 203
204async function removeVideo (_req: express.Request, res: express.Response) { 204async function removeVideo (req: express.Request, res: express.Response) {
205 const videoInstance = res.locals.videoAll 205 const videoInstance = res.locals.videoAll
206 206
207 await sequelizeTypescript.transaction(async t => { 207 await sequelizeTypescript.transaction(async t => {
@@ -211,7 +211,7 @@ async function removeVideo (_req: express.Request, res: express.Response) {
211 auditLogger.delete(getAuditIdFromRes(res), new VideoAuditView(videoInstance.toFormattedDetailsJSON())) 211 auditLogger.delete(getAuditIdFromRes(res), new VideoAuditView(videoInstance.toFormattedDetailsJSON()))
212 logger.info('Video with name %s and uuid %s deleted.', videoInstance.name, videoInstance.uuid) 212 logger.info('Video with name %s and uuid %s deleted.', videoInstance.name, videoInstance.uuid)
213 213
214 Hooks.runAction('action:api.video.deleted', { video: videoInstance }) 214 Hooks.runAction('action:api.video.deleted', { video: videoInstance, req, res })
215 215
216 return res.type('json') 216 return res.type('json')
217 .status(HttpStatusCode.NO_CONTENT_204) 217 .status(HttpStatusCode.NO_CONTENT_204)
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts
index efafe64e9..e29615ff5 100644
--- a/server/controllers/api/videos/live.ts
+++ b/server/controllers/api/videos/live.ts
@@ -133,7 +133,7 @@ async function addLiveVideo (req: express.Request, res: express.Response) {
133 return { videoCreated } 133 return { videoCreated }
134 }) 134 })
135 135
136 Hooks.runAction('action:api.live-video.created', { video: videoCreated }) 136 Hooks.runAction('action:api.live-video.created', { video: videoCreated, req, res })
137 137
138 return res.json({ 138 return res.json({
139 video: { 139 video: {
diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts
index de5d94d55..3fcff3e86 100644
--- a/server/controllers/api/videos/update.ts
+++ b/server/controllers/api/videos/update.ts
@@ -153,7 +153,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
153 Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) 153 Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
154 } 154 }
155 155
156 Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body }) 156 Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res })
157 } catch (err) { 157 } catch (err) {
158 // Force fields we want to update 158 // Force fields we want to update
159 // If the transaction is retried, sequelize will think the object has not changed 159 // If the transaction is retried, sequelize will think the object has not changed
diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts
index 3e9979330..6773b500f 100644
--- a/server/controllers/api/videos/upload.ts
+++ b/server/controllers/api/videos/upload.ts
@@ -129,7 +129,7 @@ async function addVideoLegacy (req: express.Request, res: express.Response) {
129 const videoInfo: VideoCreate = req.body 129 const videoInfo: VideoCreate = req.body
130 const files = req.files 130 const files = req.files
131 131
132 const response = await addVideo({ res, videoPhysicalFile, videoInfo, files }) 132 const response = await addVideo({ req, res, videoPhysicalFile, videoInfo, files })
133 133
134 return res.json(response) 134 return res.json(response)
135} 135}
@@ -139,19 +139,20 @@ async function addVideoResumable (req: express.Request, res: express.Response) {
139 const videoInfo = videoPhysicalFile.metadata 139 const videoInfo = videoPhysicalFile.metadata
140 const files = { previewfile: videoInfo.previewfile } 140 const files = { previewfile: videoInfo.previewfile }
141 141
142 const response = await addVideo({ res, videoPhysicalFile, videoInfo, files }) 142 const response = await addVideo({ req, res, videoPhysicalFile, videoInfo, files })
143 await Redis.Instance.setUploadSession(req.query.upload_id, response) 143 await Redis.Instance.setUploadSession(req.query.upload_id, response)
144 144
145 return res.json(response) 145 return res.json(response)
146} 146}
147 147
148async function addVideo (options: { 148async function addVideo (options: {
149 req: express.Request
149 res: express.Response 150 res: express.Response
150 videoPhysicalFile: express.VideoUploadFile 151 videoPhysicalFile: express.VideoUploadFile
151 videoInfo: VideoCreate 152 videoInfo: VideoCreate
152 files: express.UploadFiles 153 files: express.UploadFiles
153}) { 154}) {
154 const { res, videoPhysicalFile, videoInfo, files } = options 155 const { req, res, videoPhysicalFile, videoInfo, files } = options
155 const videoChannel = res.locals.videoChannel 156 const videoChannel = res.locals.videoChannel
156 const user = res.locals.oauth.token.User 157 const user = res.locals.oauth.token.User
157 158
@@ -235,7 +236,7 @@ async function addVideo (options: {
235 }) 236 })
236 .catch(err => logger.error('Cannot add optimize/merge audio job for %s.', videoCreated.uuid, { err, ...lTags(videoCreated.uuid) })) 237 .catch(err => logger.error('Cannot add optimize/merge audio job for %s.', videoCreated.uuid, { err, ...lTags(videoCreated.uuid) }))
237 238
238 Hooks.runAction('action:api.video.uploaded', { video: videoCreated }) 239 Hooks.runAction('action:api.video.uploaded', { video: videoCreated, req, res })
239 240
240 return { 241 return {
241 video: { 242 video: {