444d2ca7dd
* Revert "Revert "feat(structured logging): implements structured logging for backend (#1217)" (#1227)"
This reverts commit 63e6581162.
* Use pino-http instead of express pino logger
* Use correct reference to knex and do not instantiate HttpLogger prematurely
* Adds missing dependency for pino to webhook-service
* Do not instantiate middleware when passed to express
* Refactor to move logging into shared
* Copy shared packages into dockerfiles
* Build shared workspace in docker build-stage for fileimport & webhook
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
'use strict'
|
|
const zlib = require('zlib')
|
|
const cors = require('cors')
|
|
|
|
const { validatePermissionsWriteStream } = require('./authUtils')
|
|
|
|
const { hasObjects } = require('../services/objects')
|
|
const { logger } = require('@/logging/logging')
|
|
|
|
module.exports = (app) => {
|
|
app.options('/api/diff/:streamId', cors())
|
|
|
|
app.post('/api/diff/:streamId', cors(), async (req, res) => {
|
|
const hasStreamAccess = await validatePermissionsWriteStream(
|
|
req.params.streamId,
|
|
req
|
|
)
|
|
if (!hasStreamAccess.result) {
|
|
return res.status(hasStreamAccess.status).end()
|
|
}
|
|
|
|
const objectList = JSON.parse(req.body.objects)
|
|
|
|
logger.info(
|
|
`[User ${req.context.userId || '-'}] Diffing ${
|
|
objectList.length
|
|
} objects for stream ${req.params.streamId}`
|
|
)
|
|
|
|
const response = await hasObjects({
|
|
streamId: req.params.streamId,
|
|
objectIds: objectList
|
|
})
|
|
// logger.debug(response)
|
|
res.writeHead(200, {
|
|
'Content-Encoding': 'gzip',
|
|
'Content-Type': 'application/json'
|
|
})
|
|
const gzip = zlib.createGzip()
|
|
gzip.write(JSON.stringify(response))
|
|
gzip.flush()
|
|
gzip.end()
|
|
gzip.pipe(res)
|
|
})
|
|
}
|