@vaadin-component-factory/vcf-pdf-viewer 0.9.0 → 1.0.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 +1 -1
- package/package.json +42 -26
- package/{src/display → pdfjs/dist}/display_utils.js +344 -139
- package/{src/display → pdfjs/dist}/fetch_stream.js +115 -97
- package/pdfjs/dist/l10n_utils.js +140 -0
- package/{src/shared → pdfjs/dist}/message_handler.js +243 -259
- package/{src/display → pdfjs/dist}/network.js +149 -87
- package/{src/display/content_disposition.js → pdfjs/dist/network_utils.js} +167 -55
- package/{src/display → pdfjs/dist}/node_stream.js +133 -98
- package/pdfjs/dist/pdf.js +12778 -0
- package/pdfjs/dist/pdf_link_service.js +638 -0
- package/pdfjs/dist/pdf_rendering_queue.js +199 -0
- package/pdfjs/dist/pdf_thumbnail_viewer.js +819 -0
- package/pdfjs/dist/pdf_viewer.js +3598 -0
- package/pdfjs/dist/ui_utils.js +1033 -0
- package/{src/shared → pdfjs/dist}/util.js +301 -287
- package/pdfjs/dist/worker.js +62813 -0
- package/src/vcf-pdf-viewer.js +98 -46
- package/theme/lumo/vcf-pdf-viewer-styles.js +4 -4
- package/theme/material/vcf-pdf-viewer-styles.js +4 -4
- package/theme/material/vcf-pdf-viewer.js +2 -2
- package/src/core/.eslintrc +0 -13
- package/src/core/annotation.js +0 -2948
- package/src/core/arithmetic_decoder.js +0 -182
- package/src/core/ascii_85_stream.js +0 -98
- package/src/core/ascii_hex_stream.js +0 -79
- package/src/core/base_stream.js +0 -110
- package/src/core/bidi.js +0 -438
- package/src/core/calibri_factors.js +0 -308
- package/src/core/catalog.js +0 -1459
- package/src/core/ccitt.js +0 -1062
- package/src/core/ccitt_stream.js +0 -60
- package/src/core/cff_font.js +0 -116
- package/src/core/cff_parser.js +0 -1949
- package/src/core/charsets.js +0 -119
- package/src/core/chunked_stream.js +0 -557
- package/src/core/cmap.js +0 -1039
- package/src/core/colorspace.js +0 -1533
- package/src/core/core_utils.js +0 -464
- package/src/core/crypto.js +0 -1900
- package/src/core/decode_stream.js +0 -170
- package/src/core/decrypt_stream.js +0 -59
- package/src/core/default_appearance.js +0 -99
- package/src/core/document.js +0 -1456
- package/src/core/encodings.js +0 -301
- package/src/core/evaluator.js +0 -4601
- package/src/core/file_spec.js +0 -108
- package/src/core/flate_stream.js +0 -402
- package/src/core/font_renderer.js +0 -882
- package/src/core/fonts.js +0 -3260
- package/src/core/fonts_utils.js +0 -221
- package/src/core/function.js +0 -1257
- package/src/core/glyf.js +0 -706
- package/src/core/glyphlist.js +0 -4558
- package/src/core/helvetica_factors.js +0 -353
- package/src/core/image.js +0 -802
- package/src/core/image_utils.js +0 -291
- package/src/core/jbig2.js +0 -2572
- package/src/core/jbig2_stream.js +0 -73
- package/src/core/jpeg_stream.js +0 -105
- package/src/core/jpg.js +0 -1416
- package/src/core/jpx.js +0 -2343
- package/src/core/jpx_stream.js +0 -87
- package/src/core/liberationsans_widths.js +0 -221
- package/src/core/lzw_stream.js +0 -150
- package/src/core/metadata_parser.js +0 -146
- package/src/core/metrics.js +0 -2970
- package/src/core/murmurhash3.js +0 -139
- package/src/core/myriadpro_factors.js +0 -290
- package/src/core/name_number_tree.js +0 -153
- package/src/core/object_loader.js +0 -149
- package/src/core/opentype_file_builder.js +0 -154
- package/src/core/operator_list.js +0 -734
- package/src/core/parser.js +0 -1416
- package/src/core/pattern.js +0 -985
- package/src/core/pdf_manager.js +0 -217
- package/src/core/predictor_stream.js +0 -238
- package/src/core/primitives.js +0 -402
- package/src/core/ps_parser.js +0 -272
- package/src/core/run_length_stream.js +0 -61
- package/src/core/segoeui_factors.js +0 -308
- package/src/core/standard_fonts.js +0 -817
- package/src/core/stream.js +0 -103
- package/src/core/struct_tree.js +0 -335
- package/src/core/to_unicode_map.js +0 -103
- package/src/core/type1_font.js +0 -421
- package/src/core/type1_parser.js +0 -776
- package/src/core/unicode.js +0 -1649
- package/src/core/worker.js +0 -848
- package/src/core/worker_stream.js +0 -135
- package/src/core/writer.js +0 -278
- package/src/core/xfa/bind.js +0 -652
- package/src/core/xfa/builder.js +0 -207
- package/src/core/xfa/config.js +0 -1926
- package/src/core/xfa/connection_set.js +0 -202
- package/src/core/xfa/data.js +0 -82
- package/src/core/xfa/datasets.js +0 -76
- package/src/core/xfa/factory.js +0 -111
- package/src/core/xfa/fonts.js +0 -181
- package/src/core/xfa/formcalc_lexer.js +0 -385
- package/src/core/xfa/formcalc_parser.js +0 -1340
- package/src/core/xfa/html_utils.js +0 -639
- package/src/core/xfa/layout.js +0 -383
- package/src/core/xfa/locale_set.js +0 -345
- package/src/core/xfa/namespaces.js +0 -81
- package/src/core/xfa/parser.js +0 -184
- package/src/core/xfa/setup.js +0 -38
- package/src/core/xfa/signature.js +0 -40
- package/src/core/xfa/som.js +0 -338
- package/src/core/xfa/stylesheet.js +0 -40
- package/src/core/xfa/template.js +0 -6260
- package/src/core/xfa/text.js +0 -290
- package/src/core/xfa/unknown.js +0 -29
- package/src/core/xfa/utils.js +0 -217
- package/src/core/xfa/xdp.js +0 -59
- package/src/core/xfa/xfa_object.js +0 -1130
- package/src/core/xfa/xhtml.js +0 -543
- package/src/core/xfa_fonts.js +0 -208
- package/src/core/xml_parser.js +0 -507
- package/src/core/xref.js +0 -899
- package/src/display/annotation_layer.js +0 -2107
- package/src/display/annotation_storage.js +0 -113
- package/src/display/api.js +0 -3292
- package/src/display/base_factory.js +0 -180
- package/src/display/canvas.js +0 -2828
- package/src/display/font_loader.js +0 -484
- package/src/display/metadata.js +0 -41
- package/src/display/network_utils.js +0 -100
- package/src/display/node_utils.js +0 -83
- package/src/display/optional_content_config.js +0 -189
- package/src/display/pattern_helper.js +0 -659
- package/src/display/svg.js +0 -1709
- package/src/display/text_layer.js +0 -847
- package/src/display/transport_stream.js +0 -303
- package/src/display/worker_options.js +0 -40
- package/src/display/xfa_layer.js +0 -204
- package/src/doc_helper.js +0 -25
- package/src/images/logo.svg +0 -41
- package/src/interfaces.js +0 -169
- package/src/license_header.js +0 -14
- package/src/license_header_libre.js +0 -21
- package/src/pdf.image_decoders.js +0 -46
- package/src/pdf.js +0 -146
- package/src/pdf.sandbox.external.js +0 -181
- package/src/pdf.sandbox.js +0 -151
- package/src/pdf.scripting.js +0 -25
- package/src/pdf.worker.entry.js +0 -19
- package/src/pdf.worker.js +0 -23
- package/src/scripting_api/aform.js +0 -608
- package/src/scripting_api/app.js +0 -621
- package/src/scripting_api/color.js +0 -129
- package/src/scripting_api/common.js +0 -58
- package/src/scripting_api/console.js +0 -38
- package/src/scripting_api/constants.js +0 -208
- package/src/scripting_api/doc.js +0 -1195
- package/src/scripting_api/error.js +0 -23
- package/src/scripting_api/event.js +0 -232
- package/src/scripting_api/field.js +0 -620
- package/src/scripting_api/fullscreen.js +0 -145
- package/src/scripting_api/initialization.js +0 -223
- package/src/scripting_api/pdf_object.js +0 -24
- package/src/scripting_api/print_params.js +0 -146
- package/src/scripting_api/proxy.js +0 -139
- package/src/scripting_api/thermometer.js +0 -69
- package/src/scripting_api/util.js +0 -581
- package/src/shared/.eslintrc +0 -13
- package/src/shared/cffStandardStrings.js +0 -311
- package/src/shared/compatibility.js +0 -114
- package/src/shared/fonts_utils.js +0 -429
- package/src/shared/is_node.js +0 -27
- package/src/shared/scripting_utils.js +0 -85
- package/src/worker_loader.js +0 -32
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { n as stringToBytes, c as assert, M as MissingPDFException, v as UnexpectedResponseException } from './util.js';
|
|
2
|
+
import { i as isPdfFile } from './display_utils.js';
|
|
3
|
+
|
|
1
4
|
/* Copyright 2017 Mozilla Foundation
|
|
2
5
|
*
|
|
3
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,10 +15,6 @@
|
|
|
12
15
|
* See the License for the specific language governing permissions and
|
|
13
16
|
* limitations under the License.
|
|
14
17
|
*/
|
|
15
|
-
|
|
16
|
-
import { stringToBytes } from "../shared/util.js";
|
|
17
|
-
|
|
18
|
-
// This getFilenameFromContentDispositionHeader function is adapted from
|
|
19
18
|
// https://github.com/Rob--W/open-in-browser/blob/7e2e35a38b8b4e981b11da7b2f01df0149049e92/extension/content-disposition.js
|
|
20
19
|
// with the following changes:
|
|
21
20
|
// - Modified to conform to PDF.js's coding style.
|
|
@@ -29,11 +28,12 @@ import { stringToBytes } from "../shared/util.js";
|
|
|
29
28
|
* @param {string} contentDisposition
|
|
30
29
|
* @returns {string} Filename, if found in the Content-Disposition header.
|
|
31
30
|
*/
|
|
31
|
+
|
|
32
32
|
function getFilenameFromContentDispositionHeader(contentDisposition) {
|
|
33
|
-
let needsEncodingFixup = true;
|
|
33
|
+
let needsEncodingFixup = true; // filename*=ext-value ("ext-value" from RFC 5987, referenced by RFC 6266).
|
|
34
34
|
|
|
35
|
-
// filename*=ext-value ("ext-value" from RFC 5987, referenced by RFC 6266).
|
|
36
35
|
let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
|
|
36
|
+
|
|
37
37
|
if (tmp) {
|
|
38
38
|
tmp = tmp[1];
|
|
39
39
|
let filename = rfc2616unquote(tmp);
|
|
@@ -41,52 +41,48 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
|
|
|
41
41
|
filename = rfc5987decode(filename);
|
|
42
42
|
filename = rfc2047decode(filename);
|
|
43
43
|
return fixupEncoding(filename);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Continuations (RFC 2231 section 3, referenced by RFC 5987 section 3.1).
|
|
44
|
+
} // Continuations (RFC 2231 section 3, referenced by RFC 5987 section 3.1).
|
|
47
45
|
// filename*n*=part
|
|
48
46
|
// filename*n=part
|
|
47
|
+
|
|
48
|
+
|
|
49
49
|
tmp = rfc2231getparam(contentDisposition);
|
|
50
|
+
|
|
50
51
|
if (tmp) {
|
|
51
52
|
// RFC 2047, section
|
|
52
53
|
const filename = rfc2047decode(tmp);
|
|
53
54
|
return fixupEncoding(filename);
|
|
54
|
-
}
|
|
55
|
+
} // filename=value (RFC 5987, section 4.1).
|
|
56
|
+
|
|
55
57
|
|
|
56
|
-
// filename=value (RFC 5987, section 4.1).
|
|
57
58
|
tmp = toParamRegExp("filename", "i").exec(contentDisposition);
|
|
59
|
+
|
|
58
60
|
if (tmp) {
|
|
59
61
|
tmp = tmp[1];
|
|
60
62
|
let filename = rfc2616unquote(tmp);
|
|
61
63
|
filename = rfc2047decode(filename);
|
|
62
64
|
return fixupEncoding(filename);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// After this line there are only function declarations. We cannot put
|
|
65
|
+
} // After this line there are only function declarations. We cannot put
|
|
66
66
|
// "return" here for readability because babel would then drop the function
|
|
67
67
|
// declarations...
|
|
68
|
+
|
|
69
|
+
|
|
68
70
|
function toParamRegExp(attributePattern, flags) {
|
|
69
|
-
return new RegExp(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"\\s*=\\s*" +
|
|
73
|
-
// Captures: value = token | quoted-string
|
|
74
|
-
// (RFC 2616, section 3.6 and referenced by RFC 6266 4.1)
|
|
75
|
-
"(" +
|
|
76
|
-
'[^";\\s][^;\\s]*' +
|
|
77
|
-
"|" +
|
|
78
|
-
'"(?:[^"\\\\]|\\\\"?)+"?' +
|
|
79
|
-
")",
|
|
80
|
-
flags
|
|
81
|
-
);
|
|
71
|
+
return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + // Captures: value = token | quoted-string
|
|
72
|
+
// (RFC 2616, section 3.6 and referenced by RFC 6266 4.1)
|
|
73
|
+
"(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
|
|
82
74
|
}
|
|
75
|
+
|
|
83
76
|
function textdecode(encoding, value) {
|
|
84
77
|
if (encoding) {
|
|
85
78
|
if (!/^[\x00-\xFF]+$/.test(value)) {
|
|
86
79
|
return value;
|
|
87
80
|
}
|
|
81
|
+
|
|
88
82
|
try {
|
|
89
|
-
const decoder = new TextDecoder(encoding, {
|
|
83
|
+
const decoder = new TextDecoder(encoding, {
|
|
84
|
+
fatal: true
|
|
85
|
+
});
|
|
90
86
|
const buffer = stringToBytes(value);
|
|
91
87
|
value = decoder.decode(buffer);
|
|
92
88
|
needsEncodingFixup = false;
|
|
@@ -102,127 +98,243 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
|
|
|
102
98
|
}
|
|
103
99
|
}
|
|
104
100
|
}
|
|
101
|
+
|
|
105
102
|
return value;
|
|
106
103
|
}
|
|
104
|
+
|
|
107
105
|
function fixupEncoding(value) {
|
|
108
106
|
if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
|
|
109
107
|
// Maybe multi-byte UTF-8.
|
|
110
108
|
value = textdecode("utf-8", value);
|
|
109
|
+
|
|
111
110
|
if (needsEncodingFixup) {
|
|
112
111
|
// Try iso-8859-1 encoding.
|
|
113
112
|
value = textdecode("iso-8859-1", value);
|
|
114
113
|
}
|
|
115
114
|
}
|
|
115
|
+
|
|
116
116
|
return value;
|
|
117
117
|
}
|
|
118
|
+
|
|
118
119
|
function rfc2231getparam(contentDispositionStr) {
|
|
119
120
|
const matches = [];
|
|
120
|
-
let match;
|
|
121
|
-
// Iterate over all filename*n= and filename*n*= with n being an integer
|
|
121
|
+
let match; // Iterate over all filename*n= and filename*n*= with n being an integer
|
|
122
122
|
// of at least zero. Any non-zero number must not start with '0'.
|
|
123
|
+
|
|
123
124
|
const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
|
|
125
|
+
|
|
124
126
|
while ((match = iter.exec(contentDispositionStr)) !== null) {
|
|
125
127
|
let [, n, quot, part] = match; // eslint-disable-line prefer-const
|
|
128
|
+
|
|
126
129
|
n = parseInt(n, 10);
|
|
130
|
+
|
|
127
131
|
if (n in matches) {
|
|
128
132
|
// Ignore anything after the invalid second filename*0.
|
|
129
133
|
if (n === 0) {
|
|
130
134
|
break;
|
|
131
135
|
}
|
|
136
|
+
|
|
132
137
|
continue;
|
|
133
138
|
}
|
|
139
|
+
|
|
134
140
|
matches[n] = [quot, part];
|
|
135
141
|
}
|
|
142
|
+
|
|
136
143
|
const parts = [];
|
|
144
|
+
|
|
137
145
|
for (let n = 0; n < matches.length; ++n) {
|
|
138
146
|
if (!(n in matches)) {
|
|
139
147
|
// Numbers must be consecutive. Truncate when there is a hole.
|
|
140
148
|
break;
|
|
141
149
|
}
|
|
150
|
+
|
|
142
151
|
let [quot, part] = matches[n]; // eslint-disable-line prefer-const
|
|
152
|
+
|
|
143
153
|
part = rfc2616unquote(part);
|
|
154
|
+
|
|
144
155
|
if (quot) {
|
|
145
156
|
part = unescape(part);
|
|
157
|
+
|
|
146
158
|
if (n === 0) {
|
|
147
159
|
part = rfc5987decode(part);
|
|
148
160
|
}
|
|
149
161
|
}
|
|
162
|
+
|
|
150
163
|
parts.push(part);
|
|
151
164
|
}
|
|
165
|
+
|
|
152
166
|
return parts.join("");
|
|
153
167
|
}
|
|
168
|
+
|
|
154
169
|
function rfc2616unquote(value) {
|
|
155
170
|
if (value.startsWith('"')) {
|
|
156
|
-
const parts = value.slice(1).split('\\"');
|
|
157
|
-
|
|
171
|
+
const parts = value.slice(1).split('\\"'); // Find the first unescaped " and terminate there.
|
|
172
|
+
|
|
158
173
|
for (let i = 0; i < parts.length; ++i) {
|
|
159
174
|
const quotindex = parts[i].indexOf('"');
|
|
175
|
+
|
|
160
176
|
if (quotindex !== -1) {
|
|
161
177
|
parts[i] = parts[i].slice(0, quotindex);
|
|
162
178
|
parts.length = i + 1; // Truncates and stop the iteration.
|
|
163
179
|
}
|
|
180
|
+
|
|
164
181
|
parts[i] = parts[i].replace(/\\(.)/g, "$1");
|
|
165
182
|
}
|
|
183
|
+
|
|
166
184
|
value = parts.join('"');
|
|
167
185
|
}
|
|
186
|
+
|
|
168
187
|
return value;
|
|
169
188
|
}
|
|
189
|
+
|
|
170
190
|
function rfc5987decode(extvalue) {
|
|
171
191
|
// Decodes "ext-value" from RFC 5987.
|
|
172
192
|
const encodingend = extvalue.indexOf("'");
|
|
193
|
+
|
|
173
194
|
if (encodingend === -1) {
|
|
174
195
|
// Some servers send "filename*=" without encoding 'language' prefix,
|
|
175
196
|
// e.g. in https://github.com/Rob--W/open-in-browser/issues/26
|
|
176
197
|
// Let's accept the value like Firefox (57) (Chrome 62 rejects it).
|
|
177
198
|
return extvalue;
|
|
178
199
|
}
|
|
200
|
+
|
|
179
201
|
const encoding = extvalue.slice(0, encodingend);
|
|
180
|
-
const langvalue = extvalue.slice(encodingend + 1);
|
|
181
|
-
|
|
202
|
+
const langvalue = extvalue.slice(encodingend + 1); // Ignore language (RFC 5987 section 3.2.1, and RFC 6266 section 4.1 ).
|
|
203
|
+
|
|
182
204
|
const value = langvalue.replace(/^[^']*'/, "");
|
|
183
205
|
return textdecode(encoding, value);
|
|
184
206
|
}
|
|
207
|
+
|
|
185
208
|
function rfc2047decode(value) {
|
|
186
209
|
// RFC 2047-decode the result. Firefox tried to drop support for it, but
|
|
187
210
|
// backed out because some servers use it - https://bugzil.la/875615
|
|
188
211
|
// Firefox's condition for decoding is here: https://searchfox.org/mozilla-central/rev/4a590a5a15e35d88a3b23dd6ac3c471cf85b04a8/netwerk/mime/nsMIMEHeaderParamImpl.cpp#742-748
|
|
189
|
-
|
|
190
212
|
// We are more strict and only recognize RFC 2047-encoding if the value
|
|
191
213
|
// starts with "=?", since then it is likely that the full value is
|
|
192
214
|
// RFC 2047-encoded.
|
|
193
|
-
|
|
194
215
|
// Firefox also decodes words even where RFC 2047 section 5 states:
|
|
195
216
|
// "An 'encoded-word' MUST NOT appear within a 'quoted-string'."
|
|
196
217
|
if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
|
|
197
218
|
return value;
|
|
198
|
-
}
|
|
199
|
-
// RFC 2047, section 2.4
|
|
219
|
+
} // RFC 2047, section 2.4
|
|
200
220
|
// encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
|
|
201
221
|
// charset = token (but let's restrict to characters that denote a
|
|
202
222
|
// possibly valid encoding).
|
|
203
223
|
// encoding = q or b
|
|
204
224
|
// encoded-text = any printable ASCII character other than ? or space.
|
|
205
225
|
// ... but Firefox permits ? and space.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return textdecode(charset, text);
|
|
216
|
-
} // else encoding is b or B - base64 (RFC 2047 section 4.1)
|
|
217
|
-
try {
|
|
218
|
-
text = atob(text);
|
|
219
|
-
} catch (e) {}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
|
|
229
|
+
if (encoding === "q" || encoding === "Q") {
|
|
230
|
+
// RFC 2047 section 4.2.
|
|
231
|
+
text = text.replace(/_/g, " ");
|
|
232
|
+
text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
|
|
233
|
+
return String.fromCharCode(parseInt(hex, 16));
|
|
234
|
+
});
|
|
220
235
|
return textdecode(charset, text);
|
|
221
|
-
}
|
|
222
|
-
|
|
236
|
+
} // else encoding is b or B - base64 (RFC 2047 section 4.1)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
text = atob(text);
|
|
241
|
+
} catch (e) {}
|
|
242
|
+
|
|
243
|
+
return textdecode(charset, text);
|
|
244
|
+
});
|
|
223
245
|
}
|
|
224
246
|
|
|
225
247
|
return "";
|
|
226
248
|
}
|
|
227
249
|
|
|
228
|
-
|
|
250
|
+
/* Copyright 2012 Mozilla Foundation
|
|
251
|
+
*
|
|
252
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
253
|
+
* you may not use this file except in compliance with the License.
|
|
254
|
+
* You may obtain a copy of the License at
|
|
255
|
+
*
|
|
256
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
257
|
+
*
|
|
258
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
259
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
260
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
261
|
+
* See the License for the specific language governing permissions and
|
|
262
|
+
* limitations under the License.
|
|
263
|
+
*/
|
|
264
|
+
|
|
265
|
+
function validateRangeRequestCapabilities({
|
|
266
|
+
getResponseHeader,
|
|
267
|
+
isHttp,
|
|
268
|
+
rangeChunkSize,
|
|
269
|
+
disableRange
|
|
270
|
+
}) {
|
|
271
|
+
assert(rangeChunkSize > 0, "Range chunk size must be larger than zero");
|
|
272
|
+
const returnValues = {
|
|
273
|
+
allowRangeRequests: false,
|
|
274
|
+
suggestedLength: undefined
|
|
275
|
+
};
|
|
276
|
+
const length = parseInt(getResponseHeader("Content-Length"), 10);
|
|
277
|
+
|
|
278
|
+
if (!Number.isInteger(length)) {
|
|
279
|
+
return returnValues;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
returnValues.suggestedLength = length;
|
|
283
|
+
|
|
284
|
+
if (length <= 2 * rangeChunkSize) {
|
|
285
|
+
// The file size is smaller than the size of two chunks, so it does not
|
|
286
|
+
// make any sense to abort the request and retry with a range request.
|
|
287
|
+
return returnValues;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (disableRange || !isHttp) {
|
|
291
|
+
return returnValues;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (getResponseHeader("Accept-Ranges") !== "bytes") {
|
|
295
|
+
return returnValues;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
|
|
299
|
+
|
|
300
|
+
if (contentEncoding !== "identity") {
|
|
301
|
+
return returnValues;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
returnValues.allowRangeRequests = true;
|
|
305
|
+
return returnValues;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function extractFilenameFromHeader(getResponseHeader) {
|
|
309
|
+
const contentDisposition = getResponseHeader("Content-Disposition");
|
|
310
|
+
|
|
311
|
+
if (contentDisposition) {
|
|
312
|
+
let filename = getFilenameFromContentDispositionHeader(contentDisposition);
|
|
313
|
+
|
|
314
|
+
if (filename.includes("%")) {
|
|
315
|
+
try {
|
|
316
|
+
filename = decodeURIComponent(filename);
|
|
317
|
+
} catch (ex) {}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (isPdfFile(filename)) {
|
|
321
|
+
return filename;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function createResponseStatusError(status, url) {
|
|
329
|
+
if (status === 404 || status === 0 && url.startsWith("file:")) {
|
|
330
|
+
return new MissingPDFException('Missing PDF "' + url + '".');
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return new UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function validateResponseStatus(status) {
|
|
337
|
+
return status === 200 || status === 206;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export { validateResponseStatus as a, createResponseStatusError as c, extractFilenameFromHeader as e, validateRangeRequestCapabilities as v };
|