Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
X
xpub-faraday
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container Registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
xpub
xpub-faraday
Commits
5f745dc6
Commit
5f745dc6
authored
6 years ago
by
Bogdan Cochior
Browse files
Options
Downloads
Patches
Plain Diff
feat(mts): upload package to S3 as backup
parent
b03852ef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!21
Sprint #16 features
,
!15
MTS integration
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/component-mts-package/src/AWS.js
+50
-3
50 additions, 3 deletions
packages/component-mts-package/src/AWS.js
packages/component-mts-package/src/MTS.js
+3
-3
3 additions, 3 deletions
packages/component-mts-package/src/MTS.js
with
53 additions
and
6 deletions
packages/component-mts-package/src/AWS.js
+
50
−
3
View file @
5f745dc6
...
...
@@ -8,7 +8,7 @@ const logger = require('@pubsweet/logger')
const
filterByType
=
(
fileTypes
=
[])
=>
({
Metadata
:
{
filetype
}
})
=>
fileTypes
.
length
>
0
?
fileTypes
.
includes
(
filetype
)
:
true
const
zipAWSFiles
=
(
s3Config
,
archiver
=
nodeArchiver
)
=>
{
const
createFilesPackage
=
(
s3Config
,
archiver
=
nodeArchiver
)
=>
{
AWS
.
config
.
update
({
secretAccessKey
:
s3Config
.
secretAccessKey
,
accessKeyId
:
s3Config
.
accessKeyId
,
...
...
@@ -40,8 +40,8 @@ const zipAWSFiles = (s3Config, archiver = nodeArchiver) => {
if
(
s3Files
)
{
const
packageOutput
=
fs
.
createWriteStream
(
`
${
manuscriptName
}
.zip`
)
const
archive
=
archiver
(
'
zip
'
)
archive
.
pipe
(
packageOutput
)
archive
.
pipe
(
packageOutput
)
archive
.
append
(
xmlFile
.
content
,
{
name
:
xmlFile
.
name
})
s3Files
.
filter
(
filterByType
(
fileTypes
)).
forEach
(
f
=>
{
...
...
@@ -52,9 +52,18 @@ const zipAWSFiles = (s3Config, archiver = nodeArchiver) => {
name
:
isManuscript
?
`
${
manuscriptName
}
.
${
extension
}
`
:
name
,
})
})
archive
.
on
(
'
error
'
,
err
=>
{
throw
err
})
archive
.
on
(
'
end
'
,
err
=>
{
if
(
err
)
throw
err
uploadToS3
({
s3
,
filename
:
`
${
manuscriptName
}
.zip`
,
Bucket
:
s3Config
.
bucket
,
})
})
archive
.
finalize
()
}
}
else
{
...
...
@@ -68,4 +77,42 @@ const zipAWSFiles = (s3Config, archiver = nodeArchiver) => {
}
}
module
.
exports
=
zipAWSFiles
const
readFile
=
filename
=>
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
readFile
(
filename
,
(
err
,
data
)
=>
{
if
(
err
)
reject
(
err
)
resolve
(
data
)
})
})
const
uploadToS3
=
async
({
s3
,
filename
,
Bucket
})
=>
{
const
data
=
await
readFile
(
filename
)
const
params
=
{
Bucket
,
Body
:
data
,
Key
:
`mts/
${
filename
}
`
,
}
s3
.
upload
(
params
,
(
err
,
data
)
=>
{
deleteFile
(
filename
)
if
(
err
)
{
throw
err
}
else
{
logger
.
info
(
`Successfully uploaded
${
filename
}
`
)
}
})
}
const
deleteFile
=
filename
=>
{
fs
.
access
(
filename
,
fs
.
constants
.
F_OK
,
err
=>
{
if
(
err
)
{
if
(
err
)
throw
err
}
else
{
fs
.
unlink
(
filename
,
err
=>
{
if
(
err
)
throw
err
logger
.
info
(
`Deleted
${
filename
}
`
)
})
}
})
}
module
.
exports
=
createFilesPackage
This diff is collapsed.
Click to expand it.
packages/component-mts-package/src/MTS.js
+
3
−
3
View file @
5f745dc6
const
convert
=
require
(
'
xml-js
'
)
const
{
set
,
get
}
=
require
(
'
lodash
'
)
const
zipAWSFiles
=
require
(
'
./AWS
'
)
const
createFilesPackage
=
require
(
'
./AWS
'
)
const
mts
=
require
(
'
./mts-json-template
'
)
const
{
defaultConfig
,
...
...
@@ -206,9 +206,9 @@ class MTS {
return
this
.
convertToXML
(
this
.
composeJson
(
fragment
))
}
createMTSPackage
(
fragment
=
{})
{
async
createMTSPackage
(
fragment
=
{})
{
const
xmlFile
=
this
.
convertFragmentToXML
(
fragment
)
zipAWSFiles
(
this
.
s3Config
)({
fragment
,
xmlFile
})
await
createFilesPackage
(
this
.
s3Config
)({
fragment
,
xmlFile
})
}
}
...
...
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