Files
speckle-server/packages/fileimport-service/ifc/import_file.js
T
Kristaps Fabians Geikins 83d8035dc2 chore: upgrade to eslint 9 (#2348)
* root + server

* frontend

* frontend-2

* dui3

* dui3

* tailwind theme

* ui-components

* preview service

* viewer

* viewer-sandbox

* fileimport-service

* webhook service

* objectloader

* shared

* ui-components-nuxt

* WIP full config

* WIP full linter

* eslint projectwide util

* minor fix

* removing redundant ci

* clean up test errors

* fixed prettier formatting

* CI improvements

* TSC lint fix

* 'buildBatch' needs to be async since some batch types (like Text) require it. Removed a disabled liniting rule from ObjLoader

* removed unnecessary void

---------

Co-authored-by: AlexandruPopovici <alexandrupopoviciioan@gmail.com>
2024-06-12 14:38:02 +03:00

57 lines
1.3 KiB
JavaScript

const fs = require('fs')
const { logger: parentLogger } = require('../observability/logging')
const TMP_RESULTS_PATH = '/tmp/import_result.json'
const { parseAndCreateCommit } = require('./index')
const Observability = require('@speckle/shared/dist/commonjs/observability/index.js')
async function main() {
const cmdArgs = process.argv.slice(2)
const [filePath, userId, streamId, branchName, commitMessage, fileId] = cmdArgs
const logger = Observability.extendLoggerComponent(
parentLogger.child({ streamId, branchName, userId, fileId, filePath }),
'ifc'
)
logger.info('ARGV: ', filePath, userId, streamId, branchName, commitMessage)
const data = fs.readFileSync(filePath)
const ifcInput = {
data,
streamId,
userId,
message: commitMessage || ' Imported file',
fileId,
logger
}
if (branchName) ifcInput.branchName = branchName
let output = {
success: false,
error: 'Unknown error'
}
try {
const commitId = await parseAndCreateCommit(ifcInput)
output = {
success: true,
commitId
}
} catch (err) {
logger.error(err, 'Error while parsing IFC file or creating commit.')
output = {
success: false,
error: err.toString()
}
}
fs.writeFileSync(TMP_RESULTS_PATH, JSON.stringify(output))
process.exit(0)
}
main()