Adds an image connector; introduces file service

This commit is contained in:
Sebastian Rindom committed 2020-07-07 14:36:48 +02:00
1 parent 8c5fa44e5f
commit 716415263d
16 files changed
+314 -9

No files matched your search

@@ -0,0 +1,51 @@
import fs from "fs"
import aws from "aws-sdk"
import { FileService } from "medusa-interfaces"
class DigitalOceanService extends FileService {
constructor({}, options) {
super()
this.bucket_ = options.bucket
this.spacesUrl_ = options.spaces_url
this.accessKeyId_ = options.access_key_id
this.secretAccessKey_ = options.secret_access_key
this.region_ = options.region
this.endpoint_ = options.endpoint
}
upload(file) {
aws.config.setPromisesDependency();
aws.config.update({
accessKeyId: this.accessKeyId_,
secretAccessKey: this.secretAccessKey_,
region: this.region_,
endpoint: this.endpoint_,
});
const s3 = new aws.S3();
var params = {
ACL: 'public-read',
Bucket: this.bucket_,
Body: fs.createReadStream(file.path),
Key: `${file.originalname}`
}
return new Promise((resolve, reject) => {
s3.upload(params, (err, data) => {
if (err) {
reject(err)
return
}
resolve({ url: data.Location })
})
})
}
delete(file) {
console.log(file)
}
}
export default DigitalOceanService