html-get 2.27.24 → 2.28.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/README.md +9 -0
- package/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/index.js +23 -3
package/README.md
CHANGED
|
@@ -81,6 +81,15 @@ The target URL for getting the HTML markup.
|
|
|
81
81
|
|
|
82
82
|
#### options
|
|
83
83
|
|
|
84
|
+
##### documentTimeout
|
|
85
|
+
|
|
86
|
+
Type: `number`<br>
|
|
87
|
+
Default: the fetch timeout (`gotOpts.timeout`)
|
|
88
|
+
|
|
89
|
+
The time, in milliseconds from the start of the fetch, that a PDF or office document may take once its response says it is one. It covers mutool or pandoc, and the page by page image search. It only lengthens the fetch timeout, never shortens it. A non-finite document timeout leaves the deadline unchanged, as does a fetch timeout that is not a number. The download itself stays within the fetch timeout.
|
|
90
|
+
|
|
91
|
+
A caller that keeps the fetch short to retry a blocked page elsewhere can still let a document convert: a 151MB scanned PDF of 688 pages downloads in 2.7s and takes mutool 6.3s, more than a 9.5s fetch timeout leaves.
|
|
92
|
+
|
|
84
93
|
##### encoding
|
|
85
94
|
|
|
86
95
|
Type: `string`
|
package/index.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ declare namespace htmlGet {
|
|
|
50
50
|
* Options for html-get
|
|
51
51
|
*/
|
|
52
52
|
interface HtmlGetOptions {
|
|
53
|
+
/** Finite milliseconds from the start of the fetch a PDF or office document may take, when longer than the fetch timeout */
|
|
54
|
+
documentTimeout?: number
|
|
53
55
|
/** Character encoding for HTML (default: 'utf-8') */
|
|
54
56
|
encoding?: string
|
|
55
57
|
/** Function that returns a browserless instance (required unless prerender is false) */
|
|
@@ -81,6 +83,7 @@ declare namespace htmlGet {
|
|
|
81
83
|
interface GetContentOptions
|
|
82
84
|
extends Pick<
|
|
83
85
|
HtmlGetOptions,
|
|
86
|
+
| 'documentTimeout'
|
|
84
87
|
| 'getBrowserless'
|
|
85
88
|
| 'getTemporalFile'
|
|
86
89
|
| 'gotOpts'
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "html-get",
|
|
3
3
|
"description": "Get the HTML from any website, fine-tuned for correction & speed",
|
|
4
4
|
"homepage": "https://nicedoc.com/microlinkhq/html-get",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.28.0",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"bin": {
|
package/src/index.js
CHANGED
|
@@ -46,7 +46,16 @@ const inheritRequestFragment = (options, response) => {
|
|
|
46
46
|
const fetch = PCancelable.fn(
|
|
47
47
|
async (
|
|
48
48
|
url,
|
|
49
|
-
{
|
|
49
|
+
{
|
|
50
|
+
documentTimeout,
|
|
51
|
+
getTemporalFile,
|
|
52
|
+
mutool,
|
|
53
|
+
pandoc,
|
|
54
|
+
reflect = false,
|
|
55
|
+
timeout = REQ_TIMEOUT,
|
|
56
|
+
toEncode,
|
|
57
|
+
...opts
|
|
58
|
+
},
|
|
50
59
|
onCancel
|
|
51
60
|
) => {
|
|
52
61
|
const temporalFiles = []
|
|
@@ -56,7 +65,13 @@ const fetch = PCancelable.fn(
|
|
|
56
65
|
return file
|
|
57
66
|
}
|
|
58
67
|
const reqTimeout = reflect ? timeout / 2 : timeout
|
|
59
|
-
const
|
|
68
|
+
const startedAt = Date.now()
|
|
69
|
+
let deadline = startedAt + reqTimeout
|
|
70
|
+
const allowDocumentTime = () => {
|
|
71
|
+
if (Number.isFinite(documentTimeout) && documentTimeout > reqTimeout) {
|
|
72
|
+
deadline = startedAt + documentTimeout
|
|
73
|
+
}
|
|
74
|
+
}
|
|
60
75
|
const conversion = new AbortController()
|
|
61
76
|
const convertOpts = () => ({
|
|
62
77
|
signal: conversion.signal,
|
|
@@ -99,6 +114,7 @@ const fetch = PCancelable.fn(
|
|
|
99
114
|
// a recognized office file never goes through mutool, even if the
|
|
100
115
|
// response is mislabeled as application/pdf
|
|
101
116
|
if (!convertOffice && contentType === 'application/pdf') {
|
|
117
|
+
allowDocumentTime()
|
|
102
118
|
pdfMeta = await extractSafe(res.body, res.url)
|
|
103
119
|
if (!mutool) return ''
|
|
104
120
|
const file = temporalFile(url, 'pdf')
|
|
@@ -134,6 +150,7 @@ const fetch = PCancelable.fn(
|
|
|
134
150
|
}
|
|
135
151
|
|
|
136
152
|
if (convertOffice) {
|
|
153
|
+
allowDocumentTime()
|
|
137
154
|
const file = temporalFile(res.url, officeFormat)
|
|
138
155
|
await writeFile(file.path, res.body)
|
|
139
156
|
try {
|
|
@@ -405,6 +422,7 @@ const getContent = PCancelable.fn(
|
|
|
405
422
|
url,
|
|
406
423
|
mode,
|
|
407
424
|
{
|
|
425
|
+
documentTimeout,
|
|
408
426
|
getBrowserless,
|
|
409
427
|
getTemporalFile,
|
|
410
428
|
gotOpts,
|
|
@@ -421,7 +439,7 @@ const getContent = PCancelable.fn(
|
|
|
421
439
|
const isFetchMode = mode === 'fetch'
|
|
422
440
|
|
|
423
441
|
const fetchOpts = isFetchMode
|
|
424
|
-
? { headers, toEncode, mutool, pandoc, getTemporalFile, ...gotOpts }
|
|
442
|
+
? { headers, toEncode, mutool, pandoc, getTemporalFile, ...gotOpts, documentTimeout }
|
|
425
443
|
: { headers, toEncode, getBrowserless, gotOpts, ...puppeteerOpts }
|
|
426
444
|
|
|
427
445
|
const promise = modes[mode](url, fetchOpts)
|
|
@@ -446,6 +464,7 @@ module.exports = PCancelable.fn(
|
|
|
446
464
|
async (
|
|
447
465
|
targetUrl,
|
|
448
466
|
{
|
|
467
|
+
documentTimeout,
|
|
449
468
|
encoding = 'utf-8',
|
|
450
469
|
getBrowserless,
|
|
451
470
|
getMode = defaultGetMode,
|
|
@@ -474,6 +493,7 @@ module.exports = PCancelable.fn(
|
|
|
474
493
|
const duration = timeSpan()
|
|
475
494
|
|
|
476
495
|
const promise = getContent(targetUrl, reqMode, {
|
|
496
|
+
documentTimeout,
|
|
477
497
|
getBrowserless,
|
|
478
498
|
getTemporalFile,
|
|
479
499
|
gotOpts,
|