mirror of
https://github.com/status-im/codimd.git
synced 2025-02-14 10:56:24 +00:00
ts: lib/imageRouter/minio.ts
Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
parent
dbf140544a
commit
5416bafa2b
@ -1,12 +1,12 @@
|
||||
'use strict'
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const config = require('../config')
|
||||
const { getImageMimeType } = require('../utils')
|
||||
const logger = require('../logger')
|
||||
import Minio from "minio";
|
||||
|
||||
import config from "../config";
|
||||
import {getImageMimeType} from "../utils";
|
||||
import logger from "../logger";
|
||||
|
||||
const Minio = require('minio')
|
||||
const minioClient = new Minio.Client({
|
||||
endPoint: config.minio.endPoint,
|
||||
port: config.minio.port,
|
||||
@ -15,7 +15,7 @@ const minioClient = new Minio.Client({
|
||||
secretKey: config.minio.secretKey
|
||||
})
|
||||
|
||||
exports.uploadImage = function (imagePath, callback) {
|
||||
export function uploadImage(imagePath, callback) {
|
||||
if (!imagePath || typeof imagePath !== 'string') {
|
||||
callback(new Error('Image path is missing or wrong'), null)
|
||||
return
|
||||
@ -28,16 +28,16 @@ exports.uploadImage = function (imagePath, callback) {
|
||||
|
||||
fs.readFile(imagePath, function (err, buffer) {
|
||||
if (err) {
|
||||
callback(new Error(err), null)
|
||||
callback(err, null)
|
||||
return
|
||||
}
|
||||
|
||||
const key = path.join('uploads', path.basename(imagePath))
|
||||
const protocol = config.minio.secure ? 'https' : 'http'
|
||||
|
||||
minioClient.putObject(config.s3bucket, key, buffer, buffer.size, getImageMimeType(imagePath), function (err, data) {
|
||||
minioClient.putObject(config.s3bucket, key, buffer, buffer.length, getImageMimeType(imagePath), function (err, data) {
|
||||
if (err) {
|
||||
callback(new Error(err), null)
|
||||
callback(err, null)
|
||||
return
|
||||
}
|
||||
const hidePort = [80, 443].includes(config.minio.port)
|
9
package-lock.json
generated
9
package-lock.json
generated
@ -1363,6 +1363,15 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz",
|
||||
"integrity": "sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw=="
|
||||
},
|
||||
"@types/minio": {
|
||||
"version": "7.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/minio/-/minio-7.0.7.tgz",
|
||||
"integrity": "sha512-cK0VuWZ5zvFmkxQzK46RtJ4qt2Gtrv34hsXDr0D3vqesjrnEKT+0rw0zWk40JtCPkoEFgLdIUbXnePsKjbb80Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.20.15",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.15.tgz",
|
||||
|
@ -112,6 +112,7 @@
|
||||
"@susisu/mte-kernel": "^2.1.0",
|
||||
"@types/express": "4.17.9",
|
||||
"@types/express-flash": "0.0.2",
|
||||
"@types/minio": "^7.0.7",
|
||||
"@types/node": "~12.20.15",
|
||||
"@types/qs": "^6.9.6",
|
||||
"acorn": "~6.1.1",
|
||||
|
Loading…
x
Reference in New Issue
Block a user