cvitool 1.0.768 → 1.0.770
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 +1 -1
- package/build/src/cutil.js +8 -3
- package/package.json +1 -1
- package/src/cutil.ts +8 -3
package/build/src/cutil.d.ts
CHANGED
|
@@ -113,7 +113,7 @@ declare function getValueType(value: any): "string" | "number" | "boolean" | "un
|
|
|
113
113
|
*/
|
|
114
114
|
declare function getMediaFileType(target: string | Buffer | Readable): Promise<getMediaFileTypeRes>;
|
|
115
115
|
/**
|
|
116
|
-
* 检查url资源是否可访问(
|
|
116
|
+
* 检查url资源是否可访问(此方法执行get请求取文件流检查, 超时时(默认5s超时)会抛错而不是返回false)
|
|
117
117
|
* @param url
|
|
118
118
|
* @returns
|
|
119
119
|
*/
|
package/build/src/cutil.js
CHANGED
|
@@ -344,19 +344,24 @@ function getMediaFileType(target) {
|
|
|
344
344
|
});
|
|
345
345
|
}
|
|
346
346
|
/**
|
|
347
|
-
* 检查url资源是否可访问(
|
|
347
|
+
* 检查url资源是否可访问(此方法执行get请求取文件流检查, 超时时(默认5s超时)会抛错而不是返回false)
|
|
348
348
|
* @param url
|
|
349
349
|
* @returns
|
|
350
350
|
*/
|
|
351
351
|
function checkURLResource(url, timeout) {
|
|
352
352
|
return __awaiter(this, void 0, void 0, function* () {
|
|
353
|
-
|
|
353
|
+
let obj = {
|
|
354
354
|
isEffective: true
|
|
355
355
|
};
|
|
356
|
+
obj = { isEffective: true };
|
|
356
357
|
try {
|
|
357
|
-
yield hgo.get(url, {
|
|
358
|
+
const res = yield hgo.get(url, { resType: 'stream', timeout });
|
|
359
|
+
res.resBody.destroy();
|
|
358
360
|
}
|
|
359
361
|
catch (e) {
|
|
362
|
+
if (e.name === 'timeoutError') {
|
|
363
|
+
throw e;
|
|
364
|
+
}
|
|
360
365
|
obj.isEffective = false;
|
|
361
366
|
obj.message = e.message;
|
|
362
367
|
obj.resHeaders = e.resHeaders;
|
package/package.json
CHANGED
package/src/cutil.ts
CHANGED
|
@@ -365,17 +365,22 @@ async function getMediaFileType(target: string | Buffer | Readable): Promise<get
|
|
|
365
365
|
}
|
|
366
366
|
|
|
367
367
|
/**
|
|
368
|
-
* 检查url资源是否可访问(
|
|
368
|
+
* 检查url资源是否可访问(此方法执行get请求取文件流检查, 超时时(默认5s超时)会抛错而不是返回false)
|
|
369
369
|
* @param url
|
|
370
370
|
* @returns
|
|
371
371
|
*/
|
|
372
372
|
async function checkURLResource(url: string, timeout?: number) {
|
|
373
|
-
|
|
373
|
+
let obj: { isEffective: boolean, message?: string, resHeaders?: CustomObject, resBody?: CustomObject | string } = {
|
|
374
374
|
isEffective: true
|
|
375
375
|
};
|
|
376
|
+
obj = { isEffective: true };
|
|
376
377
|
try {
|
|
377
|
-
await hgo.get(url, {
|
|
378
|
+
const res = await hgo.get(url, { resType: 'stream', timeout });
|
|
379
|
+
(res.resBody as Readable).destroy();
|
|
378
380
|
} catch (e) {
|
|
381
|
+
if (e.name === 'timeoutError') {
|
|
382
|
+
throw e;
|
|
383
|
+
}
|
|
379
384
|
obj.isEffective = false;
|
|
380
385
|
obj.message = e.message;
|
|
381
386
|
obj.resHeaders = e.resHeaders;
|