|
|
@@ -2,8 +2,8 @@ import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
const logger = loggerFactory('growi:service:fileUploaderAws');
|
|
|
|
|
|
-const urljoin = require('url-join');
|
|
|
const { Storage } = require('@google-cloud/storage');
|
|
|
+const urljoin = require('url-join');
|
|
|
|
|
|
let _instance;
|
|
|
|
|
|
@@ -17,11 +17,20 @@ module.exports = function(crowi) {
|
|
|
return configManager.getConfig('crowi', 'gcs:bucket');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * see https://googleapis.dev/nodejs/storage/latest/Storage.html
|
|
|
+ */
|
|
|
function getGcsInstance() {
|
|
|
if (_instance == null) {
|
|
|
const keyFilename = configManager.getConfig('crowi', 'gcs:apiKeyJsonPath');
|
|
|
- // see https://googleapis.dev/nodejs/storage/latest/Storage.html
|
|
|
- _instance = new Storage({ keyFilename });
|
|
|
+ if (keyFilename == null) {
|
|
|
+ // Create a client that uses Application Default Credentials
|
|
|
+ _instance = new Storage();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // Create a client with explicit credentials
|
|
|
+ _instance = new Storage({ keyFilename });
|
|
|
+ }
|
|
|
}
|
|
|
return _instance;
|
|
|
}
|