.on does not exist on response stream
- allow speckle server url to be passed in - adds manual script and yarn command for running script
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
"scripts": {
|
||||
"dev": "cross-env POSTGRES_URL=postgres://speckle:speckle@127.0.0.1/speckle NODE_ENV=development LOG_PRETTY=true SPECKLE_SERVER_URL=http://127.0.0.1:3000 nodemon --no-experimental-fetch ./src/daemon.js",
|
||||
"parse:ifc": "node --no-experimental-fetch ./ifc/import_file.js ./ifc/ifcs/steelplates.ifc 33763848d6 2e4bfb467a main File upload: steelplates.ifc",
|
||||
"downloadBlob": "node scripts/downloadBlob.js",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"bugs": {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
const { downloadFile } = require('../src/filesApi.js')
|
||||
const { logger } = require('../observability/logging')
|
||||
|
||||
//https://latest.speckle.systems/api/stream/c83a5b2d1f/blob/29fe85cffb
|
||||
const speckleServerUrl = 'https://latest.speckle.systems'
|
||||
const fileId = '29fe85cffb'
|
||||
const streamId = 'c83a5b2d1f'
|
||||
|
||||
downloadFile({
|
||||
speckleServerUrl,
|
||||
fileId,
|
||||
streamId,
|
||||
destination: '/var/folders/p2/fczcvzfd62x5jcfdlw6ghf640000gn/T/tmp.U8MlF9KIxH',
|
||||
token: process.env.SPECKLE_TOKEN || '',
|
||||
logger: logger.child({ streamId, fileId })
|
||||
})
|
||||
@@ -124,6 +124,7 @@ async function doTask(mainDb, regionName, taskDb, task) {
|
||||
taskLogger.info('Downloading file {fileId}')
|
||||
|
||||
await downloadFile({
|
||||
speckleServerUrl: process.env.SPECKLE_SERVER_URL,
|
||||
fileId: info.id,
|
||||
streamId: info.streamId,
|
||||
token,
|
||||
|
||||
@@ -6,11 +6,21 @@ const path = require('node:path')
|
||||
const { pipeline } = require('node:stream/promises')
|
||||
|
||||
module.exports = {
|
||||
async downloadFile({ fileId, streamId, token, destination, logger }) {
|
||||
async downloadFile({
|
||||
speckleServerUrl,
|
||||
fileId,
|
||||
streamId,
|
||||
token,
|
||||
destination,
|
||||
logger
|
||||
}) {
|
||||
fs.mkdirSync(path.dirname(destination), { recursive: true })
|
||||
logger.info(`Downloading file ${fileId} to ${destination}`)
|
||||
logger.info(
|
||||
{ destinationFile: destination },
|
||||
'Downloading file {fileId} from {streamId} to {destinationFile}'
|
||||
)
|
||||
const response = await fetch(
|
||||
`${process.env.SPECKLE_SERVER_URL}/api/stream/${streamId}/blob/${fileId}`,
|
||||
`${speckleServerUrl}/api/stream/${streamId}/blob/${fileId}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
@@ -23,9 +33,6 @@ module.exports = {
|
||||
writer.on('error', (err) => {
|
||||
logger.error(ensureError(err), `Error writing file ${destination}`)
|
||||
})
|
||||
response.body.on('error', (err) => {
|
||||
logger.error(ensureError(err), `Error reading from response body`)
|
||||
})
|
||||
|
||||
//handle completion
|
||||
writer.on('finish', () => {
|
||||
|
||||
@@ -49,6 +49,7 @@ module.exports = {
|
||||
continue
|
||||
}
|
||||
await downloadFile({
|
||||
speckleServerUrl: process.env.SPECKLE_SERVER_URL,
|
||||
fileId: file.id,
|
||||
streamId,
|
||||
token,
|
||||
|
||||
Reference in New Issue
Block a user