Skip to content

Commit

Permalink
feat: support loadConfig asynchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
gxcsoccer committed Jun 24, 2019
1 parent 93a05ea commit a0066ea
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
7 changes: 7 additions & 0 deletions app/extend/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
async createOss(...args) {
return await this.oss.createInstanceAsync.call(this.oss, ...args);
},
};
9 changes: 7 additions & 2 deletions lib/oss.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const assert = require('assert');
const is = require('is-type-of');
const OSS = require('ali-oss');
const STS = OSS.STS;
const ClusterClient = OSS.ClusterClient;
Expand All @@ -13,8 +14,12 @@ function checkBucketConfig(config) {
}

module.exports = app => {
app.addSingleton('oss', (config, app) => {
app.addSingleton('oss', async (config, app) => {
config = Object.assign({}, config, { urllib: app.httpclient });
if (is.function(config.loadConfig)) {
const result = config.loadConfig(config, app);
config = is.promise(result) ? (await result) : result;
}
if (config.cluster) {
config.cluster.forEach(checkBucketConfig);
return new ClusterClient(config);
Expand All @@ -27,5 +32,5 @@ module.exports = app => {
checkBucketConfig(config);
return new OSS(config);
});
app.createOss = app.oss.createInstance.bind(app.oss);
// app.createOss = app.oss.createInstance.bind(app.oss);
};
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
"oss"
],
"dependencies": {
"ali-oss": "^6.0.1"
"ali-oss": "^6.1.1",
"is-type-of": "^1.2.1"
},
"devDependencies": {
"autod": "^3.0.1",
"autod": "^3.1.0",
"dotenv": "^6.1.0",
"egg": "^2.11.2",
"egg-bin": "^4.9.0",
"egg-mock": "^3.20.1",
"eslint": "^5.6.1",
"eslint-config-egg": "^7.1.0",
"egg": "^2.22.2",
"egg-bin": "^4.13.0",
"egg-mock": "^3.23.1",
"eslint": "^6.0.0",
"eslint-config-egg": "^7.4.1",
"is-type-of": "^1.2.1"
},
"engines": {
Expand Down

0 comments on commit a0066ea

Please sign in to comment.