Skip to content
Snippets Groups Projects
Commit 06a93780 authored by Yuci Gou's avatar Yuci Gou
Browse files

Clean up minio

parent 7c497d6f
No related branches found
No related tags found
2 merge requests!83Shared data model,!86Dev
......@@ -20,7 +20,6 @@ MINIO_PORT=9000
MINIO_SECURITY=false
MINIO_BUCKET=manuscripts
MINIO_UPLOADS_FOLDER_NAME=uploads
MINIO_DATA_FOLDER_NAME=data
```
Configuration 2:
......@@ -35,7 +34,6 @@ MINIO_PORT=9000
MINIO_SECURITY=false
MINIO_BUCKET=manuscripts
MINIO_UPLOADS_FOLDER_NAME=uploads
MINIO_DATA_FOLDER_NAME=data
```
In both cases, be sure that the key and secret are the same as those in .env.minio
### 3. REST APIs to use
......@@ -84,4 +82,4 @@ DELETE: /api/files/{filename}
#### List all files
```
GET: /api/files
```
\ No newline at end of file
```
......@@ -192,7 +192,6 @@ module.exports = {
secure: process.env.MINIO_SECURITY === 'true',
bucket: process.env.MINIO_BUCKET,
uploads: process.env.MINIO_UPLOADS_FOLDER_NAME,
data: process.env.MINIO_DATA_FOLDER_NAME,
},
publicKeys: [
'pubsweet-client',
......
......@@ -13,7 +13,6 @@ For example:
secure: process.env.MINIO_SECURITY === 'true',
bucket: process.env.MINIO_BUCKET,
uploads: process.env.MINIO_UPLOADS_FOLDER_NAME,
data: process.env.MINIO_DATA_FOLDER_NAME,
},
```
......@@ -27,7 +26,6 @@ MINIO_PORT=9000
MINIO_SECURITY=true
MINIO_BUCKET=manuscripts
MINIO_UPLOADS_FOLDER_NAME=uploads
MINIO_DATA_FOLDER_NAME=data
```
Then, as soon as possible in your app you should add the `dotenv` package:
......
......@@ -24,7 +24,6 @@ MINIO_PORT=9000
MINIO_SECURITY=false
MINIO_BUCKET=manuscripts
MINIO_UPLOADS_FOLDER_NAME=uploads
MINIO_DATA_FOLDER_NAME=data
```
## Then you can use the Minio middleware in your Express application:
......@@ -57,7 +56,7 @@ app.post('/api/files', minioMiddleware({op: minioClient.Ops.post}), (req, res) =
})
app.get('/api/files',
minioMiddleware({op: minioClient.Ops.list}),
minioMiddleware({op: minioClient.Ops.list}),
(req, res) => {
if (req.minio.error) {
res.status(400).json({ error: req.minio.error })
......@@ -85,4 +84,4 @@ app.delete('/api/files/:filename',
res.send(req.minio.delete);
}
)
```
\ No newline at end of file
```
const lodash = require('lodash')
const rfr = require('rfr')
const FileAccess = require('./data-access')
// const dataAccess = new FileAccess()
const { minioClient } = rfr('server/modules/pubsweet-component-minio')
const empty = {
filename: '',
label: '',
......@@ -35,31 +32,7 @@ const FileManager = {
return { ...file, id }
},
putContent: async (file, content, { size } = {}) => {
if (!file.id) {
throw new Error('File has no ID, must be saved first')
}
const data = process.env.MINIO_DATA_FOLDER_NAME
const metaData = {
'Content-Type': file.mimetype,
'Content-Length': size,
}
return minioClient.putObject(
process.env.MINIO_BUCKET,
`${data}/${file.url}/${file.id}`,
content,
metaData,
)
},
getContent: async file => {
const data = process.env.MINIO_DATA_FOLDER_NAME
const Body = await minioClient.getObject(
process.env.MINIO_BUCKET,
`${data}/${file.url}/${file.id}`,
)
return Body
},
modelName: 'File',
model: FileAccess,
......
......@@ -162,7 +162,6 @@ module.exports = {
secure: process.env.MINIO_SECURITY === 'true',
bucket: process.env.MINIO_BUCKET,
uploads: process.env.MINIO_UPLOADS_FOLDER_NAME,
data: process.env.MINIO_DATA_FOLDER_NAME,
},
publicKeys: ['pubsweet-client', 'authsome', 'validations'],
elife: {
......
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