1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 10:49:28 +02:00

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.
This commit is contained in:
lutangar 2021-11-24 14:33:14 +01:00 committed by Chocobozzz
parent 5098098d96
commit 7226e90fdc
12 changed files with 41 additions and 23 deletions

View file

@ -129,7 +129,7 @@ async function addVideoLegacy (req: express.Request, res: express.Response) {
const videoInfo: VideoCreate = req.body
const files = req.files
const response = await addVideo({ res, videoPhysicalFile, videoInfo, files })
const response = await addVideo({ req, res, videoPhysicalFile, videoInfo, files })
return res.json(response)
}
@ -139,19 +139,20 @@ async function addVideoResumable (req: express.Request, res: express.Response) {
const videoInfo = videoPhysicalFile.metadata
const files = { previewfile: videoInfo.previewfile }
const response = await addVideo({ res, videoPhysicalFile, videoInfo, files })
const response = await addVideo({ req, res, videoPhysicalFile, videoInfo, files })
await Redis.Instance.setUploadSession(req.query.upload_id, response)
return res.json(response)
}
async function addVideo (options: {
req: express.Request
res: express.Response
videoPhysicalFile: express.VideoUploadFile
videoInfo: VideoCreate
files: express.UploadFiles
}) {
const { res, videoPhysicalFile, videoInfo, files } = options
const { req, res, videoPhysicalFile, videoInfo, files } = options
const videoChannel = res.locals.videoChannel
const user = res.locals.oauth.token.User
@ -235,7 +236,7 @@ async function addVideo (options: {
})
.catch(err => logger.error('Cannot add optimize/merge audio job for %s.', videoCreated.uuid, { err, ...lTags(videoCreated.uuid) }))
Hooks.runAction('action:api.video.uploaded', { video: videoCreated })
Hooks.runAction('action:api.video.uploaded', { video: videoCreated, req, res })
return {
video: {