steam-family-bot-core
Version:
一个用于新版 Steam 家庭的库存监控 Bot 插件
45 lines • 1.67 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TmpFileStorage = void 0;
const client_s3_1 = require("@aws-sdk/client-s3");
const crypto_1 = __importDefault(require("crypto"));
class TmpFileStorage {
s3Client;
bucket;
keyPrefix = '';
baseURL = '';
// env sdk, env
constructor(config) {
const s3 = new client_s3_1.S3Client({
region: config.uploadImageToS3.region ?? 'auto',
endpoint: config.uploadImageToS3.endpoint,
credentials: {
accessKeyId: config.uploadImageToS3.s3AccessKey,
secretAccessKey: config.uploadImageToS3.s3SecretKey,
},
});
this.bucket = config.uploadImageToS3.bucketName;
this.keyPrefix = config.uploadImageToS3.keyPrefix;
this.baseURL = config.uploadImageToS3.baseURL;
this.s3Client = s3;
}
async uploadImg(buffer, mimeType) {
// md5 digest
const md5 = crypto_1.default.createHash('md5').update(buffer).digest('hex');
const key = this.keyPrefix ? `${this.keyPrefix}-${md5}` : md5;
const params = {
Bucket: this.bucket,
Key: key,
Body: buffer,
ContentType: mimeType ?? 'image/png',
};
const command = new client_s3_1.PutObjectCommand(params);
const data = await this.s3Client.send(command);
return `${this.baseURL}${key}`;
}
}
exports.TmpFileStorage = TmpFileStorage;
//# sourceMappingURL=s3.js.map