cvitool 1.0.749 → 1.0.750
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/build/src/cutil.d.ts +2 -5
- package/build/src/cutil.js +19 -20
- package/build/src/hgo.d.ts +0 -5
- package/build/src/hgo.js +9 -10
- package/build/src/streamhelper.d.ts +0 -2
- package/build/src/streamhelper.js +2 -3
- package/package.json +1 -1
- package/src/cutil.ts +6 -6
package/build/src/cutil.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
1
|
import { Encoding } from 'crypto';
|
|
5
2
|
import { ReadStream } from 'fs';
|
|
6
3
|
interface randomStringOptions {
|
|
@@ -75,11 +72,11 @@ declare function getValueType(value: any): "string" | "number" | "boolean" | "un
|
|
|
75
72
|
*/
|
|
76
73
|
declare function getMediaFileType(target: string | Buffer | ReadStream): Promise<getMediaFileTypeRes>;
|
|
77
74
|
/**
|
|
78
|
-
* 检查url资源是否可访问(此方法取文件首字节进行检查, 超时时(5s超时)
|
|
75
|
+
* 检查url资源是否可访问(此方法取文件首字节进行检查, 超时时(默认5s超时)返回false)
|
|
79
76
|
* @param url
|
|
80
77
|
* @returns
|
|
81
78
|
*/
|
|
82
|
-
declare function checkURLResource(url: string): Promise<boolean>;
|
|
79
|
+
declare function checkURLResource(url: string, timeout?: number): Promise<boolean>;
|
|
83
80
|
/**
|
|
84
81
|
* 写入json文件
|
|
85
82
|
* @param data 待写入json对象
|
package/build/src/cutil.js
CHANGED
|
@@ -9,7 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.randomString = randomString;
|
|
13
|
+
exports.encryptCBC = encryptCBC;
|
|
14
|
+
exports.decryptCBC = decryptCBC;
|
|
15
|
+
exports.md5 = md5;
|
|
16
|
+
exports.execCmdCommand = execCmdCommand;
|
|
17
|
+
exports.getValueType = getValueType;
|
|
18
|
+
exports.getMediaFileType = getMediaFileType;
|
|
19
|
+
exports.checkURLResource = checkURLResource;
|
|
20
|
+
exports.writeJsonFileSync = writeJsonFileSync;
|
|
21
|
+
exports.readJsonFileSync = readJsonFileSync;
|
|
22
|
+
exports.uuid = uuid;
|
|
13
23
|
const crypto_1 = require("crypto");
|
|
14
24
|
const child_process_1 = require("child_process");
|
|
15
25
|
const fs_1 = require("fs");
|
|
@@ -56,7 +66,6 @@ function randomString(length, options) {
|
|
|
56
66
|
}
|
|
57
67
|
return result;
|
|
58
68
|
}
|
|
59
|
-
exports.randomString = randomString;
|
|
60
69
|
/**
|
|
61
70
|
* 以CBC算法进行对称加密
|
|
62
71
|
* @param data 待加密数据
|
|
@@ -73,7 +82,6 @@ function encryptCBC(data, length, key, iv, inputEncoding = 'utf-8') {
|
|
|
73
82
|
crypted += cipher.final('hex');
|
|
74
83
|
return crypted;
|
|
75
84
|
}
|
|
76
|
-
exports.encryptCBC = encryptCBC;
|
|
77
85
|
;
|
|
78
86
|
/**
|
|
79
87
|
* 以CBC算法进行对称解密
|
|
@@ -91,7 +99,6 @@ function decryptCBC(encryptData, length, key, iv, outputEncoding = 'utf-8') {
|
|
|
91
99
|
decrypted += decipher.final(outputEncoding);
|
|
92
100
|
return decrypted;
|
|
93
101
|
}
|
|
94
|
-
exports.decryptCBC = decryptCBC;
|
|
95
102
|
;
|
|
96
103
|
/**
|
|
97
104
|
* md5加密
|
|
@@ -102,15 +109,14 @@ exports.decryptCBC = decryptCBC;
|
|
|
102
109
|
function md5(data, inputEncoding = 'utf-8') {
|
|
103
110
|
return (0, crypto_1.createHash)('md5').update(data, inputEncoding).digest('hex');
|
|
104
111
|
}
|
|
105
|
-
exports.md5 = md5;
|
|
106
112
|
/**
|
|
107
113
|
* 调用终端执行命令
|
|
108
114
|
* @param command 命令
|
|
109
115
|
* @param timeout 执行超时时间,单位: ms, 默认: 60000
|
|
110
116
|
* @returns
|
|
111
117
|
*/
|
|
112
|
-
function execCmdCommand(
|
|
113
|
-
return __awaiter(this,
|
|
118
|
+
function execCmdCommand(command_1) {
|
|
119
|
+
return __awaiter(this, arguments, void 0, function* (command, timeout = 1 * 60 * 1000) {
|
|
114
120
|
const commandList = command.split(' ');
|
|
115
121
|
const commandName = commandList.splice(0, 1);
|
|
116
122
|
return new Promise((resolve, reject) => {
|
|
@@ -142,7 +148,6 @@ function execCmdCommand(command, timeout = 1 * 60 * 1000) {
|
|
|
142
148
|
});
|
|
143
149
|
});
|
|
144
150
|
}
|
|
145
|
-
exports.execCmdCommand = execCmdCommand;
|
|
146
151
|
/**
|
|
147
152
|
* 获取给定值node类型
|
|
148
153
|
* @param value
|
|
@@ -180,7 +185,6 @@ function getValueType(value) {
|
|
|
180
185
|
;
|
|
181
186
|
return type;
|
|
182
187
|
}
|
|
183
|
-
exports.getValueType = getValueType;
|
|
184
188
|
/**
|
|
185
189
|
* 获取媒体文件类型(此方法取文件前30个字节进行检查)
|
|
186
190
|
* @param target
|
|
@@ -301,28 +305,26 @@ function getMediaFileType(target) {
|
|
|
301
305
|
return getResult('unknow|unknow');
|
|
302
306
|
});
|
|
303
307
|
}
|
|
304
|
-
exports.getMediaFileType = getMediaFileType;
|
|
305
308
|
/**
|
|
306
|
-
* 检查url资源是否可访问(此方法取文件首字节进行检查, 超时时(5s超时)
|
|
309
|
+
* 检查url资源是否可访问(此方法取文件首字节进行检查, 超时时(默认5s超时)返回false)
|
|
307
310
|
* @param url
|
|
308
311
|
* @returns
|
|
309
312
|
*/
|
|
310
|
-
function checkURLResource(url) {
|
|
313
|
+
function checkURLResource(url, timeout) {
|
|
311
314
|
return __awaiter(this, void 0, void 0, function* () {
|
|
312
315
|
let isEffective = true;
|
|
313
316
|
try {
|
|
314
|
-
yield hgo.get(url, { headers: { Range: 'bytes=0-0' }, resType: 'buffer' });
|
|
317
|
+
yield hgo.get(url, { headers: { Range: 'bytes=0-0' }, resType: 'buffer', timeout });
|
|
315
318
|
}
|
|
316
319
|
catch (e) {
|
|
317
|
-
if (e.name === 'timeoutError') {
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
+
// if (e.name === 'timeoutError') {
|
|
321
|
+
// throw e;
|
|
322
|
+
// }
|
|
320
323
|
isEffective = false;
|
|
321
324
|
}
|
|
322
325
|
return isEffective;
|
|
323
326
|
});
|
|
324
327
|
}
|
|
325
|
-
exports.checkURLResource = checkURLResource;
|
|
326
328
|
/**
|
|
327
329
|
* 写入json文件
|
|
328
330
|
* @param data 待写入json对象
|
|
@@ -339,7 +341,6 @@ function writeJsonFileSync(data, path, space = 3) {
|
|
|
339
341
|
}
|
|
340
342
|
(0, fs_1.writeFileSync)(path, writeStr);
|
|
341
343
|
}
|
|
342
|
-
exports.writeJsonFileSync = writeJsonFileSync;
|
|
343
344
|
/**
|
|
344
345
|
* 读取json文件
|
|
345
346
|
* @param path 读取文件路径
|
|
@@ -353,7 +354,6 @@ function readJsonFileSync(path, toObj = true) {
|
|
|
353
354
|
}
|
|
354
355
|
return str;
|
|
355
356
|
}
|
|
356
|
-
exports.readJsonFileSync = readJsonFileSync;
|
|
357
357
|
/**
|
|
358
358
|
* 生成去掉'-'形式的uuid
|
|
359
359
|
* @returns
|
|
@@ -361,4 +361,3 @@ exports.readJsonFileSync = readJsonFileSync;
|
|
|
361
361
|
function uuid() {
|
|
362
362
|
return (0, crypto_1.randomUUID)().replace(/-/g, '');
|
|
363
363
|
}
|
|
364
|
-
exports.uuid = uuid;
|
package/build/src/hgo.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
/// <reference types="node" />
|
|
5
|
-
/// <reference types="node" />
|
|
6
1
|
import * as querystring from 'querystring';
|
|
7
2
|
import * as https from 'https';
|
|
8
3
|
import * as http from 'http';
|
package/build/src/hgo.js
CHANGED
|
@@ -9,7 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.request = request;
|
|
13
|
+
exports.reqSendBuffer = reqSendBuffer;
|
|
14
|
+
exports.reqSendStream = reqSendStream;
|
|
15
|
+
exports.reqSendMultiPart = reqSendMultiPart;
|
|
16
|
+
exports.get = get;
|
|
17
|
+
exports.post = post;
|
|
18
|
+
exports.put = put;
|
|
19
|
+
exports.head = head;
|
|
20
|
+
exports.del = del;
|
|
13
21
|
const querystring = require("querystring");
|
|
14
22
|
const https = require("https");
|
|
15
23
|
const http = require("http");
|
|
@@ -98,7 +106,6 @@ function request(url, options) {
|
|
|
98
106
|
return res;
|
|
99
107
|
});
|
|
100
108
|
}
|
|
101
|
-
exports.request = request;
|
|
102
109
|
/**
|
|
103
110
|
* 传送buffer请求
|
|
104
111
|
* @param url
|
|
@@ -156,7 +163,6 @@ function reqSendBuffer(url, options) {
|
|
|
156
163
|
return res;
|
|
157
164
|
});
|
|
158
165
|
}
|
|
159
|
-
exports.reqSendBuffer = reqSendBuffer;
|
|
160
166
|
/**
|
|
161
167
|
* 传送stream请求
|
|
162
168
|
* @param url
|
|
@@ -209,7 +215,6 @@ function reqSendStream(url, options) {
|
|
|
209
215
|
return res;
|
|
210
216
|
});
|
|
211
217
|
}
|
|
212
|
-
exports.reqSendStream = reqSendStream;
|
|
213
218
|
/**
|
|
214
219
|
* 传送表单formData请求
|
|
215
220
|
* @param url
|
|
@@ -251,7 +256,6 @@ function reqSendMultiPart(url, options) {
|
|
|
251
256
|
return res;
|
|
252
257
|
});
|
|
253
258
|
}
|
|
254
|
-
exports.reqSendMultiPart = reqSendMultiPart;
|
|
255
259
|
function resHandld(res, resolve, reject, resType, method, readTimeOut, req, reqUrl) {
|
|
256
260
|
const resHeaders = {};
|
|
257
261
|
for (let i = 0; i < res.rawHeaders.length; i += 2) {
|
|
@@ -377,7 +381,6 @@ function get(url, options) {
|
|
|
377
381
|
return request(url, Object.assign(Object.assign({}, options), { method: 'get' }));
|
|
378
382
|
});
|
|
379
383
|
}
|
|
380
|
-
exports.get = get;
|
|
381
384
|
/**
|
|
382
385
|
* request-post
|
|
383
386
|
* @param url
|
|
@@ -389,7 +392,6 @@ function post(url, options) {
|
|
|
389
392
|
return request(url, Object.assign(Object.assign({}, options), { method: 'post' }));
|
|
390
393
|
});
|
|
391
394
|
}
|
|
392
|
-
exports.post = post;
|
|
393
395
|
/**
|
|
394
396
|
* request-put
|
|
395
397
|
* @param url
|
|
@@ -401,7 +403,6 @@ function put(url, options) {
|
|
|
401
403
|
return request(url, Object.assign(Object.assign({}, options), { method: 'put' }));
|
|
402
404
|
});
|
|
403
405
|
}
|
|
404
|
-
exports.put = put;
|
|
405
406
|
/**
|
|
406
407
|
* request-head
|
|
407
408
|
* @param url
|
|
@@ -413,7 +414,6 @@ function head(url, options) {
|
|
|
413
414
|
return request(url, Object.assign(Object.assign({}, options), { method: 'head' }));
|
|
414
415
|
});
|
|
415
416
|
}
|
|
416
|
-
exports.head = head;
|
|
417
417
|
/**
|
|
418
418
|
* request-delete
|
|
419
419
|
* @param url
|
|
@@ -425,7 +425,6 @@ function del(url, options) {
|
|
|
425
425
|
return request(url, Object.assign(Object.assign({}, options), { method: 'delete' }));
|
|
426
426
|
});
|
|
427
427
|
}
|
|
428
|
-
exports.del = del;
|
|
429
428
|
function getReqProtocolAndOpt(url, baseHeaders, headers, timeout, method, agent, useEnvProxy, proxyHost) {
|
|
430
429
|
let reqProtocol = getProtocol(url);
|
|
431
430
|
const urlOpt = new URL(url);
|
|
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.pipe = pipe;
|
|
13
|
+
exports.limitStreamFlowingRate = limitStreamFlowingRate;
|
|
13
14
|
/**
|
|
14
15
|
* 实现一个promise流传输
|
|
15
16
|
* @param source 原流
|
|
@@ -46,7 +47,6 @@ function pipe(source, target, options) {
|
|
|
46
47
|
});
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
|
-
exports.pipe = pipe;
|
|
50
50
|
/**
|
|
51
51
|
* stream传输限流
|
|
52
52
|
* @param stream 可读流
|
|
@@ -85,4 +85,3 @@ function limitStreamFlowingRate(stream, readBytesPreSec) {
|
|
|
85
85
|
clearInterval(checkInterval);
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
exports.limitStreamFlowingRate = limitStreamFlowingRate;
|
package/package.json
CHANGED
package/src/cutil.ts
CHANGED
|
@@ -311,18 +311,18 @@ async function getMediaFileType(target: string | Buffer | ReadStream): Promise<g
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
/**
|
|
314
|
-
* 检查url资源是否可访问(此方法取文件首字节进行检查, 超时时(5s超时)
|
|
314
|
+
* 检查url资源是否可访问(此方法取文件首字节进行检查, 超时时(默认5s超时)返回false)
|
|
315
315
|
* @param url
|
|
316
316
|
* @returns
|
|
317
317
|
*/
|
|
318
|
-
async function checkURLResource(url: string) {
|
|
318
|
+
async function checkURLResource(url: string, timeout?: number) {
|
|
319
319
|
let isEffective = true;
|
|
320
320
|
try {
|
|
321
|
-
await hgo.get(url, { headers: { Range: 'bytes=0-0' }, resType: 'buffer' });
|
|
321
|
+
await hgo.get(url, { headers: { Range: 'bytes=0-0' }, resType: 'buffer', timeout });
|
|
322
322
|
} catch (e) {
|
|
323
|
-
if (e.name === 'timeoutError') {
|
|
324
|
-
|
|
325
|
-
}
|
|
323
|
+
// if (e.name === 'timeoutError') {
|
|
324
|
+
// throw e;
|
|
325
|
+
// }
|
|
326
326
|
isEffective = false;
|
|
327
327
|
}
|
|
328
328
|
return isEffective;
|