mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-23 23:51:50 +00:00
Add support for minio
This commit is contained in:
parent
d1d6d5810b
commit
2c780f53df
4 changed files with 49 additions and 0 deletions
|
@ -48,6 +48,13 @@ module.exports = {
|
|||
secretAccessKey: undefined,
|
||||
region: undefined
|
||||
},
|
||||
minio: {
|
||||
accessKey: undefined,
|
||||
secretKey: undefined,
|
||||
endPoint: undefined,
|
||||
secure: true,
|
||||
port: 9000
|
||||
},
|
||||
s3bucket: undefined,
|
||||
// authentication
|
||||
facebook: {
|
||||
|
|
|
@ -24,6 +24,13 @@ module.exports = {
|
|||
secretAccessKey: process.env.HMD_S3_SECRET_ACCESS_KEY,
|
||||
region: process.env.HMD_S3_REGION
|
||||
},
|
||||
minio: {
|
||||
accessKey: process.env.HMD_MINIO_ACCESS_KEY,
|
||||
secretKey: process.env.HMD_MINIO_SECRET_KEY,
|
||||
endPoint: process.env.HMD_MINIO_ENDPOINT,
|
||||
secure: toBooleanConfig(process.env.HMD_MINIO_SECURE),
|
||||
port: parseInt(process.env.HMD_MINIO_PORT)
|
||||
},
|
||||
s3bucket: process.env.HMD_S3_BUCKET,
|
||||
facebook: {
|
||||
clientID: process.env.HMD_FACEBOOK_CLIENTID,
|
||||
|
|
|
@ -73,6 +73,40 @@ imageRouter.post('/uploadimage', function (req, res) {
|
|||
})
|
||||
})
|
||||
break
|
||||
|
||||
case 'minio':
|
||||
var utils = require('../utils')
|
||||
var Minio = require('minio')
|
||||
var minioClient = new Minio.Client({
|
||||
endPoint: config.minio.endPoint,
|
||||
port: config.minio.port,
|
||||
secure: config.minio.secure,
|
||||
accessKey: config.minio.accessKey,
|
||||
secretKey: config.minio.secretKey
|
||||
})
|
||||
fs.readFile(files.image.path, function (err, buffer) {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
res.status(500).end('upload image error')
|
||||
return
|
||||
}
|
||||
|
||||
var key = path.join('uploads', path.basename(files.image.path))
|
||||
var protocol = config.minio.secure ? 'https' : 'http'
|
||||
|
||||
minioClient.putObject(config.s3bucket, key, buffer, buffer.size, utils.getImageMimeType(files.image.path), function (err, data) {
|
||||
if (err) {
|
||||
logger.error(err)
|
||||
res.status(500).end('upload image error')
|
||||
return
|
||||
}
|
||||
res.send({
|
||||
link: `${protocol}://${config.minio.endPoint}:${config.minio.port}/${config.s3bucket}/${key}`
|
||||
})
|
||||
})
|
||||
})
|
||||
break
|
||||
|
||||
case 'imgur':
|
||||
default:
|
||||
imgur.setClientId(config.imgur.clientID)
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
"mermaid": "~7.0.0",
|
||||
"meta-marked": "^0.4.2",
|
||||
"method-override": "^2.3.7",
|
||||
"minio": "^3.1.3",
|
||||
"moment": "^2.17.1",
|
||||
"morgan": "^1.7.0",
|
||||
"mysql": "^2.12.0",
|
||||
|
|
Loading…
Reference in a new issue