dfs-adapter 0.0.3 → 0.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/lib/declare.js +23 -36
- package/lib/fastdfs.js +61 -83
- package/lib/http.js +58 -77
- package/lib/mdfs.js +12 -37
- package/lib/minio.js +28 -53
- package/lib/native.js +30 -53
- package/lib/oss.js +35 -54
- package/package.json +1 -1
package/lib/declare.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -18,6 +9,10 @@ const path_1 = __importDefault(require("path"));
|
|
|
18
9
|
const defineDfsConfig = (config) => config;
|
|
19
10
|
exports.defineDfsConfig = defineDfsConfig;
|
|
20
11
|
class Dfs {
|
|
12
|
+
context;
|
|
13
|
+
options;
|
|
14
|
+
logger;
|
|
15
|
+
timeMap;
|
|
21
16
|
constructor(options, context) {
|
|
22
17
|
this.options = options;
|
|
23
18
|
this.context = context;
|
|
@@ -52,36 +47,28 @@ class Dfs {
|
|
|
52
47
|
stream.read();
|
|
53
48
|
});
|
|
54
49
|
}
|
|
55
|
-
startup() {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
});
|
|
50
|
+
async startup() {
|
|
51
|
+
if (this.logger.isDebugEnabled()) {
|
|
52
|
+
this.logger.info(`${this.constructor.name} is startup`);
|
|
53
|
+
}
|
|
61
54
|
}
|
|
62
|
-
upload(path, buffer, ...args) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return path;
|
|
68
|
-
});
|
|
55
|
+
async upload(path, buffer, ...args) {
|
|
56
|
+
if (this.logger.isDebugEnabled()) {
|
|
57
|
+
this.logger.info(`${this.constructor.name} upload ${path}`);
|
|
58
|
+
}
|
|
59
|
+
return path;
|
|
69
60
|
}
|
|
70
|
-
download(path, ...args) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return null;
|
|
76
|
-
});
|
|
61
|
+
async download(path, ...args) {
|
|
62
|
+
if (this.logger.isDebugEnabled()) {
|
|
63
|
+
this.logger.info(`${this.constructor.name} download ${path}`);
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
77
66
|
}
|
|
78
|
-
getAccess(path) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return '';
|
|
84
|
-
});
|
|
67
|
+
async getAccess(path) {
|
|
68
|
+
if (this.logger.isDebugEnabled()) {
|
|
69
|
+
this.logger.info(`${this.constructor.name} access ${path}`);
|
|
70
|
+
}
|
|
71
|
+
return '';
|
|
85
72
|
}
|
|
86
73
|
}
|
|
87
74
|
exports.Dfs = Dfs;
|
package/lib/fastdfs.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -19,89 +10,76 @@ const form_data_1 = __importDefault(require("form-data"));
|
|
|
19
10
|
const fs_1 = __importDefault(require("fs"));
|
|
20
11
|
const path_1 = __importDefault(require("path"));
|
|
21
12
|
class HttpDfs extends declare_1.Dfs {
|
|
13
|
+
client;
|
|
22
14
|
constructor(options, context) {
|
|
23
|
-
super(
|
|
15
|
+
super({ group: 'group1', ...options }, context);
|
|
24
16
|
this.client = axios_1.default.create();
|
|
25
17
|
}
|
|
26
|
-
startup() {
|
|
27
|
-
|
|
28
|
-
startup: { get: () => super.startup }
|
|
29
|
-
});
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
return _super.startup.call(this);
|
|
32
|
-
});
|
|
18
|
+
async startup() {
|
|
19
|
+
return super.startup();
|
|
33
20
|
}
|
|
34
|
-
upload(path, buffer) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
21
|
+
async upload(path, buffer) {
|
|
22
|
+
try {
|
|
23
|
+
this.timeBegin(`upload ${path}`);
|
|
24
|
+
let { name, dir, ext } = path_1.default.parse(path);
|
|
25
|
+
let tmpFile = this.getTmpFile(`${vweb_core_1.util.snowflake.nextId()}${ext}`);
|
|
26
|
+
fs_1.default.writeFileSync(tmpFile, buffer);
|
|
27
|
+
const { domain, group, token } = this.options;
|
|
28
|
+
let form = new form_data_1.default();
|
|
29
|
+
form.append('file', fs_1.default.createReadStream(tmpFile));
|
|
30
|
+
form.append('filename', `${name}${ext}`);
|
|
31
|
+
if (token) {
|
|
32
|
+
form.append('auth_token', token);
|
|
33
|
+
}
|
|
34
|
+
form.append('path', dir);
|
|
35
|
+
let headers = form.getHeaders();
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
form.getLength((err, length) => {
|
|
38
|
+
if (err) {
|
|
39
|
+
reject(err);
|
|
40
|
+
}
|
|
41
|
+
headers['contentLength'] = length;
|
|
42
|
+
axios_1.default.post(`${domain}/${group}/upload`, form, {
|
|
43
|
+
maxContentLength: Infinity,
|
|
44
|
+
maxBodyLength: Infinity,
|
|
45
|
+
headers
|
|
46
|
+
}).then(({ data }) => {
|
|
47
|
+
resolve(path);
|
|
48
|
+
}).catch(err => {
|
|
49
|
+
reject(err);
|
|
50
|
+
}).finally(() => {
|
|
51
|
+
if (fs_1.default.existsSync(tmpFile)) {
|
|
52
|
+
fs_1.default.rmSync(tmpFile);
|
|
54
53
|
}
|
|
55
|
-
headers['contentLength'] = length;
|
|
56
|
-
axios_1.default.post(`${domain}/${group}/upload`, form, {
|
|
57
|
-
maxContentLength: Infinity,
|
|
58
|
-
maxBodyLength: Infinity,
|
|
59
|
-
headers
|
|
60
|
-
}).then(({ data }) => {
|
|
61
|
-
resolve(path);
|
|
62
|
-
}).catch(err => {
|
|
63
|
-
reject(err);
|
|
64
|
-
}).finally(() => {
|
|
65
|
-
if (fs_1.default.existsSync(tmpFile)) {
|
|
66
|
-
fs_1.default.rmSync(tmpFile);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
54
|
});
|
|
70
55
|
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
download(path, ...args) {
|
|
78
|
-
const _super = Object.create(null, {
|
|
79
|
-
download: { get: () => super.download }
|
|
80
|
-
});
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
try {
|
|
83
|
-
const { domain, group } = this.options;
|
|
84
|
-
this.timeBegin(`download ${path}`);
|
|
85
|
-
const { status, data } = yield axios_1.default.get(`${domain}/${group}${path}`, { responseType: 'arraybuffer' });
|
|
86
|
-
yield _super.download.call(this, path, ...args);
|
|
87
|
-
return data;
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
this.logger.error(`download ${path} error >>> ${e.message}`);
|
|
91
|
-
}
|
|
92
|
-
finally {
|
|
93
|
-
this.timeEnd(`download ${path}`);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
this.timeEnd(`upload ${path}`);
|
|
60
|
+
}
|
|
96
61
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (this.options.access) {
|
|
100
|
-
return `${this.options.access}/dfs/get?filename=${path}`;
|
|
101
|
-
}
|
|
62
|
+
async download(path, ...args) {
|
|
63
|
+
try {
|
|
102
64
|
const { domain, group } = this.options;
|
|
103
|
-
|
|
104
|
-
|
|
65
|
+
this.timeBegin(`download ${path}`);
|
|
66
|
+
const { status, data } = await axios_1.default.get(`${domain}/${group}${path}`, { responseType: 'arraybuffer' });
|
|
67
|
+
await super.download(path, ...args);
|
|
68
|
+
return data;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
this.logger.error(`download ${path} error >>> ${e.message}`);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
this.timeEnd(`download ${path}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async getAccess(path) {
|
|
78
|
+
if (this.options.access) {
|
|
79
|
+
return `${this.options.access}/dfs/get?filename=${path}`;
|
|
80
|
+
}
|
|
81
|
+
const { domain, group } = this.options;
|
|
82
|
+
return `${domain}/${group}${path}`;
|
|
105
83
|
}
|
|
106
84
|
}
|
|
107
85
|
exports.default = HttpDfs;
|
package/lib/http.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -19,86 +10,76 @@ const form_data_1 = __importDefault(require("form-data"));
|
|
|
19
10
|
const path_1 = __importDefault(require("path"));
|
|
20
11
|
const fs_1 = __importDefault(require("fs"));
|
|
21
12
|
class HttpDfs extends declare_1.Dfs {
|
|
13
|
+
client;
|
|
22
14
|
constructor(options, context) {
|
|
23
15
|
super(options, context);
|
|
24
16
|
this.client = axios_1.default.create({
|
|
25
17
|
headers: options.headers
|
|
26
18
|
});
|
|
27
19
|
}
|
|
28
|
-
startup() {
|
|
29
|
-
|
|
30
|
-
startup: { get: () => super.startup }
|
|
31
|
-
});
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
return _super.startup.call(this);
|
|
34
|
-
});
|
|
20
|
+
async startup() {
|
|
21
|
+
return super.startup();
|
|
35
22
|
}
|
|
36
|
-
upload(path, buffer, ...args) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
23
|
+
async upload(path, buffer, ...args) {
|
|
24
|
+
try {
|
|
25
|
+
this.timeBegin(`upload ${path}`);
|
|
26
|
+
let { name, dir, ext } = path_1.default.parse(path);
|
|
27
|
+
let tmpFile = this.getTmpFile(`${vweb_core_1.util.snowflake.nextId()}${ext}`);
|
|
28
|
+
fs_1.default.writeFileSync(tmpFile, buffer);
|
|
29
|
+
let form = new form_data_1.default();
|
|
30
|
+
form.append('file', fs_1.default.createReadStream(tmpFile));
|
|
31
|
+
form.append('filename', `${name}${ext}`);
|
|
32
|
+
form.append('path', path);
|
|
33
|
+
let headers = form.getHeaders();
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
form.getLength((err, length) => {
|
|
36
|
+
if (err) {
|
|
37
|
+
reject(err);
|
|
38
|
+
}
|
|
39
|
+
headers['contentLength'] = length;
|
|
40
|
+
axios_1.default.post(this.options.url, form, {
|
|
41
|
+
maxContentLength: Infinity,
|
|
42
|
+
maxBodyLength: Infinity,
|
|
43
|
+
headers,
|
|
44
|
+
params: this.options.body
|
|
45
|
+
}).then(({ data }) => {
|
|
46
|
+
resolve(path);
|
|
47
|
+
}).catch(err => {
|
|
48
|
+
reject(err);
|
|
49
|
+
}).finally(() => {
|
|
50
|
+
if (fs_1.default.existsSync(tmpFile)) {
|
|
51
|
+
fs_1.default.rmSync(tmpFile);
|
|
52
52
|
}
|
|
53
|
-
headers['contentLength'] = length;
|
|
54
|
-
axios_1.default.post(this.options.url, form, {
|
|
55
|
-
maxContentLength: Infinity,
|
|
56
|
-
maxBodyLength: Infinity,
|
|
57
|
-
headers,
|
|
58
|
-
params: this.options.body
|
|
59
|
-
}).then(({ data }) => {
|
|
60
|
-
resolve(path);
|
|
61
|
-
}).catch(err => {
|
|
62
|
-
reject(err);
|
|
63
|
-
}).finally(() => {
|
|
64
|
-
if (fs_1.default.existsSync(tmpFile)) {
|
|
65
|
-
fs_1.default.rmSync(tmpFile);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
53
|
});
|
|
69
54
|
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
this.timeEnd(`upload ${path}`);
|
|
59
|
+
}
|
|
75
60
|
}
|
|
76
|
-
download(path, ...args) {
|
|
77
|
-
|
|
78
|
-
download
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
});
|
|
61
|
+
async download(path, ...args) {
|
|
62
|
+
try {
|
|
63
|
+
this.timeBegin(`download ${path}`);
|
|
64
|
+
const { data } = await axios_1.default.get(this.options.url, {
|
|
65
|
+
params: {
|
|
66
|
+
filename: path,
|
|
67
|
+
...this.options.body
|
|
68
|
+
},
|
|
69
|
+
responseType: 'arraybuffer'
|
|
70
|
+
});
|
|
71
|
+
await super.download(path, ...args);
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
this.timeEnd(`download ${path}`);
|
|
76
|
+
}
|
|
94
77
|
}
|
|
95
|
-
getAccess(path) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return `${this.options.url}?filename=${path}`;
|
|
101
|
-
});
|
|
78
|
+
async getAccess(path) {
|
|
79
|
+
if (this.options.access) {
|
|
80
|
+
return `${this.options.access}/dfs/get?filename=${path}`;
|
|
81
|
+
}
|
|
82
|
+
return `${this.options.url}?filename=${path}`;
|
|
102
83
|
}
|
|
103
84
|
}
|
|
104
85
|
exports.default = HttpDfs;
|
package/lib/mdfs.js
CHANGED
|
@@ -1,28 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
3
|
const vweb_core_1 = require("vweb-core");
|
|
24
4
|
const declare_1 = require("./declare");
|
|
25
5
|
class MDFSHttpListenerWrapper {
|
|
6
|
+
annotation;
|
|
26
7
|
constructor() {
|
|
27
8
|
this.annotation = {
|
|
28
9
|
type: "controller",
|
|
@@ -41,33 +22,27 @@ class MDFSHttpListenerWrapper {
|
|
|
41
22
|
}
|
|
42
23
|
}
|
|
43
24
|
class Mdfs extends declare_1.Dfs {
|
|
25
|
+
dfs;
|
|
26
|
+
config;
|
|
44
27
|
constructor(config, context) {
|
|
45
28
|
super(config, context);
|
|
46
29
|
this.config = config;
|
|
47
30
|
context.trusteeship(new MDFSHttpListenerWrapper());
|
|
48
|
-
const
|
|
31
|
+
const { config: { type, ...options } } = this;
|
|
49
32
|
let Type = require(`./${type}`).default;
|
|
50
33
|
this.dfs = new Type(options, context);
|
|
51
34
|
}
|
|
52
|
-
startup() {
|
|
53
|
-
return
|
|
54
|
-
return this.dfs.startup();
|
|
55
|
-
});
|
|
35
|
+
async startup() {
|
|
36
|
+
return this.dfs.startup();
|
|
56
37
|
}
|
|
57
|
-
upload(path, buffer, ...args) {
|
|
58
|
-
return
|
|
59
|
-
return this.dfs.upload(path, buffer, ...args);
|
|
60
|
-
});
|
|
38
|
+
async upload(path, buffer, ...args) {
|
|
39
|
+
return this.dfs.upload(path, buffer, ...args);
|
|
61
40
|
}
|
|
62
|
-
download(path, ...args) {
|
|
63
|
-
return
|
|
64
|
-
return this.dfs.download(path, ...args);
|
|
65
|
-
});
|
|
41
|
+
async download(path, ...args) {
|
|
42
|
+
return this.dfs.download(path, ...args);
|
|
66
43
|
}
|
|
67
|
-
getAccess(path) {
|
|
68
|
-
return
|
|
69
|
-
return this.dfs.getAccess(path);
|
|
70
|
-
});
|
|
44
|
+
async getAccess(path) {
|
|
45
|
+
return this.dfs.getAccess(path);
|
|
71
46
|
}
|
|
72
47
|
}
|
|
73
48
|
exports.default = Mdfs;
|
package/lib/minio.js
CHANGED
|
@@ -22,69 +22,44 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
const declare_1 = require("./declare");
|
|
36
27
|
const minio = __importStar(require("minio"));
|
|
37
28
|
class MinioDfs extends declare_1.Dfs {
|
|
29
|
+
client;
|
|
38
30
|
constructor(options, context) {
|
|
39
|
-
super(
|
|
31
|
+
super({ accessKey: '', secretKey: '', ...options }, context);
|
|
40
32
|
this.client = new minio.Client(this.options);
|
|
41
33
|
}
|
|
42
|
-
startup() {
|
|
43
|
-
|
|
44
|
-
startup: { get: () => super.startup }
|
|
45
|
-
});
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
return _super.startup.call(this);
|
|
48
|
-
});
|
|
34
|
+
async startup() {
|
|
35
|
+
return super.startup();
|
|
49
36
|
}
|
|
50
|
-
upload(path, buffer, ...args) {
|
|
51
|
-
|
|
52
|
-
upload
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
finally {
|
|
61
|
-
this.timeEnd(`upload ${path}`);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
37
|
+
async upload(path, buffer, ...args) {
|
|
38
|
+
try {
|
|
39
|
+
this.timeBegin(`upload ${path}`);
|
|
40
|
+
await this.client.putObject(this.options.bucketName, path, buffer, ...args);
|
|
41
|
+
return super.upload(path, buffer, ...args);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
this.timeEnd(`upload ${path}`);
|
|
45
|
+
}
|
|
64
46
|
}
|
|
65
|
-
download(path, ...args) {
|
|
66
|
-
|
|
67
|
-
download
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
this.timeEnd(`download ${path}`);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
47
|
+
async download(path, ...args) {
|
|
48
|
+
try {
|
|
49
|
+
this.timeBegin(`download ${path}`);
|
|
50
|
+
await super.download(path, ...args);
|
|
51
|
+
let stream = await this.client.getObject(this.options.bucketName, path);
|
|
52
|
+
return await this.stream2buffer(stream);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
this.timeEnd(`download ${path}`);
|
|
56
|
+
}
|
|
80
57
|
}
|
|
81
|
-
getAccess(path) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return `http://${this.options.endPoint}:${this.options.port}/${this.options.bucketName}${path}`;
|
|
87
|
-
});
|
|
58
|
+
async getAccess(path) {
|
|
59
|
+
if (this.options.access) {
|
|
60
|
+
return `${this.options.access}/dfs/get?filename=${path}`;
|
|
61
|
+
}
|
|
62
|
+
return `http://${this.options.endPoint}:${this.options.port}/${this.options.bucketName}${path}`;
|
|
88
63
|
}
|
|
89
64
|
}
|
|
90
65
|
exports.default = MinioDfs;
|
package/lib/native.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
@@ -41,54 +32,40 @@ const fs = __importStar(require("fs"));
|
|
|
41
32
|
const path_1 = __importDefault(require("path"));
|
|
42
33
|
class NativeDfs extends declare_1.Dfs {
|
|
43
34
|
constructor(options, context) {
|
|
44
|
-
super(
|
|
35
|
+
super({
|
|
36
|
+
...options,
|
|
37
|
+
storage: path_1.default.resolve(options.storage)
|
|
38
|
+
}, context);
|
|
45
39
|
}
|
|
46
|
-
startup() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
vweb_core_1.util.file.forceMkDirSync(this.options.storage);
|
|
52
|
-
return _super.startup.call(this);
|
|
53
|
-
});
|
|
40
|
+
async startup() {
|
|
41
|
+
vweb_core_1.util.file.forceMkDirSync(this.options.storage);
|
|
42
|
+
return super.startup();
|
|
54
43
|
}
|
|
55
|
-
upload(path, buffer) {
|
|
56
|
-
|
|
57
|
-
upload
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
finally {
|
|
69
|
-
this.timeEnd(`upload ${path}`);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
44
|
+
async upload(path, buffer) {
|
|
45
|
+
try {
|
|
46
|
+
this.timeBegin(`upload ${path}`);
|
|
47
|
+
let file = `${this.options.storage}${path}`;
|
|
48
|
+
let { dir } = path_1.default.parse(file);
|
|
49
|
+
vweb_core_1.util.file.forceMkDirSync(dir);
|
|
50
|
+
fs.writeFileSync(file, buffer);
|
|
51
|
+
return super.upload(path, buffer);
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
this.timeEnd(`upload ${path}`);
|
|
55
|
+
}
|
|
72
56
|
}
|
|
73
|
-
download(path) {
|
|
74
|
-
|
|
75
|
-
download
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
finally {
|
|
84
|
-
this.timeEnd(`download ${path}`);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
57
|
+
async download(path) {
|
|
58
|
+
try {
|
|
59
|
+
this.timeBegin(`download ${path}`);
|
|
60
|
+
await super.download(path);
|
|
61
|
+
return fs.readFileSync(`${this.options.storage}${path}`);
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
this.timeEnd(`download ${path}`);
|
|
65
|
+
}
|
|
87
66
|
}
|
|
88
|
-
getAccess(path) {
|
|
89
|
-
return
|
|
90
|
-
return `${this.options.access}/dfs/get?filename=${path}`;
|
|
91
|
-
});
|
|
67
|
+
async getAccess(path) {
|
|
68
|
+
return `${this.options.access}/dfs/get?filename=${path}`;
|
|
92
69
|
}
|
|
93
70
|
}
|
|
94
71
|
exports.default = NativeDfs;
|
package/lib/oss.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -16,63 +7,53 @@ const declare_1 = require("./declare");
|
|
|
16
7
|
const ali_oss_1 = __importDefault(require("ali-oss"));
|
|
17
8
|
const fs_1 = __importDefault(require("fs"));
|
|
18
9
|
class OssDfs extends declare_1.Dfs {
|
|
10
|
+
client;
|
|
19
11
|
constructor(options, context) {
|
|
20
12
|
super(options, context);
|
|
21
13
|
this.client = new ali_oss_1.default(options);
|
|
22
14
|
}
|
|
23
|
-
startup() {
|
|
24
|
-
|
|
25
|
-
startup: { get: () => super.startup }
|
|
26
|
-
});
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
return _super.startup.call(this);
|
|
29
|
-
});
|
|
15
|
+
async startup() {
|
|
16
|
+
return super.startup();
|
|
30
17
|
}
|
|
31
|
-
upload(path, buffer, ...args) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
result = yield this.client.put(path, buffer, ...args);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
result = yield this.client.put(path, Buffer.from(buffer), ...args);
|
|
45
|
-
}
|
|
18
|
+
async upload(path, buffer, ...args) {
|
|
19
|
+
try {
|
|
20
|
+
this.timeBegin(`upload ${path}`);
|
|
21
|
+
let result;
|
|
22
|
+
if (buffer.constructor.name === 'Buffer') {
|
|
23
|
+
result = await this.client.put(path, buffer, ...args);
|
|
24
|
+
}
|
|
25
|
+
else if (typeof buffer === 'string') {
|
|
26
|
+
if (fs_1.default.existsSync(buffer)) {
|
|
27
|
+
result = await this.client.put(path, buffer, ...args);
|
|
46
28
|
}
|
|
47
29
|
else {
|
|
48
|
-
result =
|
|
30
|
+
result = await this.client.put(path, Buffer.from(buffer), ...args);
|
|
49
31
|
}
|
|
50
|
-
return path;
|
|
51
32
|
}
|
|
52
|
-
|
|
53
|
-
this.
|
|
33
|
+
else {
|
|
34
|
+
result = await this.client.putStream(path, buffer, ...args);
|
|
54
35
|
}
|
|
55
|
-
|
|
36
|
+
return path;
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
this.timeEnd(`upload ${path}`);
|
|
40
|
+
}
|
|
56
41
|
}
|
|
57
|
-
download(path, ...args) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
});
|
|
42
|
+
async download(path, ...args) {
|
|
43
|
+
try {
|
|
44
|
+
this.timeBegin(`download ${path}`);
|
|
45
|
+
const result = await this.client.getStream(path, ...args);
|
|
46
|
+
return this.stream2buffer(result.stream);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
this.timeEnd(`download ${path}`);
|
|
50
|
+
}
|
|
68
51
|
}
|
|
69
|
-
getAccess(path) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return this.client.getObjectUrl(path, this.options.access);
|
|
75
|
-
});
|
|
52
|
+
async getAccess(path) {
|
|
53
|
+
if (this.options.access) {
|
|
54
|
+
return `${this.options.access}/dfs/get?filename=${path}`;
|
|
55
|
+
}
|
|
56
|
+
return this.client.getObjectUrl(path, this.options.access);
|
|
76
57
|
}
|
|
77
58
|
}
|
|
78
59
|
exports.default = OssDfs;
|