Skip to content
Snippets Groups Projects
Commit a5e471e9 authored by Yogmatee Roochun's avatar Yogmatee Roochun
Browse files

modified something

parent ce9968b8
No related branches found
No related tags found
2 merge requests!98Dev,!97Shared data model
......@@ -12,15 +12,17 @@ const db = require('../utils/db.js')
const pubsweetServer = config.get('pubsweet-server.baseUrl')
const label = 'xsweet conversion'
/*
xsweetConvert(
'/home/yogmatee/projects/xmlValidation_files/xweet_files/tiana.docx',
'EMS90008',
'EMS90005',
)
*/
module.exports.xsweetConvert = function xsweetConvert(fileUrl, manuscriptId) {
module.exports.xsweetConvert = async function xsweetConvert(
fileUrl,
manuscriptId,
) {
const options = {
method: 'POST',
uri: `${pubsweetServer}/convertDocxToHTML`,
......@@ -33,40 +35,35 @@ module.exports.xsweetConvert = function xsweetConvert(fileUrl, manuscriptId) {
},
}
rp(options)
.then(body => {
await rp(options)
.then(async body => {
try {
return new Promise(async resolve => {
const tmpPath = await tar.createTempDir()
const user = await getUser.getAdminUser()
fs.writeFileSync(`${tmpPath}/${manuscriptId}.html`, body)
const tmpPath = await tar.createTempDir()
const user = await getUser.getAdminUser()
fs.writeFileSync(`${tmpPath}/${manuscriptId}.html`, body)
const fileInfo = getFileInfo(
`${tmpPath}/${manuscriptId}.html`,
manuscriptId,
user,
label,
)
const uuid = uuidv4()
const fileInfo = getFileInfo(
`${tmpPath}/${manuscriptId}.html`,
manuscriptId,
user,
label,
)
const uuid = uuidv4()
// upload to minio
files.uploadFileToMinio(
`${uuid}${fileInfo.extension}`,
fileInfo.filename,
fileInfo.url,
fileInfo.mimeType,
)
// upload to minio
files.uploadFileToMinio(
`${uuid}${fileInfo.extension}`,
fileInfo.filename,
fileInfo.url,
fileInfo.mimeType,
)
// update object details for database upsert
fileInfo.url = `/download/${uuid}${fileInfo.extension}`
delete fileInfo.extension
// update object details for database upsert
fileInfo.url = `/download/${uuid}${fileInfo.extension}`
delete fileInfo.extension
await db.upsertHtmlPrevFile(fileInfo, manuscriptId)
logger.info(
'HTML converted file has been uploaded to Minio and to db',
)
resolve(true)
})
await db.upsertHtmlPrevFile(fileInfo, manuscriptId)
logger.info('HTML converted file has been uploaded to Minio and to db')
} catch (err) {
throw err
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment