doomistorage 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/filehelper.js +16 -0
- package/package.json +1 -1
- package/src/filehelper.ts +18 -2
package/dist/filehelper.js
CHANGED
|
@@ -17,6 +17,19 @@ const cosfile_1 = require("./cosfile");
|
|
|
17
17
|
const localfile_1 = require("./localfile");
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const fs_1 = __importDefault(require("fs"));
|
|
21
|
+
/**
|
|
22
|
+
* 读取系统配置文件的腾讯云设置
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
function getConfigurationSetting(settingName) {
|
|
26
|
+
let configfilename = process.env["CONFIGFILE"] || 'configuration.json';
|
|
27
|
+
let configfile = path_1.default.join(process.cwd(), configfilename);
|
|
28
|
+
if (!fs_1.default.existsSync(configfile))
|
|
29
|
+
return null;
|
|
30
|
+
const config = require(configfile)[settingName || 'tencentCOS'];
|
|
31
|
+
return config;
|
|
32
|
+
}
|
|
20
33
|
/**
|
|
21
34
|
* 文件处理器类型
|
|
22
35
|
*/
|
|
@@ -36,6 +49,9 @@ function FileHelper(provider, apiOption) {
|
|
|
36
49
|
filehandler = new localfile_1.LocalFile();
|
|
37
50
|
break;
|
|
38
51
|
case exports.FileProviderEnum.TENCENTCOS:
|
|
52
|
+
if (!apiOption || typeof (apiOption) == 'string') {
|
|
53
|
+
apiOption = getConfigurationSetting(apiOption);
|
|
54
|
+
}
|
|
39
55
|
filehandler = new cosfile_1.CosFile(apiOption);
|
|
40
56
|
break;
|
|
41
57
|
default: filehandler = new localfile_1.LocalFile();
|
package/package.json
CHANGED
package/src/filehelper.ts
CHANGED
|
@@ -4,7 +4,18 @@ import { FileBase } from "./file";
|
|
|
4
4
|
import { LocalFile } from "./localfile";
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import path from 'path';
|
|
7
|
-
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
/**
|
|
9
|
+
* 读取系统配置文件的腾讯云设置
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
function getConfigurationSetting(settingName?:string):any{
|
|
13
|
+
let configfilename = process.env["CONFIGFILE"] || 'configuration.json'
|
|
14
|
+
let configfile = path.join(process.cwd(), configfilename);
|
|
15
|
+
if (!fs.existsSync(configfile)) return null;
|
|
16
|
+
const config = require(configfile)[settingName || 'tencentCOS'];
|
|
17
|
+
return config;
|
|
18
|
+
}
|
|
8
19
|
/**
|
|
9
20
|
* 文件处理器类型
|
|
10
21
|
*/
|
|
@@ -22,7 +33,12 @@ export function FileHelper(provider: FileProviderEnum, apiOption?: any): FileUti
|
|
|
22
33
|
let filehandler: FileBase
|
|
23
34
|
switch (provider) {
|
|
24
35
|
case FileProviderEnum.LOCAL: filehandler = new LocalFile(); break;
|
|
25
|
-
case FileProviderEnum.TENCENTCOS:
|
|
36
|
+
case FileProviderEnum.TENCENTCOS:
|
|
37
|
+
if (!apiOption || typeof (apiOption)=='string'){
|
|
38
|
+
apiOption = getConfigurationSetting(apiOption)
|
|
39
|
+
}
|
|
40
|
+
filehandler = new CosFile(apiOption);
|
|
41
|
+
break;
|
|
26
42
|
default: filehandler = new LocalFile();
|
|
27
43
|
}
|
|
28
44
|
return new FileUtility(filehandler)
|