Skip to content
Snippets Groups Projects
Commit d3922d7e authored by Sebastian Mihalache's avatar Sebastian Mihalache
Browse files

Merge branch 'develop' of gitlab.coko.foundation:xpub/xpub-faraday into develop

parents e1f81c5b a88bbf09
No related branches found
No related tags found
1 merge request!34Sprint 17 features
...@@ -52,7 +52,7 @@ module.exports = models => async (req, res) => { ...@@ -52,7 +52,7 @@ module.exports = models => async (req, res) => {
}, },
} }
await MTS.sendPackage(packageFragment) await MTS.sendPackage({ fragment: packageFragment })
notifications.sendNotifications({ notifications.sendNotifications({
fragment, fragment,
......
const uuid = require('uuid') const uuid = require('uuid')
const { pick } = require('lodash') const { pick, get } = require('lodash')
const config = require('config')
const { const {
services, services,
...@@ -7,6 +8,10 @@ const { ...@@ -7,6 +8,10 @@ const {
Collection, Collection,
} = require('pubsweet-component-helper-service') } = require('pubsweet-component-helper-service')
const s3Config = get(config, 'pubsweet-component-aws-s3', {})
const mtsConfig = get(config, 'mts-service', {})
const MTSService = require('pubsweet-component-mts-package')
const notifications = require('./notifications/notifications') const notifications = require('./notifications/notifications')
module.exports = models => async (req, res) => { module.exports = models => async (req, res) => {
...@@ -70,6 +75,20 @@ module.exports = models => async (req, res) => { ...@@ -70,6 +75,20 @@ module.exports = models => async (req, res) => {
fragment.revision = pick(fragment, ['authors', 'files', 'metadata']) fragment.revision = pick(fragment, ['authors', 'files', 'metadata'])
} }
if (isEditorInChief && recommendation === 'publish') {
const { journal, xmlParser, ftp } = mtsConfig
const MTS = new MTSService(journal, xmlParser, s3Config, ftp)
const packageFragment = {
...fragment,
metadata: {
...fragment.metadata,
customId: collection.customId,
},
}
await MTS.sendPackage({ fragment: packageFragment, isEQA: true })
}
notifications.sendNotifications({ notifications.sendNotifications({
fragment, fragment,
collection, collection,
......
...@@ -216,15 +216,19 @@ class MTS { ...@@ -216,15 +216,19 @@ class MTS {
return this.convertToXML(this.composeJson(fragment)) return this.convertToXML(this.composeJson(fragment))
} }
sendPackage(fragment = {}) { sendPackage({ fragment = {}, isEQA = false }) {
const xmlFile = this.convertFragmentToXML(fragment) const xmlFile = this.convertFragmentToXML(fragment)
return PackageManager.createFilesPackage(this.s3Config)({ return PackageManager.createFilesPackage(this.s3Config)({
fragment, fragment,
xmlFile, xmlFile,
isEQA,
}).then(() => { }).then(() => {
const manuscriptName = get(xmlFile, 'name', '').replace('.xml', '') const packageName = get(xmlFile, 'name', '').replace('.xml', '')
const filename = `${manuscriptName}.zip` const filename = isEQA
? `ACCEPTED_${packageName}.zip`
: `${packageName}.zip`
return PackageManager.uploadFiles({ return PackageManager.uploadFiles({
filename, filename,
s3Config: this.s3Config, s3Config: this.s3Config,
......
...@@ -19,9 +19,12 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => { ...@@ -19,9 +19,12 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => {
const asyncGetObject = promisify(s3.getObject.bind(s3)) const asyncGetObject = promisify(s3.getObject.bind(s3))
const asyncListObjects = promisify(s3.listObjects.bind(s3)) const asyncListObjects = promisify(s3.listObjects.bind(s3))
return async ({ fragment, fileTypes, xmlFile }) => { return async ({ fragment, fileTypes, xmlFile, isEQA = false }) => {
const { id } = fragment const { id } = fragment
const manuscriptName = get(xmlFile, 'name', '').replace('.xml', '') let packageName = get(xmlFile, 'name', '').replace('.xml', '')
if (isEQA) {
packageName = `ACCEPTED_${packageName}`
}
try { try {
const params = { const params = {
Bucket: s3Config.bucket, Bucket: s3Config.bucket,
...@@ -39,7 +42,7 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => { ...@@ -39,7 +42,7 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => {
) )
if (s3Files) { if (s3Files) {
const packageOutput = fs.createWriteStream(`${manuscriptName}.zip`) const packageOutput = fs.createWriteStream(`${packageName}.zip`)
const archive = archiver('zip') const archive = archiver('zip')
archive.pipe(packageOutput) archive.pipe(packageOutput)
......
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