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
46e7cfcf
Commit
46e7cfcf
authored
6 years ago
by
Yogmatee Roochun
Browse files
Options
Downloads
Patches
Plain Diff
xsweet conversion - front end
parent
959de4c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!114
Shared data model
,
!115
Dev
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
package.json
+1
-0
1 addition, 0 deletions
package.json
server/xpub-server/entities/file/uploadFiles.js
+27
-3
27 additions, 3 deletions
server/xpub-server/entities/file/uploadFiles.js
yarn.lock
+12
-0
12 additions, 0 deletions
yarn.lock
with
40 additions
and
3 deletions
package.json
+
1
−
0
View file @
46e7cfcf
...
...
@@ -91,6 +91,7 @@
"
request-promise
"
:
"
^4.2.4
"
,
"
rfr
"
:
"
^1.2.3
"
,
"
rimraf
"
:
"
^2.6.3
"
,
"
stream-to-array
"
:
"
^2.3.0
"
,
"
supertest
"
:
"
^3.0.0
"
,
"
tar
"
:
"
^4.4.8
"
,
"
tar-fs
"
:
"
^1.16.3
"
,
...
...
This diff is collapsed.
Click to expand it.
server/xpub-server/entities/file/uploadFiles.js
+
27
−
3
View file @
46e7cfcf
...
...
@@ -4,8 +4,12 @@ const config = require('config')
const
rfr
=
require
(
'
rfr
'
)
const
{
minioClient
}
=
require
(
'
express-middleware-minio
'
)
const
{
timer
}
=
require
(
'
benmark
'
)
const
fs
=
require
(
'
fs
'
)
const
FileModel
=
rfr
(
'
server/xpub-model/entities/file/data-access
'
)
const
tar
=
rfr
(
'
server/utils/unTar
'
)
const
fileUtil
=
rfr
(
'
server/utils/files
'
)
const
{
xsweetConvert
}
=
rfr
(
'
server/xsweet-conversion
'
)
const
extractFileExtension
=
filename
=>
{
if
(
filename
)
{
...
...
@@ -14,17 +18,31 @@ const extractFileExtension = filename => {
return
''
}
const
handleFile
=
async
file
=>
{
const
handleFile
=
async
(
file
,
manuscriptId
,
type
)
=>
{
const
{
stream
,
filename
,
mimetype
}
=
await
file
let
newFilename
=
uuidv1
()
let
extension
=
''
if
(
filename
)
{
const
extension
=
extractFileExtension
(
filename
)
extension
=
extractFileExtension
(
filename
)
if
(
extension
)
{
newFilename
+=
`.
${
extension
}
`
}
}
// case when manuscript is a docx file
if
(
type
===
'
manuscript
'
&&
extension
===
'
docx
'
)
{
const
tmpPath
=
await
tar
.
createTempDir
()
const
wstreamTmp
=
fs
.
createWriteStream
(
`
${
tmpPath
}
/
${
filename
}
`
)
stream
.
pipe
(
wstreamTmp
)
wstreamTmp
.
on
(
'
finish
'
,
async
()
=>
{
await
xsweetConvert
(
`
${
tmpPath
}
/
${
filename
}
`
,
manuscriptId
)
logger
.
info
(
'
xsweet conversion is DONE!
'
)
fileUtil
.
tidyUp
(
tmpPath
)
})
}
try
{
await
timer
(
`S3 uploading file
${
filename
}
`
)(
minioClient
.
uploadFileSteam
)(
newFilename
,
...
...
@@ -40,10 +58,15 @@ const handleFile = async file => {
async
function
uploadFiles
(
_
,
{
id
,
files
,
type
=
''
},
{
user
})
{
const
resolvedFiles
=
await
files
const
savedFiles
=
[]
await
Promise
.
all
(
resolvedFiles
.
map
(
async
resolvedFile
=>
{
const
{
err
,
filename
,
url
,
mimetype
}
=
await
handleFile
(
resolvedFile
)
const
{
err
,
filename
,
url
,
mimetype
}
=
await
handleFile
(
resolvedFile
,
id
,
type
,
)
if
(
err
||
!
filename
)
{
logger
.
error
(
'
Minio error:
'
,
err
)
return
...
...
@@ -61,6 +84,7 @@ async function uploadFiles(_, { id, files, type = '' }, { user }) {
const
savedFile
=
await
file
.
save
()
logger
.
debug
(
'
savedFile:
'
,
savedFile
)
savedFiles
.
push
(
savedFile
)
// xsweetConvert()
}),
)
...
...
This diff is collapsed.
Click to expand it.
yarn.lock
+
12
−
0
View file @
46e7cfcf
...
...
@@ -1017,6 +1017,11 @@ any-observable@^0.2.0:
resolved "https://registry.yarnpkg.com/any-observable/-/any-observable-0.2.0.tgz#c67870058003579009083f54ac0abafb5c33d242"
integrity sha1-xnhwBYADV5AJCD9UrAq6+1wz0kI=
any-promise@^1.1.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"
integrity sha1-q8av7tzqUugJzcA3au0845Y10X8=
anymatch@^1.3.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.2.tgz#553dcb8f91e3c889845dfdba34c77721b90b9d7a"
...
...
@@ -13191,6 +13196,13 @@ stream-shift@^1.0.0:
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
integrity sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=
stream-to-array@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/stream-to-array/-/stream-to-array-2.3.0.tgz#bbf6b39f5f43ec30bc71babcb37557acecf34353"
integrity sha1-u/azn19D7DC8cbq8s3VXrOzzQ1M=
dependencies:
any-promise "^1.1.0"
stream-to-observable@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/stream-to-observable/-/stream-to-observable-0.1.0.tgz#45bf1d9f2d7dc09bed81f1c307c430e68b84cffe"
...
...
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