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