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

xsweet conversion - ftp

parent 13dcdd67
No related branches found
No related tags found
2 merge requests!93Shared data model,!94Dev
const fs = require('fs')
const request = require('request')
const rp = require('request-promise')
const tar = require('../utils/unTar.js')
const logger = require('@pubsweet/logger')
......@@ -10,14 +9,14 @@ const path = require('path')
const files = require('../utils/files.js')
const db = require('../utils/db.js')
// '/home/yogmatee/projects/xmlValidation_files/xweet_files/tiana.docx'
/*
xsweetConvert(
'/home/yogmatee/projects/xmlValidation_files/xweet_files/tiana.docx',
'EMS90002',
'EMS90005',
)
*/
function xsweetConvert(fileUrl, manuscriptId) {
module.exports.xsweetConvert = function xsweetConvert(fileUrl, manuscriptId) {
const options = {
method: 'POST',
uri: 'http://localhost:3000/convertDocxToHTML',
......@@ -33,18 +32,19 @@ function xsweetConvert(fileUrl, manuscriptId) {
}
rp(options)
.then(async function(body) {
.then(async body => {
try {
const tmpPath = await tar.createTempDir()
const user = await getUser.getAdminUser()
fs.writeFileSync(`${tmpPath}/${manuscriptId}.html`, body)
console.log('The file has been saved!', tmpPath)
const fileInfo = getFileInfo(
`${tmpPath}/${manuscriptId}.html`,
manuscriptId,
user,
)
const uuid = uuidv4()
// upload to minio
files.uploadFileToMinio(
`${uuid}${fileInfo.extension}`,
......@@ -52,14 +52,18 @@ function xsweetConvert(fileUrl, manuscriptId) {
fileInfo.url,
fileInfo.mimeType,
)
// update object details for database upsert
fileInfo.url = `/download/${uuid}${fileInfo.extension}`
delete fileInfo.extension
await db.upsertHtmlPrevFile(fileInfo)
console.log('file has been uploaded to Minio and to db')
await db.upsertHtmlPrevFile(fileInfo, manuscriptId)
logger.info('file has been uploaded to Minio and to db')
} catch (err) {
throw err
}
})
.catch(function(err) {
.catch(err => {
logger.error('Conversion failed:', err)
})
}
......
This diff is collapsed.
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