Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xpub-epmc
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Literature-services
public-projects
xpub-epmc
Commits
d8563637
Commit
d8563637
authored
6 years ago
by
Yogmatee Roochun
Browse files
Options
Downloads
Patches
Plain Diff
issue 397 - filter list of files for taggers
parent
1ffb9001
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!83
Shared data model
,
!86
Dev
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/ftp-integration/toTaggers.js
+42
-33
42 additions, 33 deletions
server/ftp-integration/toTaggers.js
yarn.lock
+1
-1
1 addition, 1 deletion
yarn.lock
with
43 additions
and
34 deletions
server/ftp-integration/toTaggers.js
+
42
−
33
View file @
d8563637
...
...
@@ -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('EMS
8
000
0
')
// createPackageForTaggers('EMS
9
000
2
')
// 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
.
f
iles
.
forEach
(
file
=>
{
filteredF
iles
.
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
(
t
mpPath
)
resolve
(
t
rue
)
})
})
}
...
...
This diff is collapsed.
Click to expand it.
yarn.lock
+
1
−
1
View file @
d8563637
...
...
@@ -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:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment