UNPKG

wepy-plugin-resources-cdn

Version:
79 lines (59 loc) 2.58 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _aliOss = require('ali-oss'); var _aliOss2 = _interopRequireDefault(_aliOss); var _promise = require('promise'); var _promise2 = _interopRequireDefault(_promise); var _utils = require('../../utils'); var _utils2 = _interopRequireDefault(_utils); var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var OssDriver = function () { function OssDriver(options) { _classCallCheck(this, OssDriver); this.options = options; this.options.oss = Object.assign({ internal: false, secure: false, endpoint: null, cname: false, timeout: 60000 }, this.options.oss); this.options.oss.timeout = this.options.oss.timeout || 60000; this.client = new _aliOss2.default({ region: this.options.oss.region, accessKeyId: this.options.oss.accessKeyId, accessKeySecret: this.options.oss.accessKeySecret, bucket: this.options.oss.bucket, internal: this.options.oss.internal, secure: this.options.oss.secure, endpoint: this.options.oss.endpoint, cname: this.options.oss.cname, timeout: this.options.oss.timeout }); } _createClass(OssDriver, [{ key: 'uploader', value: function uploader(remotePath, localFile) { var _this = this; return new _promise2.default(function (resolve, reject) { try { _this.client.put(remotePath, localFile).then(function (res) { resolve(_utils2.default.responeCdn(res.url, res)); }).catch(function (err) { reject(err); }); } catch (e) { reject(e); } }); } }]); return OssDriver; }(); exports.default = OssDriver;