dfs-adapter 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -1 +1 @@
1
- ###
1
+ ###
package/lib/cos.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Dfs, CosConfig } from "./declare";
3
2
  import { VWebApplicationContext } from "vweb-core";
4
3
  export default class CosDfs extends Dfs<'cos'> {
package/lib/declare.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { VWebApplicationContext } from "vweb-core";
4
2
  export declare interface OssConfig {
5
3
  accessKeyId: string;
@@ -59,6 +57,14 @@ export declare interface CosConfig {
59
57
  bucket: string;
60
58
  access?: string;
61
59
  }
60
+ export declare interface SftpConfig {
61
+ host: string;
62
+ port?: number;
63
+ username: string;
64
+ password: string;
65
+ saveDir?: string;
66
+ access: string;
67
+ }
62
68
  export declare type ConfigOptionsMap = {
63
69
  oss: OssConfig;
64
70
  minio: MinioConfig;
@@ -67,6 +73,7 @@ export declare type ConfigOptionsMap = {
67
73
  fastdfs: FastdfsConfig;
68
74
  obs: ObsConfig;
69
75
  cos: CosConfig;
76
+ sftp: SftpConfig;
70
77
  };
71
78
  export declare type ConfigOptionsKey = keyof ConfigOptionsMap;
72
79
  type ConfigOptionsOptions<T> = T extends ConfigOptionsKey ? {
package/lib/fastdfs.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Dfs, FastdfsConfig } from "./declare";
3
2
  import { VWebApplicationContext } from "vweb-core";
4
3
  export default class HttpDfs extends Dfs<'fastdfs'> {
package/lib/http.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Dfs, HttpConfig } from "./declare";
3
2
  import { VWebApplicationContext } from "vweb-core";
4
3
  export default class HttpDfs extends Dfs<'http'> {
package/lib/mdfs.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { VWebApplicationContext } from "vweb-core";
3
2
  import { ConfigOptionsKey, Dfs, DfsConfig } from "./declare";
4
3
  export default class Mdfs extends Dfs<ConfigOptionsKey> {
package/lib/minio.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Dfs, MinioConfig } from "./declare";
3
2
  import { VWebApplicationContext } from "vweb-core";
4
3
  export default class MinioDfs extends Dfs<'minio'> {
package/lib/minio.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  const declare_1 = require("./declare");
27
37
  const minio = __importStar(require("minio"));
package/lib/native.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Dfs, NativeConfig } from "./declare";
3
2
  import { VWebApplicationContext } from "vweb-core";
4
3
  export default class NativeDfs extends Dfs<'native'> {
package/lib/native.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
package/lib/obs.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Dfs, ObsConfig } from "./declare";
3
2
  import { VWebApplicationContext } from "vweb-core";
4
3
  export default class ObsDfs extends Dfs<'obs'> {
package/lib/oss.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Dfs, OssConfig } from "./declare";
3
2
  import { VWebApplicationContext } from "vweb-core";
4
3
  export default class OssDfs extends Dfs<'oss'> {
package/lib/sftp.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { Dfs, SftpConfig } from "./declare";
2
+ import { VWebApplicationContext } from "vweb-core";
3
+ export default class SftpDfs extends Dfs<'sftp'> {
4
+ constructor(options: SftpConfig & {
5
+ type: 'sftp';
6
+ }, context: VWebApplicationContext);
7
+ private doSftp;
8
+ private getSavePath;
9
+ upload(remotePath: string, buffer: any): Promise<string>;
10
+ download(remotePath: string): Promise<Buffer>;
11
+ getAccess(path: string, ...args: any[]): Promise<string>;
12
+ }
package/lib/sftp.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const declare_1 = require("./declare");
7
+ const ssh2_sftp_client_1 = __importDefault(require("ssh2-sftp-client"));
8
+ const path_1 = __importDefault(require("path"));
9
+ class SftpDfs extends declare_1.Dfs {
10
+ constructor(options, context) {
11
+ super(options, context);
12
+ this.options.saveDir = this.options.saveDir || '/tmp';
13
+ if (this.options.saveDir.endsWith('/')) {
14
+ this.options.saveDir = this.options.saveDir.substring(0, this.options.saveDir.length - 1);
15
+ }
16
+ }
17
+ async doSftp(apply) {
18
+ const { host, port = 22, username, password } = this.options;
19
+ const client = new ssh2_sftp_client_1.default();
20
+ try {
21
+ this.timeBegin(`sftp execute`);
22
+ this.logger.info(`sftp connect ${host}:${port}`);
23
+ await client.connect({ host, port, username, password });
24
+ this.logger.info(`sftp connected do execute`);
25
+ const returnValue = await apply(client);
26
+ this.logger.info(`sftp execute done ${returnValue}`);
27
+ return returnValue;
28
+ }
29
+ catch (e) {
30
+ this.logger.error(e.messasge, e);
31
+ }
32
+ finally {
33
+ await client.end();
34
+ this.timeEnd(`sftp execute`);
35
+ }
36
+ }
37
+ getSavePath(savePath) {
38
+ if (!savePath.startsWith('/')) {
39
+ throw new Error('savePath must start with /');
40
+ }
41
+ return this.options.saveDir + savePath;
42
+ }
43
+ async upload(remotePath, buffer) {
44
+ return this.doSftp(async (client) => {
45
+ const savePath = this.getSavePath(remotePath);
46
+ const { dir } = path_1.default.parse(savePath);
47
+ if (!await client.exists(dir)) {
48
+ this.logger.info(`mkdir ${dir}`);
49
+ await client.mkdir(dir, true);
50
+ }
51
+ this.logger.info(`upload <<< ${savePath}`);
52
+ await client.put(buffer, savePath);
53
+ const link = await this.getAccess(remotePath);
54
+ this.logger.info(`upload ${remotePath} >>> ${link}`);
55
+ return link;
56
+ });
57
+ }
58
+ async download(remotePath) {
59
+ return this.doSftp(async (client) => {
60
+ this.logger.info(`download ${this.getSavePath(remotePath)}`);
61
+ const content = await client.get(this.getSavePath(remotePath));
62
+ return content;
63
+ });
64
+ }
65
+ async getAccess(path, ...args) {
66
+ const { access } = this.options;
67
+ return access ? access + path : path;
68
+ }
69
+ }
70
+ exports.default = SftpDfs;
@@ -0,0 +1 @@
1
+ {"root":["../src/cos.ts","../src/declare.ts","../src/fastdfs.ts","../src/http.ts","../src/index.ts","../src/mdfs.ts","../src/minio.ts","../src/native.ts","../src/obs.ts","../src/oss.ts","../src/sftp.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dfs-adapter",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "oss minio fastdfs native",
5
5
  "main": "./lib/index",
6
6
  "files": [
@@ -26,18 +26,18 @@
26
26
  "@babel/runtime": "^7.16.3",
27
27
  "@types/ali-oss": "^6.16.3",
28
28
  "@types/node": "^16.11.12",
29
+ "@types/ssh2-sftp-client": "^9.0.5",
29
30
  "ali-oss": "^6.18.1",
30
31
  "axios": "^1.6.1",
31
32
  "babel-plugin-transform-decorators-legacy": "^1.3.5",
33
+ "cos-nodejs-sdk-v5": "^2.14.4",
32
34
  "esdk-obs-nodejs": "^3.24.3",
33
35
  "form-data": "^4.0.0",
34
36
  "minio": "^8.0.0",
37
+ "ssh2-sftp-client": "^12.0.1",
35
38
  "vweb-core": "^3.0.14",
36
39
  "vweb-mvc": "^1.2.18"
37
40
  },
38
41
  "author": "",
39
- "license": "ISC",
40
- "dependencies": {
41
- "cos-nodejs-sdk-v5": "^2.14.4"
42
- }
42
+ "license": "ISC"
43
43
  }