"use strict";
/**
 * 华为云对象存储服务obs
 * @date 2022-08-09 11:55:58
 * @author 黄家维
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HuaWeiObsService = exports.HuaWeiObsResponse = exports.obsClient = void 0;
var mslib_1 = require("mslib");
var typescript_ioc_1 = require("typescript-ioc");
var Config_1 = require("./Config");
var Contants_1 = require("./Contants");
function init() {
    try {
        var ObsClient = require('esdk-obs-nodejs');
        exports.obsClient = new ObsClient({
            access_key_id: 'NZEGUDBCFFAXKOODXAYT',
            secret_access_key: '6idSEUUwrguY22GmmXZWIGE0LYGYTn9lyPBN2Slj',
            server: 'obs.cn-east-3.myhuaweicloud.com',
        });
    }
    catch (error) {
        mslib_1.logger.error('huawei-obs客户端实例创建失败', error);
    }
}
/**
 * 非标桶
 */
var non_standard_bucket = 'ddd-nonstandar';
var accessBaseUrl = 'http://dddfile.keytop.cn';
/**
 * 华为obs响应
 */
var HuaWeiObsResponse = /** @class */ (function () {
    function HuaWeiObsResponse() {
    }
    /**
     * 判断华为接口响应是否成功
     */
    HuaWeiObsResponse.statusIsSuccess = function (status) {
        return status === 200;
    };
    return HuaWeiObsResponse;
}());
exports.HuaWeiObsResponse = HuaWeiObsResponse;
var HuaWeiObsService = /** @class */ (function () {
    function HuaWeiObsService() {
    }
    HuaWeiObsService.prototype.getRootPath = function () {
        var _a;
        return Contants_1.default.P_ID || ((_a = Config_1.IocConfigProvider.getBasicConfig()) === null || _a === void 0 ? void 0 : _a.tapdId) || 'tapdId';
    };
    /**
     * 上传对象到huawei-obs
     */
    HuaWeiObsService.prototype.put = function (data, name) {
        var _this = this;
        return new Promise(function (resolve, reject) {
            var fullname = _this.getRootPath() + "/" + name;
            exports.obsClient.putObject({
                Bucket: non_standard_bucket,
                Key: fullname,
                Body: data
            }, function (err, res) {
                if (err)
                    reject(err);
                if (!HuaWeiObsResponse.statusIsSuccess(res === null || res === void 0 ? void 0 : res.CommonMsg.Status)) {
                    reject(res);
                }
                var url = accessBaseUrl + "/" + fullname;
                mslib_1.logger.info("huawei-obs \u4E0A\u4F20\u5BF9\u8C61\u6210\u529F,\u5BF9\u8C61\u8BBF\u95EE\u5730\u5740:" + url);
                resolve(url);
            });
        });
    };
    HuaWeiObsService = __decorate([
        typescript_ioc_1.Singleton
    ], HuaWeiObsService);
    return HuaWeiObsService;
}());
exports.HuaWeiObsService = HuaWeiObsService;
//# sourceMappingURL=HuaWeiObs.js.map