express-sharp
Version:
Real-time image processing for your express application
31 lines • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.S3Adapter = void 0;
const aws_sdk_1 = require("aws-sdk");
const logger_1 = require("../logger");
class S3Adapter {
constructor(bucketName, s3client = new aws_sdk_1.S3()) {
this.bucketName = bucketName;
this.s3client = s3client;
this.log = logger_1.getLogger('adapter:s3');
this.log(`Using bucket name: ${bucketName}`);
}
async fetch(id) {
this.log(`Fetching image "${id}" from bucket "${this.bucketName}"`);
try {
const object = await this.s3client
.getObject({ Bucket: this.bucketName, Key: id })
.promise();
if (!Buffer.isBuffer(object.Body)) {
return undefined;
}
return object.Body;
}
catch (error) {
this.log(`Fetching bucket "${id}" failed: ${JSON.stringify(error)}`);
return undefined;
}
}
}
exports.S3Adapter = S3Adapter;
//# sourceMappingURL=s3.adapter.js.map