Unverified Commit 2fe10a78 authored by Raccoon's avatar Raccoon

chore: change aws-sdk to @aws-sdk/client-s3-node, reduced module size

Signed-off-by: default avatarRaccoon <raccoon@hackmd.io>
parent a048b587
......@@ -6,9 +6,10 @@ const config = require('../config')
const { getImageMimeType } = require('../utils')
const logger = require('../logger')
const AWS = require('aws-sdk')
const awsConfig = new AWS.Config(config.s3)
const s3 = new AWS.S3(awsConfig)
const { S3Client } = require('@aws-sdk/client-s3-node/S3Client')
const { PutObjectCommand } = require('@aws-sdk/client-s3-node/commands/PutObjectCommand')
const s3 = new S3Client(config.s3)
exports.uploadImage = function (imagePath, callback) {
if (!imagePath || typeof imagePath !== 'string') {
......@@ -32,16 +33,12 @@ exports.uploadImage = function (imagePath, callback) {
Body: buffer,
ACL: 'public-read'
}
const mimeType = getImageMimeType(imagePath)
if (mimeType) { params.ContentType = mimeType }
s3.putObject(params, function (err, data) {
if (err) {
callback(new Error(err), null)
return
}
const command = new PutObjectCommand(params)
s3.send(command).then(data => {
let s3Endpoint = 's3.amazonaws.com'
if (config.s3.endpoint) {
s3Endpoint = config.s3.endpoint
......@@ -49,6 +46,10 @@ exports.uploadImage = function (imagePath, callback) {
s3Endpoint = `s3-${config.s3.region}.amazonaws.com`
}
callback(null, `https://${s3Endpoint}/${config.s3bucket}/${params.Key}`)
}).catch(err => {
if (err) {
callback(new Error(err), null)
}
})
})
}
This diff is collapsed.
......@@ -30,6 +30,7 @@
"postinstall": "bin/heroku"
},
"dependencies": {
"@aws-sdk/client-s3-node": "0.1.0-preview.2",
"@hackmd/diff-match-patch": "~1.1.3",
"@hackmd/imgur": "~0.5.0",
"@hackmd/lz-string": "~1.4.4",
......@@ -38,7 +39,6 @@
"@passport-next/passport-openid": "~1.0.0",
"archiver": "~3.1.1",
"async": "~3.1.0",
"aws-sdk": "~2.503.0",
"azure-storage": "~2.10.3",
"babel-polyfill": "~6.26.0",
"base64url": "~3.0.1",
......
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