gyomu 0.1.0
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/archive/abstract.d.ts +7 -0
- package/lib/archive/abstract.js +30 -0
- package/lib/archive/gz.d.ts +16 -0
- package/lib/archive/gz.js +66 -0
- package/lib/archive/index.d.ts +3 -0
- package/lib/archive/index.js +19 -0
- package/lib/archive/tar.d.ts +17 -0
- package/lib/archive/tar.js +165 -0
- package/lib/archive/zip.d.ts +28 -0
- package/lib/archive/zip.js +254 -0
- package/lib/base64.d.ts +6 -0
- package/lib/base64.js +24 -0
- package/lib/buffer.d.ts +4 -0
- package/lib/buffer.js +23 -0
- package/lib/configurator.d.ts +16 -0
- package/lib/configurator.js +53 -0
- package/lib/dateOperation.d.ts +3 -0
- package/lib/dateOperation.js +23 -0
- package/lib/dbsingleton.d.ts +11 -0
- package/lib/dbsingleton.js +13 -0
- package/lib/dbutil.d.ts +3 -0
- package/lib/dbutil.js +44 -0
- package/lib/dictionary.d.ts +8 -0
- package/lib/dictionary.js +55 -0
- package/lib/encryption.d.ts +17 -0
- package/lib/encryption.js +202 -0
- package/lib/errors.d.ts +31 -0
- package/lib/errors.js +64 -0
- package/lib/excel.d.ts +1 -0
- package/lib/excel.js +34 -0
- package/lib/fileModel.d.ts +96 -0
- package/lib/fileModel.js +170 -0
- package/lib/fileOperation.d.ts +11 -0
- package/lib/fileOperation.js +275 -0
- package/lib/holidays.d.ts +20 -0
- package/lib/holidays.js +200 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +31 -0
- package/lib/milestone.d.ts +19 -0
- package/lib/milestone.js +169 -0
- package/lib/net/_ftp.d.ts +0 -0
- package/lib/net/_ftp.js +228 -0
- package/lib/net/ftp.d.ts +19 -0
- package/lib/net/ftp.js +160 -0
- package/lib/net/remoteConnection.d.ts +11 -0
- package/lib/net/remoteConnection.js +26 -0
- package/lib/net/sftp.d.ts +19 -0
- package/lib/net/sftp.js +155 -0
- package/lib/numberOperation.d.ts +3 -0
- package/lib/numberOperation.js +24 -0
- package/lib/parameter.d.ts +14 -0
- package/lib/parameter.js +291 -0
- package/lib/result.d.ts +23 -0
- package/lib/result.js +47 -0
- package/lib/timer.d.ts +11 -0
- package/lib/timer.js +62 -0
- package/lib/user.d.ts +11 -0
- package/lib/user.js +23 -0
- package/lib/variable.d.ts +11 -0
- package/lib/variable.js +280 -0
- package/lib/web/attribute.d.ts +6 -0
- package/lib/web/attribute.js +29 -0
- package/lib/web/element.d.ts +24 -0
- package/lib/web/element.js +119 -0
- package/lib/web/index.d.ts +7 -0
- package/lib/web/index.js +19 -0
- package/lib/web/page.d.ts +22 -0
- package/lib/web/page.js +102 -0
- package/lib/web/table.d.ts +15 -0
- package/lib/web/table.js +110 -0
- package/lib/web/tableColumn.d.ts +10 -0
- package/lib/web/tableColumn.js +21 -0
- package/lib/web/tableRow.d.ts +10 -0
- package/lib/web/tableRow.js +80 -0
- package/lib/web/util.d.ts +12 -0
- package/lib/web/util.js +22 -0
- package/package.json +63 -0
package/lib/net/ftp.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ftp from 'basic-ftp';
|
|
2
|
+
import { NetworkError } from '../errors';
|
|
3
|
+
import { FileTransportInfo } from '../fileModel';
|
|
4
|
+
import { Failure, Result } from '../result';
|
|
5
|
+
import { RemoteConnection } from './remoteConnection';
|
|
6
|
+
export declare class Ftp {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(connectionConfig: RemoteConnection);
|
|
9
|
+
client: ftp.Client;
|
|
10
|
+
get connected(): boolean;
|
|
11
|
+
download(transportInformation: FileTransportInfo): Promise<import("../result").Success<boolean> | Failure<NetworkError>>;
|
|
12
|
+
upload(transportInformation: FileTransportInfo): Promise<import("../result").Success<boolean> | Failure<NetworkError>>;
|
|
13
|
+
getFileInfo(transportInformation: FileTransportInfo): Promise<Failure<NetworkError> | import("../result").Success<{
|
|
14
|
+
size: number;
|
|
15
|
+
date: Date;
|
|
16
|
+
}>>;
|
|
17
|
+
listFiles(transportInformation: FileTransportInfo): Promise<Failure<NetworkError> | import("../result").Success<string[]>>;
|
|
18
|
+
close(): Result<boolean, NetworkError>;
|
|
19
|
+
}
|
package/lib/net/ftp.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
var _Ftp_instances, _Ftp_connectionInformation, _Ftp_init;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.Ftp = void 0;
|
|
28
|
+
const basic_ftp_1 = __importDefault(require("basic-ftp"));
|
|
29
|
+
const errors_1 = require("../errors");
|
|
30
|
+
const result_1 = require("../result");
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
class Ftp {
|
|
33
|
+
constructor(connectionConfig) {
|
|
34
|
+
_Ftp_instances.add(this);
|
|
35
|
+
_Ftp_connectionInformation.set(this, void 0);
|
|
36
|
+
__classPrivateFieldSet(this, _Ftp_connectionInformation, connectionConfig, "f");
|
|
37
|
+
this.client = new basic_ftp_1.default.Client();
|
|
38
|
+
}
|
|
39
|
+
get connected() {
|
|
40
|
+
return !this.client.closed;
|
|
41
|
+
}
|
|
42
|
+
download(transportInformation) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
if (!this.connected) {
|
|
45
|
+
const result = yield __classPrivateFieldGet(this, _Ftp_instances, "m", _Ftp_init).call(this);
|
|
46
|
+
if (result.isFailure())
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
if (!transportInformation.isSourceDirectory)
|
|
51
|
+
yield this.client.downloadTo(transportInformation.destinationFullName, transportInformation.sourceFullName.replace(path_1.default.sep, '/'));
|
|
52
|
+
else
|
|
53
|
+
yield this.client.downloadToDir(transportInformation.destinationPath, transportInformation.sourceFolderName.replace(path_1.default.sep, '/'));
|
|
54
|
+
return (0, result_1.success)(true);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to do ftp download', err));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
upload(transportInformation) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
if (!this.connected) {
|
|
64
|
+
const result = yield __classPrivateFieldGet(this, _Ftp_instances, "m", _Ftp_init).call(this);
|
|
65
|
+
if (result.isFailure())
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
if (!transportInformation.isSourceDirectory)
|
|
70
|
+
yield this.client.uploadFrom(transportInformation.sourceFullName, transportInformation.destinationFullName.replace(path_1.default.sep, '/'));
|
|
71
|
+
else
|
|
72
|
+
yield this.client.uploadFromDir(transportInformation.sourceFullName, transportInformation.destinationFullName.replace(path_1.default.sep, '/'));
|
|
73
|
+
return (0, result_1.success)(true);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to do ftp upload', err));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
getFileInfo(transportInformation) {
|
|
81
|
+
var _a;
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (!this.connected) {
|
|
84
|
+
const result = yield __classPrivateFieldGet(this, _Ftp_instances, "m", _Ftp_init).call(this);
|
|
85
|
+
if (result.isFailure())
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
const fullPath = (_a = transportInformation.sourceFullName) !== null && _a !== void 0 ? _a : ''.replace(path_1.default.sep, '/');
|
|
89
|
+
try {
|
|
90
|
+
const size = yield this.client.size(fullPath);
|
|
91
|
+
const lastModifiedDate = yield this.client.lastMod(fullPath);
|
|
92
|
+
return (0, result_1.success)({ size: size, date: lastModifiedDate });
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to get ftp file information', err));
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
listFiles(transportInformation) {
|
|
100
|
+
var _a;
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
if (!this.connected) {
|
|
103
|
+
const result = yield __classPrivateFieldGet(this, _Ftp_instances, "m", _Ftp_init).call(this);
|
|
104
|
+
if (result.isFailure())
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
const fullPath = (_a = transportInformation.sourceFullName) !== null && _a !== void 0 ? _a : ''.replace(path_1.default.sep, '/');
|
|
108
|
+
try {
|
|
109
|
+
const fileInfoList = yield this.client.list(fullPath);
|
|
110
|
+
return (0, result_1.success)(fileInfoList.map((f) => f.name));
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to retrieve ftp folders', err));
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
close() {
|
|
118
|
+
if (!this.connected)
|
|
119
|
+
return (0, result_1.success)(true);
|
|
120
|
+
try {
|
|
121
|
+
this.client.close();
|
|
122
|
+
return (0, result_1.success)(true);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to close ftp connection', err));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.Ftp = Ftp;
|
|
130
|
+
_Ftp_connectionInformation = new WeakMap(), _Ftp_instances = new WeakSet(), _Ftp_init = function _Ftp_init() {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
this.client.ftp.verbose = true;
|
|
133
|
+
try {
|
|
134
|
+
const ftpResponse = yield this.client.access({
|
|
135
|
+
host: __classPrivateFieldGet(this, _Ftp_connectionInformation, "f").serverURL,
|
|
136
|
+
user: __classPrivateFieldGet(this, _Ftp_connectionInformation, "f").userId,
|
|
137
|
+
password: __classPrivateFieldGet(this, _Ftp_connectionInformation, "f").password,
|
|
138
|
+
port: __classPrivateFieldGet(this, _Ftp_connectionInformation, "f").port,
|
|
139
|
+
secure: __classPrivateFieldGet(this, _Ftp_connectionInformation, "f").sslEnabled
|
|
140
|
+
? __classPrivateFieldGet(this, _Ftp_connectionInformation, "f").sslImplicit
|
|
141
|
+
? 'implicit'
|
|
142
|
+
: true
|
|
143
|
+
: false,
|
|
144
|
+
secureOptions: !__classPrivateFieldGet(this, _Ftp_connectionInformation, "f").sslEnabled
|
|
145
|
+
? undefined
|
|
146
|
+
: {
|
|
147
|
+
host: __classPrivateFieldGet(this, _Ftp_connectionInformation, "f").serverURL,
|
|
148
|
+
port: __classPrivateFieldGet(this, _Ftp_connectionInformation, "f").port,
|
|
149
|
+
checkServerIdentity: (hostname, cert) => {
|
|
150
|
+
return undefined;
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
return (0, result_1.success)(true);
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to do ftp conneciton', err));
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class RemoteConnection {
|
|
2
|
+
serverURL: string;
|
|
3
|
+
port: number;
|
|
4
|
+
userId: string;
|
|
5
|
+
password?: string;
|
|
6
|
+
privateKeyFilename?: string;
|
|
7
|
+
isPassive?: boolean;
|
|
8
|
+
sslEnabled?: boolean;
|
|
9
|
+
sslImplicit?: boolean;
|
|
10
|
+
setSsl(isImplicit: boolean): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteConnection = void 0;
|
|
4
|
+
class RemoteConnection {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.serverURL = '';
|
|
7
|
+
this.port = 21;
|
|
8
|
+
this.userId = '';
|
|
9
|
+
}
|
|
10
|
+
// setProxy(
|
|
11
|
+
// proxyHost: string,
|
|
12
|
+
// proxyPort: number,
|
|
13
|
+
// proxyUser: string,
|
|
14
|
+
// proxyPassword: string
|
|
15
|
+
// ) {
|
|
16
|
+
// this.proxyHost = proxyHost;
|
|
17
|
+
// this.proxyPort = proxyPort;
|
|
18
|
+
// this.proxyUserID = proxyUser;
|
|
19
|
+
// this.proxyPassword = proxyPassword;
|
|
20
|
+
// }
|
|
21
|
+
setSsl(isImplicit) {
|
|
22
|
+
this.sslEnabled = true;
|
|
23
|
+
this.sslImplicit = isImplicit;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.RemoteConnection = RemoteConnection;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import sftp from 'ssh2-sftp-client';
|
|
2
|
+
import { RemoteConnection } from './remoteConnection';
|
|
3
|
+
import { Failure } from '../result';
|
|
4
|
+
import { NetworkError } from '../errors';
|
|
5
|
+
import { FileTransportInfo } from '../fileModel';
|
|
6
|
+
export declare class Sftp {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(connectionConfig: RemoteConnection);
|
|
9
|
+
client: sftp;
|
|
10
|
+
connected: boolean;
|
|
11
|
+
download(transportInformation: FileTransportInfo): Promise<import("../result").Success<boolean> | Failure<NetworkError>>;
|
|
12
|
+
upload(transportInformation: FileTransportInfo): Promise<import("../result").Success<boolean> | Failure<NetworkError>>;
|
|
13
|
+
getFileInfo(transportInformation: FileTransportInfo): Promise<Failure<NetworkError> | import("../result").Success<{
|
|
14
|
+
size: number;
|
|
15
|
+
date: Date;
|
|
16
|
+
}>>;
|
|
17
|
+
listFiles(transportInformation: FileTransportInfo): Promise<Failure<NetworkError> | import("../result").Success<string[]>>;
|
|
18
|
+
close(): Promise<import("../result").Success<boolean> | Failure<NetworkError>>;
|
|
19
|
+
}
|
package/lib/net/sftp.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
var _Sftp_instances, _Sftp_config, _Sftp_init;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.Sftp = void 0;
|
|
28
|
+
const ssh2_sftp_client_1 = __importDefault(require("ssh2-sftp-client"));
|
|
29
|
+
const fs_1 = __importDefault(require("fs"));
|
|
30
|
+
const result_1 = require("../result");
|
|
31
|
+
const errors_1 = require("../errors");
|
|
32
|
+
const path_1 = __importDefault(require("path"));
|
|
33
|
+
class Sftp {
|
|
34
|
+
constructor(connectionConfig) {
|
|
35
|
+
_Sftp_instances.add(this);
|
|
36
|
+
_Sftp_config.set(this, void 0);
|
|
37
|
+
__classPrivateFieldSet(this, _Sftp_config, connectionConfig, "f");
|
|
38
|
+
this.client = new ssh2_sftp_client_1.default();
|
|
39
|
+
this.connected = false;
|
|
40
|
+
}
|
|
41
|
+
download(transportInformation) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
if (!this.connected) {
|
|
44
|
+
const result = yield __classPrivateFieldGet(this, _Sftp_instances, "m", _Sftp_init).call(this);
|
|
45
|
+
if (result.isFailure())
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
if (!transportInformation.isSourceDirectory)
|
|
50
|
+
yield this.client.get(transportInformation.sourceFullName.replace(path_1.default.sep, '/'), transportInformation.destinationFullName);
|
|
51
|
+
else
|
|
52
|
+
yield this.client.downloadDir(transportInformation.sourceFolderName.replace(path_1.default.sep, '/'), transportInformation.destinationPath);
|
|
53
|
+
return (0, result_1.success)(true);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to do sftp download', err));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
upload(transportInformation) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
if (!this.connected) {
|
|
63
|
+
const result = yield __classPrivateFieldGet(this, _Sftp_instances, "m", _Sftp_init).call(this);
|
|
64
|
+
if (result.isFailure())
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
if (!transportInformation.isSourceDirectory)
|
|
69
|
+
yield this.client.put(transportInformation.sourceFullName, transportInformation.destinationFullName.replace(path_1.default.sep, '/'));
|
|
70
|
+
else
|
|
71
|
+
yield this.client.uploadDir(transportInformation.sourceFullName, transportInformation.destinationFullName.replace(path_1.default.sep, '/'));
|
|
72
|
+
return (0, result_1.success)(true);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to do sftp upload', err));
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getFileInfo(transportInformation) {
|
|
80
|
+
var _a;
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (!this.connected) {
|
|
83
|
+
const result = yield __classPrivateFieldGet(this, _Sftp_instances, "m", _Sftp_init).call(this);
|
|
84
|
+
if (result.isFailure())
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
const fullPath = (_a = transportInformation.sourceFullName) !== null && _a !== void 0 ? _a : ''.replace(path_1.default.sep, '/');
|
|
88
|
+
try {
|
|
89
|
+
const stat = yield this.client.stat(fullPath);
|
|
90
|
+
return (0, result_1.success)({ size: stat.size, date: new Date(stat.modifyTime) });
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to get sftp file information', err));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
listFiles(transportInformation) {
|
|
98
|
+
var _a;
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
if (!this.connected) {
|
|
101
|
+
const result = yield __classPrivateFieldGet(this, _Sftp_instances, "m", _Sftp_init).call(this);
|
|
102
|
+
if (result.isFailure())
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
const fullPath = (_a = transportInformation.sourceFullName) !== null && _a !== void 0 ? _a : ''.replace(path_1.default.sep, '/');
|
|
106
|
+
try {
|
|
107
|
+
const fileInfoList = yield this.client.list(fullPath);
|
|
108
|
+
return (0, result_1.success)(fileInfoList.map((f) => f.name));
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to retrieve sftp folders', err));
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
close() {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
if (!this.connected)
|
|
118
|
+
return (0, result_1.success)(true);
|
|
119
|
+
try {
|
|
120
|
+
yield this.client.end();
|
|
121
|
+
this.connected = false;
|
|
122
|
+
return (0, result_1.success)(true);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to close sftp connection', err));
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.Sftp = Sftp;
|
|
131
|
+
_Sftp_config = new WeakMap(), _Sftp_instances = new WeakSet(), _Sftp_init = function _Sftp_init() {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
try {
|
|
134
|
+
const ftpResponse = yield this.client.connect({
|
|
135
|
+
host: __classPrivateFieldGet(this, _Sftp_config, "f").serverURL,
|
|
136
|
+
username: __classPrivateFieldGet(this, _Sftp_config, "f").userId,
|
|
137
|
+
port: __classPrivateFieldGet(this, _Sftp_config, "f").port,
|
|
138
|
+
password: !!__classPrivateFieldGet(this, _Sftp_config, "f").privateKeyFilename
|
|
139
|
+
? undefined
|
|
140
|
+
: __classPrivateFieldGet(this, _Sftp_config, "f").password,
|
|
141
|
+
privateKey: !!__classPrivateFieldGet(this, _Sftp_config, "f").privateKeyFilename
|
|
142
|
+
? fs_1.default.readFileSync(__classPrivateFieldGet(this, _Sftp_config, "f").privateKeyFilename)
|
|
143
|
+
: undefined,
|
|
144
|
+
passphrase: !!__classPrivateFieldGet(this, _Sftp_config, "f").privateKeyFilename
|
|
145
|
+
? __classPrivateFieldGet(this, _Sftp_config, "f").password
|
|
146
|
+
: undefined,
|
|
147
|
+
});
|
|
148
|
+
this.connected = true;
|
|
149
|
+
return (0, result_1.success)(true);
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
return new result_1.Failure(new errors_1.NetworkError('Fail to do ftp conneciton', err));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRoundDown = exports.toRoundUp = exports.toHalfAdjust = void 0;
|
|
4
|
+
const toHalfAdjust = (targetNumber, digit) => {
|
|
5
|
+
if (digit === 0)
|
|
6
|
+
return Math.round(targetNumber);
|
|
7
|
+
const adjust = Math.pow(10, digit);
|
|
8
|
+
return Math.round(targetNumber * adjust) / adjust;
|
|
9
|
+
};
|
|
10
|
+
exports.toHalfAdjust = toHalfAdjust;
|
|
11
|
+
const toRoundUp = (targetNumber, digit) => {
|
|
12
|
+
if (digit === 0)
|
|
13
|
+
return Math.ceil(targetNumber);
|
|
14
|
+
const adjust = Math.pow(10, digit);
|
|
15
|
+
return Math.ceil(targetNumber * adjust) / adjust;
|
|
16
|
+
};
|
|
17
|
+
exports.toRoundUp = toRoundUp;
|
|
18
|
+
const toRoundDown = (targetNumber, digit) => {
|
|
19
|
+
if (digit === 0)
|
|
20
|
+
return Math.floor(targetNumber);
|
|
21
|
+
const adjust = Math.pow(10, digit);
|
|
22
|
+
return Math.floor(targetNumber * adjust) / adjust;
|
|
23
|
+
};
|
|
24
|
+
exports.toRoundDown = toRoundDown;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DBError } from './errors';
|
|
2
|
+
import { PromiseResult } from './result';
|
|
3
|
+
import { User } from './user';
|
|
4
|
+
declare type ParameterType = string | number | boolean;
|
|
5
|
+
export declare class ParameterAccess {
|
|
6
|
+
#private;
|
|
7
|
+
static keyExists(key: string): PromiseResult<boolean, DBError>;
|
|
8
|
+
static getKey(key: string, user?: User): string;
|
|
9
|
+
static value(key: string, user?: User, targetDate?: Date): PromiseResult<string, DBError>;
|
|
10
|
+
static booleanValue(key: string, user?: User, targetDate?: Date): PromiseResult<boolean, DBError>;
|
|
11
|
+
static numberValue(key: string, user?: User, targetDate?: Date): PromiseResult<number, DBError>;
|
|
12
|
+
static setValue<T extends ParameterType>(key: string, item: T, user?: User): PromiseResult<boolean, DBError>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|