mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
a079aa1fae
[web] convert convert-to-file endpoint into a script GitOrigin-RevId: 5babebae5df8510b83f09ec4a2bb4064cca5ec75
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
const minimist = require('minimist')
|
|
const { waitForDb, ObjectId } = require('../app/src/infrastructure/mongodb')
|
|
const ProjectEntityUpdateHandler = require('../app/src/Features/Project/ProjectEntityUpdateHandler')
|
|
const Errors = require('../app/src/Features/Errors/Errors')
|
|
|
|
async function main() {
|
|
const argv = minimist(process.argv.slice(2))
|
|
const projectId = argv['project-id']
|
|
const docId = argv['doc-id']
|
|
const userId = argv['user-id']
|
|
|
|
if ([projectId, docId, userId].some(it => !it || !ObjectId.isValid(it))) {
|
|
throw new Error(
|
|
'provide a valid object id as --project-id, --doc-id and --user-id'
|
|
)
|
|
}
|
|
|
|
console.log(`Converting doc ${projectId}/${docId} as user ${userId}`)
|
|
await waitForDb()
|
|
try {
|
|
await ProjectEntityUpdateHandler.promises.convertDocToFile(
|
|
projectId,
|
|
docId,
|
|
userId
|
|
)
|
|
} catch (err) {
|
|
if (err instanceof Errors.NotFoundError) {
|
|
throw new Error('Document not found')
|
|
} else if (err instanceof Errors.DocHasRangesError) {
|
|
throw new Error('Document has comments or tracked changes')
|
|
} else {
|
|
throw err
|
|
}
|
|
}
|
|
}
|
|
|
|
main()
|
|
.then(() => {
|
|
console.log('Done.')
|
|
process.exit(0)
|
|
})
|
|
.catch(err => {
|
|
console.error(err)
|
|
process.exit(1)
|
|
})
|