3d6653f73b
* Update to new specklepy (#1173) * Publish images for all branches but limit tagging * only tag 'latest' and '2' when 'SHOULD_PUBLISH' variable is 'true' * Publishing helm chart should check for `SHOULD_PUBLISH` * Move blocking step to publish-helm chart, and allow images to be published * Pin python requirements and bump to latest versions * Fix EOL whitespace * use valid version for psycopg2-binary (the clue is in the 2!) * fix(fileimports): add exception printing to file imports * fix(fileimports): bump specklepy version move to a specklepy version that contains a fix for send without writing to disk Co-authored-by: Iain Sproat <68657+iainsproat@users.noreply.github.com> * Fixes liveness and readiness checks to prevent CSRF error message (#1169) - provides content-type header - check that status code is 200 * Fixes broken helm template by adding quotation marks around liveness probe command (#1171) * fix(server activities): make sure the stream events are properly dispatched * feat(server webhooks): add scheduled orphaned webhook cleanup * test(server webhooks): add test to webhook cleanup service * feat(server webhooks): drop foreign key reference for webhooks schema to streams * refactor(server req context): refactor req context to have the ip attribute for all requests * feat(server objects rest api): add ratelimits to objects rest api endpoints * fix(server rest api): properly handle returning 419 Co-authored-by: Iain Sproat <68657+iainsproat@users.noreply.github.com>
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
'use strict'
|
|
const zlib = require('zlib')
|
|
const cors = require('cors')
|
|
const debug = require('debug')
|
|
|
|
const { contextMiddleware } = require('@/modules/shared')
|
|
const { validatePermissionsWriteStream } = require('./authUtils')
|
|
const {
|
|
rejectsRequestWithRatelimitStatusIfNeeded
|
|
} = require('@/modules/core/services/ratelimits')
|
|
|
|
const { hasObjects } = require('../services/objects')
|
|
|
|
module.exports = (app) => {
|
|
app.options('/api/diff/:streamId', cors())
|
|
|
|
app.post('/api/diff/:streamId', cors(), contextMiddleware, async (req, res) => {
|
|
const rejected = await rejectsRequestWithRatelimitStatusIfNeeded({
|
|
action: 'POST /api/diff/:streamId',
|
|
req,
|
|
res
|
|
})
|
|
if (rejected) return rejected
|
|
const hasStreamAccess = await validatePermissionsWriteStream(
|
|
req.params.streamId,
|
|
req
|
|
)
|
|
if (!hasStreamAccess.result) {
|
|
return res.status(hasStreamAccess.status).end()
|
|
}
|
|
|
|
const objectList = JSON.parse(req.body.objects)
|
|
|
|
debug('speckle:info')(
|
|
`[User ${req.context.userId || '-'}] Diffing ${
|
|
objectList.length
|
|
} objects for stream ${req.params.streamId}`
|
|
)
|
|
|
|
const response = await hasObjects({
|
|
streamId: req.params.streamId,
|
|
objectIds: objectList
|
|
})
|
|
// console.log(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)
|
|
})
|
|
}
|