Commit 094bd929 authored by Yuci Gou's avatar Yuci Gou

Merge branch 'dev' of gitlab.coko.foundation:xpub/xpub-epmc into dev

parents b6ec2561 48304bae
Pipeline #13440 failed with stages
in 30 seconds
......@@ -15,7 +15,7 @@ services:
app:
# user: 'node'
image: xpubepmc_app:1.5.2
image: xpubepmc_app:1.6.0
build:
context: .
dockerfile: ./Dockerfile
......
{
"name": "xpub-epmc",
"version": "1.5.2",
"version": "1.6.0",
"private": true,
"description": "xpub configured for Europe PMC Plus manuscript submission system",
"license": "MIT",
......
require('dotenv').config()
const logger = require('@pubsweet/logger')
const { minioClient } = require('@europepmc/express-middleware-minio')
const AWS = require('aws-sdk')
const { PassThrough } = require('stream')
const s3 = new AWS.S3({
region: 'eu-west-2',
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
})
minioClient.listFiles((error, list) => {
if (error) {
logger.info('error')
} else {
let counter = 0
// eslint-disable-next-line no-restricted-syntax
for (const file of list) {
logger.info(file)
uploadFile(file.name.replace('uploads/', ''))
counter += 1
if (counter > 10) {
break
}
}
}
})
function uploadFile(filePath) {
minioClient.getFileStream(filePath, (err, inputStream) => {
if (err) throw err
inputStream.pipe(uploadFromStream(s3, filePath))
})
}
// arn:aws:s3:::xpub-epmc-test
function uploadFromStream(s3, filePath) {
const pass = new PassThrough()
const params = {
Bucket: process.env.AWS_BUCKET_NAME, // pass your bucket name
Key: `uploads/${filePath}`, // file will be saved as
Body: pass,
}
s3.upload(params, (s3Err, data) => {
if (s3Err) throw s3Err
logger.info(`File uploaded successfully at ${data.Location}`)
})
return pass
}
This diff is collapsed.
Markdown is supported
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