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

issue 397 - filter list of files for taggers

parent 1ffb9001
No related branches found
No related tags found
2 merge requests!83Shared data model,!86Dev
......@@ -8,62 +8,55 @@ const os = require('os')
// const fetch = require('node-fetch')
const config = require('config')
const passport = require('passport')
const Manuscript = require('../xpub-model/entities/manuscript/data-access')
const { taggerEmail } = rfr('server/email')
const pubsweetServer = config.get('pubsweet-server.baseUrl')
let manId
const ftpTagger = config.get('ftp_tagger')
const ftpLocation = `${process.env.HOME}/${config.get('ftp_directory')}/${
ftpTagger.username
}/New`
const authBearer = passport.authenticate('bearer', { session: false })
const datedFolder = dateFormat(new Date(), 'yyyy-mm-dd')
module.exports = app => {
app.get('/tagging/send', authBearer, (req, res) => {
app.get('/tagging/send', authBearer, async (req, res) => {
res.set({ 'Content-Type': 'application/json' })
const { manid } = req.query
createPackageForTaggers(manid)
await createPackageForTaggers(manid)
res.send(JSON.stringify('result:success'))
})
}
// createPackageForTaggers('EMS80000')
// createPackageForTaggers('EMS90002')
// noinspection JSAnnotator
function createPackageForTaggers(manid) {
async function createPackageForTaggers(manid) {
logger.info(`Sending package ${manid} to tagger FTP location.`)
manId = manid
getManuscript().then(manuscript =>
createTempDir(manuscript).then(tmpPath =>
writeFiles(tmpPath, manuscript).then(() =>
createMetadataXML(tmpPath, manuscript).then(tmpPath =>
createManifest(tmpPath, manuscript).then(() =>
compress(tmpPath, manuscript).then(() => {
// taggerEmail = (email, manId, title, link) => {
taggerEmail(
ftpTagger.email,
manuscript.id,
manuscript['meta,title'],
`ftp://${process.env.PUBSWEET_HOST}/New/${datedFolder}/${
manuscript.id
}.tar.gz`,
)
tidyUp(tmpPath)
}),
),
),
),
),
const manuscript = await getManuscript(manid)
const tmpPath = await createTempDir(manuscript)
await writeFiles(tmpPath, manuscript)
await createMetadataXML(tmpPath, manuscript)
await createManifest(tmpPath, manuscript)
await compress(tmpPath, manuscript)
taggerEmail(
ftpTagger.email,
manuscript.id,
manuscript['meta,title'],
`ftp://${process.env.PUBSWEET_HOST}/New/${datedFolder}/${
manuscript.id
}.tar.gz`,
)
await tidyUp(tmpPath)
}
function getManuscript() {
const Manuscript = require('../xpub-model/entities/manuscript/data-access')
function getManuscript(manId) {
return new Promise((resolve, reject) => {
Manuscript.findByFieldEager('id', manId, '[journal, files, audits]')
.then(rows => {
......@@ -218,16 +211,32 @@ async function createMetadataXML(tmpPath, manuscript) {
if (err) {
reject(err)
}
resolve(tmpPath)
resolve(`${manuscript.id}.xml`)
})
})
}
// file types included for taggers
function filterFiles(files) {
const allowedTypes = [
'manuscript',
'supplement',
'figure',
'PMC',
'IMGview',
'IMGprint',
]
const result = files.filter(file => allowedTypes.includes(file.type))
return result
}
function writeFiles(tmpPath, manuscript) {
const promises = [] // array of promises
const filteredFiles = filterFiles(manuscript.files)
// do not export the metadata file
manuscript.files.forEach(file => {
filteredFiles.forEach(file => {
const promise = new Promise((resolve, reject) => {
const fileOnDisk = fs.createWriteStream(`${tmpPath}/${file.filename}`)
......@@ -270,7 +279,7 @@ function createManifest(tmpPath, manuscript) {
if (err) {
reject(err)
}
resolve(tmpPath)
resolve(true)
})
})
}
......
......@@ -10304,7 +10304,7 @@ prompt@^1.0.0:
utile "0.3.x"
winston "2.1.x"
 
"prompt@github:flatiron/prompt#1c95d1d8d333b5fbc13fa5f0619f3dcf0d514f87":
prompt@flatiron/prompt#1c95d1d8d333b5fbc13fa5f0619f3dcf0d514f87:
version "1.0.0"
resolved "https://codeload.github.com/flatiron/prompt/tar.gz/1c95d1d8d333b5fbc13fa5f0619f3dcf0d514f87"
dependencies:
......
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