dfs-adapter 0.0.3 → 0.0.5

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 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
- return __awaiter(this, void 0, void 0, function* () {
57
- if (this.logger.isDebugEnabled()) {
58
- this.logger.info(`${this.constructor.name} is startup`);
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
- return __awaiter(this, void 0, void 0, function* () {
64
- if (this.logger.isDebugEnabled()) {
65
- this.logger.info(`${this.constructor.name} upload ${path}`);
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
- return __awaiter(this, void 0, void 0, function* () {
72
- if (this.logger.isDebugEnabled()) {
73
- this.logger.info(`${this.constructor.name} download ${path}`);
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
- return __awaiter(this, void 0, void 0, function* () {
80
- if (this.logger.isDebugEnabled()) {
81
- this.logger.info(`${this.constructor.name} access ${path}`);
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(Object.assign({ group: 'group1' }, options), context);
15
+ super({ group: 'group1', ...options }, context);
24
16
  this.client = axios_1.default.create();
25
17
  }
26
- startup() {
27
- const _super = Object.create(null, {
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
- return __awaiter(this, void 0, void 0, function* () {
36
- try {
37
- this.timeBegin(`upload ${path}`);
38
- let { name, dir, ext } = path_1.default.parse(path);
39
- let tmpFile = this.getTmpFile(`${vweb_core_1.util.snowflake.nextId()}${ext}`);
40
- fs_1.default.writeFileSync(tmpFile, buffer);
41
- const { domain, group, token } = this.options;
42
- let form = new form_data_1.default();
43
- form.append('file', fs_1.default.createReadStream(tmpFile));
44
- form.append('filename', `${name}${ext}`);
45
- if (token) {
46
- form.append('auth_token', token);
47
- }
48
- form.append('path', dir);
49
- let headers = form.getHeaders();
50
- return new Promise((resolve, reject) => {
51
- form.getLength((err, length) => {
52
- if (err) {
53
- reject(err);
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
- finally {
73
- this.timeEnd(`upload ${path}`);
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
- getAccess(path) {
98
- return __awaiter(this, void 0, void 0, function* () {
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
- return `${domain}/${group}${path}`;
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
- const _super = Object.create(null, {
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
- return __awaiter(this, void 0, void 0, function* () {
38
- try {
39
- this.timeBegin(`upload ${path}`);
40
- let { name, dir, ext } = path_1.default.parse(path);
41
- let tmpFile = this.getTmpFile(`${vweb_core_1.util.snowflake.nextId()}${ext}`);
42
- fs_1.default.writeFileSync(tmpFile, buffer);
43
- let form = new form_data_1.default();
44
- form.append('file', fs_1.default.createReadStream(tmpFile));
45
- form.append('filename', `${name}${ext}`);
46
- form.append('path', path);
47
- let headers = form.getHeaders();
48
- return new Promise((resolve, reject) => {
49
- form.getLength((err, length) => {
50
- if (err) {
51
- reject(err);
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
- finally {
72
- this.timeEnd(`upload ${path}`);
73
- }
74
- });
55
+ });
56
+ }
57
+ finally {
58
+ this.timeEnd(`upload ${path}`);
59
+ }
75
60
  }
76
- download(path, ...args) {
77
- const _super = Object.create(null, {
78
- download: { get: () => super.download }
79
- });
80
- return __awaiter(this, void 0, void 0, function* () {
81
- try {
82
- this.timeBegin(`download ${path}`);
83
- const { data } = yield axios_1.default.get(this.options.url, {
84
- params: Object.assign({ filename: path }, this.options.body),
85
- responseType: 'arraybuffer'
86
- });
87
- yield _super.download.call(this, path, ...args);
88
- return data;
89
- }
90
- finally {
91
- this.timeEnd(`download ${path}`);
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
- return __awaiter(this, void 0, void 0, function* () {
97
- if (this.options.access) {
98
- return `${this.options.access}/dfs/get?filename=${path}`;
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 _a = this.config, { type } = _a, options = __rest(_a, ["type"]);
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 __awaiter(this, void 0, void 0, function* () {
54
- return this.dfs.startup();
55
- });
35
+ async startup() {
36
+ return this.dfs.startup();
56
37
  }
57
- upload(path, buffer, ...args) {
58
- return __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
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,47 @@ 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(Object.assign({ accessKey: '', secretKey: '' }, options), context);
31
+ super({ accessKey: '', secretKey: '', ...options }, context);
40
32
  this.client = new minio.Client(this.options);
41
33
  }
42
- startup() {
43
- const _super = Object.create(null, {
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
- const _super = Object.create(null, {
52
- upload: { get: () => super.upload }
53
- });
54
- return __awaiter(this, void 0, void 0, function* () {
55
- try {
56
- this.timeBegin(`upload ${path}`);
57
- yield this.client.putObject(this.options.bucketName, path, buffer, ...args);
58
- return _super.upload.call(this, path, buffer, ...args);
59
- }
60
- finally {
61
- this.timeEnd(`upload ${path}`);
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
+ if (this.logger.isDebugEnabled()) {
42
+ this.logger.debug(`upload ${path} storage ${this.options.bucketName}`);
62
43
  }
63
- });
44
+ return super.upload(path, buffer, ...args);
45
+ }
46
+ finally {
47
+ this.timeEnd(`upload ${path}`);
48
+ }
64
49
  }
65
- download(path, ...args) {
66
- const _super = Object.create(null, {
67
- download: { get: () => super.download }
68
- });
69
- return __awaiter(this, void 0, void 0, function* () {
70
- try {
71
- this.timeBegin(`download ${path}`);
72
- yield _super.download.call(this, path, ...args);
73
- let stream = yield this.client.getObject(this.options.bucketName, path);
74
- return yield this.stream2buffer(stream);
75
- }
76
- finally {
77
- this.timeEnd(`download ${path}`);
78
- }
79
- });
50
+ async download(path, ...args) {
51
+ try {
52
+ this.timeBegin(`download ${path}`);
53
+ await super.download(path, ...args);
54
+ let stream = await this.client.getObject(this.options.bucketName, path);
55
+ return await this.stream2buffer(stream);
56
+ }
57
+ finally {
58
+ this.timeEnd(`download ${path}`);
59
+ }
80
60
  }
81
- getAccess(path) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- if (this.options.access) {
84
- return `${this.options.access}/dfs/get?filename=${path}`;
85
- }
86
- return `http://${this.options.endPoint}:${this.options.port}/${this.options.bucketName}${path}`;
87
- });
61
+ async getAccess(path) {
62
+ if (this.options.access) {
63
+ return `${this.options.access}/dfs/get?filename=${path}`;
64
+ }
65
+ return `http://${this.options.endPoint}:${this.options.port}/${this.options.bucketName}${path}`;
88
66
  }
89
67
  }
90
68
  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,43 @@ 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(options, context);
35
+ super({
36
+ ...options,
37
+ storage: path_1.default.resolve(options.storage)
38
+ }, context);
45
39
  }
46
- startup() {
47
- const _super = Object.create(null, {
48
- startup: { get: () => super.startup }
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
- const _super = Object.create(null, {
57
- upload: { get: () => super.upload }
58
- });
59
- return __awaiter(this, void 0, void 0, function* () {
60
- try {
61
- this.timeBegin(`upload ${path}`);
62
- let file = `${this.options.storage}${path}`;
63
- let { dir } = path_1.default.parse(file);
64
- vweb_core_1.util.file.forceMkDirSync(dir);
65
- fs.writeFileSync(file, buffer);
66
- return _super.upload.call(this, path, buffer);
67
- }
68
- finally {
69
- this.timeEnd(`upload ${path}`);
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
+ if (this.logger.isDebugEnabled()) {
50
+ this.logger.debug(`upload ${path} storage ${file}`);
70
51
  }
71
- });
52
+ vweb_core_1.util.file.forceMkDirSync(dir);
53
+ fs.writeFileSync(file, buffer);
54
+ return super.upload(path, buffer);
55
+ }
56
+ finally {
57
+ this.timeEnd(`upload ${path}`);
58
+ }
72
59
  }
73
- download(path) {
74
- const _super = Object.create(null, {
75
- download: { get: () => super.download }
76
- });
77
- return __awaiter(this, void 0, void 0, function* () {
78
- try {
79
- this.timeBegin(`download ${path}`);
80
- yield _super.download.call(this, path);
81
- return fs.readFileSync(`${this.options.storage}${path}`);
82
- }
83
- finally {
84
- this.timeEnd(`download ${path}`);
85
- }
86
- });
60
+ async download(path) {
61
+ try {
62
+ this.timeBegin(`download ${path}`);
63
+ await super.download(path);
64
+ return fs.readFileSync(`${this.options.storage}${path}`);
65
+ }
66
+ finally {
67
+ this.timeEnd(`download ${path}`);
68
+ }
87
69
  }
88
- getAccess(path) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- return `${this.options.access}/dfs/get?filename=${path}`;
91
- });
70
+ async getAccess(path) {
71
+ return `${this.options.access}/dfs/get?filename=${path}`;
92
72
  }
93
73
  }
94
74
  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
- const _super = Object.create(null, {
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
- return __awaiter(this, void 0, void 0, function* () {
33
- try {
34
- this.timeBegin(`upload ${path}`);
35
- let result;
36
- if (buffer.constructor.name === 'Buffer') {
37
- result = yield this.client.put(path, buffer, ...args);
38
- }
39
- else if (typeof buffer === 'string') {
40
- if (fs_1.default.existsSync(buffer)) {
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 = yield this.client.putStream(path, buffer, ...args);
30
+ result = await this.client.put(path, Buffer.from(buffer), ...args);
49
31
  }
50
- return path;
51
32
  }
52
- finally {
53
- this.timeEnd(`upload ${path}`);
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
- return __awaiter(this, void 0, void 0, function* () {
59
- try {
60
- this.timeBegin(`download ${path}`);
61
- const result = yield this.client.getStream(path, ...args);
62
- return this.stream2buffer(result.stream);
63
- }
64
- finally {
65
- this.timeEnd(`download ${path}`);
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
- return __awaiter(this, void 0, void 0, function* () {
71
- if (this.options.access) {
72
- return `${this.options.access}/dfs/get?filename=${path}`;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dfs-adapter",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "oss minio dfs native",
5
5
  "main": "./lib/index",
6
6
  "files": [