Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
server
Manage
Activity
Members
Labels
Plan
Issues
25
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Show more breadcrumbs
cokoapps
server
Commits
80d1c443
Commit
80d1c443
authored
1 year ago
by
Yannis Barlas
Browse files
Options
Downloads
Patches
Plain Diff
fix(*): use s3 api instead of axios for full size image migration
parent
d5b2ba16
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!71
fix(*): use s3 api instead of axios for full size image migration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/models/file/migrations/1698750314-add-full-quality-converted-object-to-storedobjects.js
+7
-18
7 additions, 18 deletions
...314-add-full-quality-converted-object-to-storedobjects.js
with
7 additions
and
18 deletions
src/models/file/migrations/1698750314-add-full-quality-converted-object-to-storedobjects.js
+
7
−
18
View file @
80d1c443
/* eslint-disable import/no-unresolved */
const
logger
=
require
(
'
@pubsweet/logger
'
)
const
mime
=
require
(
'
mime-types
'
)
const
axios
=
require
(
'
axios
'
)
const
fs
=
require
(
'
fs-extra
'
)
const
path
=
require
(
'
path
'
)
const
sharp
=
require
(
'
sharp
'
)
...
...
@@ -11,7 +10,7 @@ const File = require('@coko/server/src/models/file/file.model')
const
{
connectToFileStorage
,
getURL
,
download
,
uploadFileHandler
,
}
=
require
(
'
@coko/server/src/services/fileStorage
'
)
...
...
@@ -61,14 +60,6 @@ const sharpConversionFullFilePath = async (
return
tempFullFilePath
}
const
createMinioFileImageStream
=
async
url
=>
{
const
response
=
await
axios
.
get
(
url
,
{
responseType
:
'
stream
'
,
})
return
response
.
data
}
exports
.
up
=
async
knex
=>
{
try
{
return
useTransaction
(
async
trx
=>
{
...
...
@@ -76,6 +67,7 @@ exports.up = async knex => {
const
files
=
await
File
.
query
(
trx
)
const
tempDir
=
path
.
join
(
__dirname
,
'
..
'
,
'
temp
'
)
await
fs
.
ensureDir
(
tempDir
)
await
Promise
.
all
(
files
.
map
(
async
file
=>
{
...
...
@@ -86,21 +78,16 @@ exports.up = async knex => {
storedObject
=>
storedObject
.
type
===
'
original
'
,
)
const
fileURL
=
await
getURL
(
originalStoredObject
.
key
)
const
filenameWithoutExtension
=
path
.
parse
(
originalStoredObject
.
key
,
).
name
const
minioFileImageStream
=
await
createMinioFileImageStream
(
fileURL
,
)
const
tempPath
=
path
.
join
(
tempDir
,
originalStoredObject
.
key
)
await
download
(
originalStoredObject
.
key
,
tempPath
)
const
format
=
originalStoredObject
.
extension
const
buffer
=
await
convertFileStreamIntoBuffer
(
minioFileImageStream
,
)
const
buffer
=
fs
.
readFileSync
(
tempPath
)
const
tempFullFilePath
=
await
sharpConversionFullFilePath
(
buffer
,
...
...
@@ -109,6 +96,8 @@ exports.up = async knex => {
format
,
)
fs
.
unlinkSync
(
tempPath
)
const
fullImageStream
=
fs
.
createReadStream
(
tempFullFilePath
)
const
full
=
await
uploadFileHandler
(
...
...
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