dfs-adapter 1.0.1 → 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/README.md +1 -1
- package/lib/cos.d.ts +0 -1
- package/lib/declare.d.ts +9 -2
- package/lib/fastdfs.d.ts +0 -1
- package/lib/http.d.ts +0 -1
- package/lib/mdfs.d.ts +0 -1
- package/lib/minio.d.ts +0 -1
- package/lib/minio.js +17 -7
- package/lib/native.d.ts +0 -1
- package/lib/native.js +17 -7
- package/lib/obs.d.ts +0 -1
- package/lib/oss.d.ts +0 -1
- package/lib/sftp.d.ts +12 -0
- package/lib/sftp.js +71 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +43 -43
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
###
|
|
1
|
+
###
|
package/lib/cos.d.ts
CHANGED
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
package/lib/http.d.ts
CHANGED
package/lib/mdfs.d.ts
CHANGED
package/lib/minio.d.ts
CHANGED
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 (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
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 (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
package/lib/oss.d.ts
CHANGED
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,71 @@
|
|
|
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
|
+
let localPath = savePath;
|
|
39
|
+
if (!savePath.startsWith('/')) {
|
|
40
|
+
localPath = '/' + savePath;
|
|
41
|
+
}
|
|
42
|
+
return this.options.saveDir + localPath;
|
|
43
|
+
}
|
|
44
|
+
async upload(remotePath, buffer) {
|
|
45
|
+
return this.doSftp(async (client) => {
|
|
46
|
+
const savePath = this.getSavePath(remotePath);
|
|
47
|
+
const { dir } = path_1.default.parse(savePath);
|
|
48
|
+
if (!await client.exists(dir)) {
|
|
49
|
+
this.logger.info(`mkdir ${dir}`);
|
|
50
|
+
await client.mkdir(dir, true);
|
|
51
|
+
}
|
|
52
|
+
this.logger.info(`upload <<< ${savePath}`);
|
|
53
|
+
await client.put(buffer, savePath);
|
|
54
|
+
const link = await this.getAccess(remotePath);
|
|
55
|
+
this.logger.info(`upload ${remotePath} >>> ${link}`);
|
|
56
|
+
return link;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async download(remotePath) {
|
|
60
|
+
return this.doSftp(async (client) => {
|
|
61
|
+
this.logger.info(`download ${this.getSavePath(remotePath)}`);
|
|
62
|
+
const content = await client.get(this.getSavePath(remotePath));
|
|
63
|
+
return content;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async getAccess(path, ...args) {
|
|
67
|
+
const { access } = this.options;
|
|
68
|
+
return access ? access + path : path;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
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.9.3"}
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dfs-adapter",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "oss minio fastdfs native",
|
|
5
|
-
"main": "./lib/index",
|
|
6
|
-
"files": [
|
|
7
|
-
"lib/"
|
|
8
|
-
],
|
|
9
|
-
"scripts": {
|
|
10
|
-
"test": "node bin/app.js",
|
|
11
|
-
"build": "tsc --build tsconfig.json",
|
|
12
|
-
"run": "npm run build && node bin/app.js"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git@codeup.aliyun.com:60b0836844816b8ed2335ed6/vweb/modules/mq-adapter.git"
|
|
17
|
-
},
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@babel/cli": "^7.16.0",
|
|
20
|
-
"@babel/core": "^7.16.0",
|
|
21
|
-
"@babel/plugin-proposal-decorators": "^7.16.4",
|
|
22
|
-
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
23
|
-
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
24
|
-
"@babel/preset-env": "^7.16.4",
|
|
25
|
-
"@babel/register": "^7.16.0",
|
|
26
|
-
"@babel/runtime": "^7.16.3",
|
|
27
|
-
"@types/ali-oss": "^6.16.3",
|
|
28
|
-
"@types/node": "^16.11.12",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dfs-adapter",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "oss minio fastdfs native",
|
|
5
|
+
"main": "./lib/index",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib/"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "node bin/app.js",
|
|
11
|
+
"build": "tsc --build tsconfig.json",
|
|
12
|
+
"run": "npm run build && node bin/app.js"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git@codeup.aliyun.com:60b0836844816b8ed2335ed6/vweb/modules/mq-adapter.git"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@babel/cli": "^7.16.0",
|
|
20
|
+
"@babel/core": "^7.16.0",
|
|
21
|
+
"@babel/plugin-proposal-decorators": "^7.16.4",
|
|
22
|
+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
23
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
24
|
+
"@babel/preset-env": "^7.16.4",
|
|
25
|
+
"@babel/register": "^7.16.0",
|
|
26
|
+
"@babel/runtime": "^7.16.3",
|
|
27
|
+
"@types/ali-oss": "^6.16.3",
|
|
28
|
+
"@types/node": "^16.11.12",
|
|
29
|
+
"@types/ssh2-sftp-client": "^9.0.5",
|
|
30
|
+
"ali-oss": "^6.18.1",
|
|
31
|
+
"axios": "^1.6.1",
|
|
32
|
+
"babel-plugin-transform-decorators-legacy": "^1.3.5",
|
|
33
|
+
"cos-nodejs-sdk-v5": "^2.14.4",
|
|
34
|
+
"esdk-obs-nodejs": "^3.24.3",
|
|
35
|
+
"form-data": "^4.0.0",
|
|
36
|
+
"minio": "^8.0.0",
|
|
37
|
+
"ssh2-sftp-client": "^12.0.1",
|
|
38
|
+
"vweb-core": "^3.0.14",
|
|
39
|
+
"vweb-mvc": "^1.2.18"
|
|
40
|
+
},
|
|
41
|
+
"author": "",
|
|
42
|
+
"license": "ISC"
|
|
43
|
+
}
|