@loaders.gl/core 3.4.13 → 3.4.15
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/dist/dist.min.js +106 -104
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +55 -55
- package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js +14 -86
- package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js +17 -33
- package/dist/es5/iterators/make-iterator/make-array-buffer-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-blob-iterator.js +10 -39
- package/dist/es5/iterators/make-iterator/make-blob-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-iterator.js +1 -1
- package/dist/es5/iterators/make-iterator/make-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-stream-iterator.js +24 -119
- package/dist/es5/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-string-iterator.js +11 -30
- package/dist/es5/iterators/make-iterator/make-string-iterator.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-dom-stream.js +22 -54
- package/dist/es5/iterators/make-stream/make-dom-stream.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-node-stream.js +50 -152
- package/dist/es5/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/es5/javascript-utils/is-type.js +18 -56
- package/dist/es5/javascript-utils/is-type.js.map +1 -1
- package/dist/es5/lib/api/encode.js +54 -203
- package/dist/es5/lib/api/encode.js.map +1 -1
- package/dist/es5/lib/api/load-in-batches.js +9 -41
- package/dist/es5/lib/api/load-in-batches.js.map +1 -1
- package/dist/es5/lib/api/load.js +15 -48
- package/dist/es5/lib/api/load.js.map +1 -1
- package/dist/es5/lib/api/loader-options.js +2 -2
- package/dist/es5/lib/api/parse-in-batches.js +71 -259
- package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
- package/dist/es5/lib/api/parse-sync.js +9 -11
- package/dist/es5/lib/api/parse-sync.js.map +1 -1
- package/dist/es5/lib/api/parse.js +62 -125
- package/dist/es5/lib/api/parse.js.map +1 -1
- package/dist/es5/lib/api/register-loaders.js +8 -25
- package/dist/es5/lib/api/register-loaders.js.map +1 -1
- package/dist/es5/lib/api/save.js +4 -28
- package/dist/es5/lib/api/save.js.map +1 -1
- package/dist/es5/lib/api/select-loader.js +76 -170
- package/dist/es5/lib/api/select-loader.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-error-message.js +13 -44
- package/dist/es5/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-file.js +10 -37
- package/dist/es5/lib/fetch/fetch-file.js.map +1 -1
- package/dist/es5/lib/fetch/read-array-buffer.js +19 -65
- package/dist/es5/lib/fetch/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/fetch/read-file.js +2 -2
- package/dist/es5/lib/fetch/read-file.js.map +1 -1
- package/dist/es5/lib/fetch/write-file.js +8 -29
- package/dist/es5/lib/fetch/write-file.js.map +1 -1
- package/dist/es5/lib/filesystems/browser-filesystem.js +78 -227
- package/dist/es5/lib/filesystems/browser-filesystem.js.map +1 -1
- package/dist/es5/lib/filesystems/read-array-buffer.js +6 -33
- package/dist/es5/lib/filesystems/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/init.js +1 -1
- package/dist/es5/lib/init.js.map +1 -1
- package/dist/es5/lib/loader-utils/check-errors.js +11 -39
- package/dist/es5/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-data.js +62 -187
- package/dist/es5/lib/loader-utils/get-data.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-fetch-function.js +3 -5
- package/dist/es5/lib/loader-utils/get-fetch-function.js.map +1 -1
- package/dist/es5/lib/loader-utils/loader-context.js +8 -12
- package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/es5/lib/loader-utils/loggers.js +37 -67
- package/dist/es5/lib/loader-utils/loggers.js.map +1 -1
- package/dist/es5/lib/loader-utils/normalize-loader.js +9 -9
- package/dist/es5/lib/loader-utils/normalize-loader.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-defaults.js +2 -2
- package/dist/es5/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-utils.js +43 -59
- package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/es5/lib/progress/fetch-progress.js +49 -125
- package/dist/es5/lib/progress/fetch-progress.js.map +1 -1
- package/dist/es5/lib/utils/log.js +1 -1
- package/dist/es5/lib/utils/log.js.map +1 -1
- package/dist/es5/lib/utils/mime-type-utils.js +4 -4
- package/dist/es5/lib/utils/mime-type-utils.js.map +1 -1
- package/dist/es5/lib/utils/resource-utils.js +8 -8
- package/dist/es5/lib/utils/resource-utils.js.map +1 -1
- package/dist/es5/lib/utils/response-utils.js +71 -171
- package/dist/es5/lib/utils/response-utils.js.map +1 -1
- package/dist/es5/lib/utils/url-utils.js +2 -2
- package/dist/es5/lib/utils/url-utils.js.map +1 -1
- package/dist/es5/null-loader.js +14 -100
- package/dist/es5/null-loader.js.map +1 -1
- package/dist/esm/lib/init.js +1 -1
- package/dist/esm/null-loader.js +1 -1
- package/dist/null-worker.js +1 -1
- package/package.json +5 -5
- package/src/.DS_Store +0 -0
- package/src/lib/.DS_Store +0 -0
|
@@ -1,134 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = fetchProgress;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
async function fetchProgress(response, onProgress) {
|
|
8
|
+
let onDone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : () => {};
|
|
9
|
+
let onError = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : () => {};
|
|
10
|
+
response = await response;
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
14
|
+
const body = response.body;
|
|
15
|
+
if (!body) {
|
|
16
|
+
return response;
|
|
17
|
+
}
|
|
18
|
+
const contentLength = response.headers.get('content-length') || 0;
|
|
19
|
+
const totalBytes = contentLength ? parseInt(contentLength) : 0;
|
|
20
|
+
if (!(totalBytes > 0)) {
|
|
21
|
+
return response;
|
|
22
|
+
}
|
|
23
|
+
if (typeof ReadableStream === 'undefined' || !body.getReader) {
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
const progressStream = new ReadableStream({
|
|
27
|
+
async start(controller) {
|
|
28
|
+
const reader = body.getReader();
|
|
29
|
+
await read(controller, reader, 0, totalBytes, onProgress, onDone, onError);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return new Response(progressStream);
|
|
12
33
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
case 7:
|
|
37
|
-
body = response.body;
|
|
38
|
-
if (body) {
|
|
39
|
-
_context2.next = 10;
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
return _context2.abrupt("return", response);
|
|
43
|
-
case 10:
|
|
44
|
-
contentLength = response.headers.get('content-length') || 0;
|
|
45
|
-
totalBytes = contentLength ? parseInt(contentLength) : 0;
|
|
46
|
-
if (totalBytes > 0) {
|
|
47
|
-
_context2.next = 14;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
return _context2.abrupt("return", response);
|
|
51
|
-
case 14:
|
|
52
|
-
if (!(typeof ReadableStream === 'undefined' || !body.getReader)) {
|
|
53
|
-
_context2.next = 16;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
return _context2.abrupt("return", response);
|
|
57
|
-
case 16:
|
|
58
|
-
progressStream = new ReadableStream({
|
|
59
|
-
start: function start(controller) {
|
|
60
|
-
return (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() {
|
|
61
|
-
var reader;
|
|
62
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
63
|
-
while (1) switch (_context.prev = _context.next) {
|
|
64
|
-
case 0:
|
|
65
|
-
reader = body.getReader();
|
|
66
|
-
_context.next = 3;
|
|
67
|
-
return read(controller, reader, 0, totalBytes, onProgress, onDone, onError);
|
|
68
|
-
case 3:
|
|
69
|
-
case "end":
|
|
70
|
-
return _context.stop();
|
|
71
|
-
}
|
|
72
|
-
}, _callee);
|
|
73
|
-
}))();
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
return _context2.abrupt("return", new Response(progressStream));
|
|
77
|
-
case 18:
|
|
78
|
-
case "end":
|
|
79
|
-
return _context2.stop();
|
|
80
|
-
}
|
|
81
|
-
}, _callee2);
|
|
82
|
-
}));
|
|
83
|
-
return _fetchProgress.apply(this, arguments);
|
|
84
|
-
}
|
|
85
|
-
function read(_x3, _x4, _x5, _x6, _x7, _x8, _x9) {
|
|
86
|
-
return _read.apply(this, arguments);
|
|
87
|
-
}
|
|
88
|
-
function _read() {
|
|
89
|
-
_read = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
|
|
90
|
-
var _yield$reader$read, done, value, percent;
|
|
91
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
92
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
93
|
-
case 0:
|
|
94
|
-
_context3.prev = 0;
|
|
95
|
-
_context3.next = 3;
|
|
96
|
-
return reader.read();
|
|
97
|
-
case 3:
|
|
98
|
-
_yield$reader$read = _context3.sent;
|
|
99
|
-
done = _yield$reader$read.done;
|
|
100
|
-
value = _yield$reader$read.value;
|
|
101
|
-
if (!done) {
|
|
102
|
-
_context3.next = 10;
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
onDone();
|
|
106
|
-
controller.close();
|
|
107
|
-
return _context3.abrupt("return");
|
|
108
|
-
case 10:
|
|
109
|
-
loadedBytes += value.byteLength;
|
|
110
|
-
percent = Math.round(loadedBytes / totalBytes * 100);
|
|
111
|
-
onProgress(percent, {
|
|
112
|
-
loadedBytes: loadedBytes,
|
|
113
|
-
totalBytes: totalBytes
|
|
114
|
-
});
|
|
115
|
-
controller.enqueue(value);
|
|
116
|
-
_context3.next = 16;
|
|
117
|
-
return read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
|
|
118
|
-
case 16:
|
|
119
|
-
_context3.next = 22;
|
|
120
|
-
break;
|
|
121
|
-
case 18:
|
|
122
|
-
_context3.prev = 18;
|
|
123
|
-
_context3.t0 = _context3["catch"](0);
|
|
124
|
-
controller.error(_context3.t0);
|
|
125
|
-
onError(_context3.t0);
|
|
126
|
-
case 22:
|
|
127
|
-
case "end":
|
|
128
|
-
return _context3.stop();
|
|
129
|
-
}
|
|
130
|
-
}, _callee3, null, [[0, 18]]);
|
|
131
|
-
}));
|
|
132
|
-
return _read.apply(this, arguments);
|
|
34
|
+
async function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
|
|
35
|
+
try {
|
|
36
|
+
const {
|
|
37
|
+
done,
|
|
38
|
+
value
|
|
39
|
+
} = await reader.read();
|
|
40
|
+
if (done) {
|
|
41
|
+
onDone();
|
|
42
|
+
controller.close();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
loadedBytes += value.byteLength;
|
|
46
|
+
const percent = Math.round(loadedBytes / totalBytes * 100);
|
|
47
|
+
onProgress(percent, {
|
|
48
|
+
loadedBytes,
|
|
49
|
+
totalBytes
|
|
50
|
+
});
|
|
51
|
+
controller.enqueue(value);
|
|
52
|
+
await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
controller.error(error);
|
|
55
|
+
onError(error);
|
|
56
|
+
}
|
|
133
57
|
}
|
|
134
58
|
//# sourceMappingURL=fetch-progress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-progress.js","names":["fetchProgress","
|
|
1
|
+
{"version":3,"file":"fetch-progress.js","names":["fetchProgress","response","onProgress","onDone","arguments","length","undefined","onError","ok","body","contentLength","headers","get","totalBytes","parseInt","ReadableStream","getReader","progressStream","start","controller","reader","read","Response","loadedBytes","done","value","close","byteLength","percent","Math","round","enqueue","error"],"sources":["../../../../src/lib/progress/fetch-progress.ts"],"sourcesContent":["// Forked from github AnthumChris/fetch-progress-indicators under MIT license\n\n/**\n * Intercepts the Response stream and creates a new Response\n */\nexport default async function fetchProgress(\n response: Response | Promise<Response>,\n onProgress: any, // TODO better callback types\n onDone = () => {},\n onError = () => {}\n) {\n response = await response;\n if (!response.ok) {\n // ERROR checking needs to be done separately\n return response;\n }\n const body = response.body;\n if (!body) {\n // 'ReadableStream not yet supported in this browser.\n return response;\n }\n const contentLength = response.headers.get('content-length') || 0;\n const totalBytes = contentLength ? parseInt(contentLength) : 0;\n if (!(totalBytes > 0)) {\n return response;\n }\n // Currently override only implemented in browser\n if (typeof ReadableStream === 'undefined' || !body.getReader) {\n return response;\n }\n\n // Create a new stream that invisbly wraps original stream\n const progressStream = new ReadableStream({\n async start(controller) {\n const reader = body.getReader();\n await read(controller, reader, 0, totalBytes, onProgress, onDone, onError);\n }\n });\n\n return new Response(progressStream);\n}\n\n// Forward to original streams controller\n// TODO - this causes a crazy deep \"async stack\"... rewrite as async iterator?\n// eslint-disable-next-line max-params\nasync function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {\n try {\n const {done, value} = await reader.read();\n if (done) {\n onDone();\n controller.close();\n return;\n }\n loadedBytes += value.byteLength;\n const percent = Math.round((loadedBytes / totalBytes) * 100);\n onProgress(percent, {loadedBytes, totalBytes});\n controller.enqueue(value);\n await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);\n } catch (error) {\n controller.error(error);\n onError(error);\n }\n}\n"],"mappings":";;;;;;AAKe,eAAeA,aAAaA,CACzCC,QAAsC,EACtCC,UAAe,EAGf;EAAA,IAFAC,MAAM,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,MAAM,CAAC,CAAC;EAAA,IACjBG,OAAO,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,MAAM,CAAC,CAAC;EAElBH,QAAQ,GAAG,MAAMA,QAAQ;EACzB,IAAI,CAACA,QAAQ,CAACO,EAAE,EAAE;IAEhB,OAAOP,QAAQ;EACjB;EACA,MAAMQ,IAAI,GAAGR,QAAQ,CAACQ,IAAI;EAC1B,IAAI,CAACA,IAAI,EAAE;IAET,OAAOR,QAAQ;EACjB;EACA,MAAMS,aAAa,GAAGT,QAAQ,CAACU,OAAO,CAACC,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC;EACjE,MAAMC,UAAU,GAAGH,aAAa,GAAGI,QAAQ,CAACJ,aAAa,CAAC,GAAG,CAAC;EAC9D,IAAI,EAAEG,UAAU,GAAG,CAAC,CAAC,EAAE;IACrB,OAAOZ,QAAQ;EACjB;EAEA,IAAI,OAAOc,cAAc,KAAK,WAAW,IAAI,CAACN,IAAI,CAACO,SAAS,EAAE;IAC5D,OAAOf,QAAQ;EACjB;EAGA,MAAMgB,cAAc,GAAG,IAAIF,cAAc,CAAC;IACxC,MAAMG,KAAKA,CAACC,UAAU,EAAE;MACtB,MAAMC,MAAM,GAAGX,IAAI,CAACO,SAAS,CAAC,CAAC;MAC/B,MAAMK,IAAI,CAACF,UAAU,EAAEC,MAAM,EAAE,CAAC,EAAEP,UAAU,EAAEX,UAAU,EAAEC,MAAM,EAAEI,OAAO,CAAC;IAC5E;EACF,CAAC,CAAC;EAEF,OAAO,IAAIe,QAAQ,CAACL,cAAc,CAAC;AACrC;AAKA,eAAeI,IAAIA,CAACF,UAAU,EAAEC,MAAM,EAAEG,WAAW,EAAEV,UAAU,EAAEX,UAAU,EAAEC,MAAM,EAAEI,OAAO,EAAE;EAC5F,IAAI;IACF,MAAM;MAACiB,IAAI;MAAEC;IAAK,CAAC,GAAG,MAAML,MAAM,CAACC,IAAI,CAAC,CAAC;IACzC,IAAIG,IAAI,EAAE;MACRrB,MAAM,CAAC,CAAC;MACRgB,UAAU,CAACO,KAAK,CAAC,CAAC;MAClB;IACF;IACAH,WAAW,IAAIE,KAAK,CAACE,UAAU;IAC/B,MAAMC,OAAO,GAAGC,IAAI,CAACC,KAAK,CAAEP,WAAW,GAAGV,UAAU,GAAI,GAAG,CAAC;IAC5DX,UAAU,CAAC0B,OAAO,EAAE;MAACL,WAAW;MAAEV;IAAU,CAAC,CAAC;IAC9CM,UAAU,CAACY,OAAO,CAACN,KAAK,CAAC;IACzB,MAAMJ,IAAI,CAACF,UAAU,EAAEC,MAAM,EAAEG,WAAW,EAAEV,UAAU,EAAEX,UAAU,EAAEC,MAAM,EAAEI,OAAO,CAAC;EACtF,CAAC,CAAC,OAAOyB,KAAK,EAAE;IACdb,UAAU,CAACa,KAAK,CAACA,KAAK,CAAC;IACvBzB,OAAO,CAACyB,KAAK,CAAC;EAChB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","names":["_log","require","log","Log","id","exports"],"sources":["../../../../src/lib/utils/log.ts"],"sourcesContent":["// loaders.gl, MIT license\nimport {Log} from '@probe.gl/log';\n\nexport const log = new Log({id: 'loaders.gl'});\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,OAAA;AAEO,
|
|
1
|
+
{"version":3,"file":"log.js","names":["_log","require","log","Log","id","exports"],"sources":["../../../../src/lib/utils/log.ts"],"sourcesContent":["// loaders.gl, MIT license\nimport {Log} from '@probe.gl/log';\n\nexport const log = new Log({id: 'loaders.gl'});\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,OAAA;AAEO,MAAMC,GAAG,GAAG,IAAIC,QAAG,CAAC;EAACC,EAAE,EAAE;AAAY,CAAC,CAAC;AAACC,OAAA,CAAAH,GAAA,GAAAA,GAAA"}
|
|
@@ -5,17 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.parseMIMEType = parseMIMEType;
|
|
7
7
|
exports.parseMIMETypeFromURL = parseMIMETypeFromURL;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
|
|
9
|
+
const MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
|
|
10
10
|
function parseMIMEType(mimeString) {
|
|
11
|
-
|
|
11
|
+
const matches = MIME_TYPE_PATTERN.exec(mimeString);
|
|
12
12
|
if (matches) {
|
|
13
13
|
return matches[1];
|
|
14
14
|
}
|
|
15
15
|
return mimeString;
|
|
16
16
|
}
|
|
17
17
|
function parseMIMETypeFromURL(url) {
|
|
18
|
-
|
|
18
|
+
const matches = DATA_URL_PATTERN.exec(url);
|
|
19
19
|
if (matches) {
|
|
20
20
|
return matches[1];
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mime-type-utils.js","names":["DATA_URL_PATTERN","MIME_TYPE_PATTERN","parseMIMEType","mimeString","matches","exec","parseMIMETypeFromURL","url"],"sources":["../../../../src/lib/utils/mime-type-utils.ts"],"sourcesContent":["// TODO - build/integrate proper MIME type parsing\n// https://mimesniff.spec.whatwg.org/\n\nconst DATA_URL_PATTERN = /^data:([-\\w.]+\\/[-\\w.+]+)(;|,)/;\nconst MIME_TYPE_PATTERN = /^([-\\w.]+\\/[-\\w.+]+)/;\n\n/**\n * Remove extra data like `charset` from MIME types\n * @param mimeString\n * @returns A clean MIME type, or an empty string\n *\n * @todo - handle more advanced MIMETYpes, multiple types\n * @todo - extract charset etc\n */\nexport function parseMIMEType(mimeString: string): string {\n // If resource is a data url, extract any embedded mime type\n const matches = MIME_TYPE_PATTERN.exec(mimeString);\n if (matches) {\n return matches[1];\n }\n return mimeString;\n}\n\n/**\n * Extract MIME type from data URL\n *\n * @param mimeString\n * @returns A clean MIME type, or an empty string\n *\n * @todo - handle more advanced MIMETYpes, multiple types\n * @todo - extract charset etc\n */\nexport function parseMIMETypeFromURL(url: string): string {\n // If resource is a data URL, extract any embedded mime type\n const matches = DATA_URL_PATTERN.exec(url);\n if (matches) {\n return matches[1];\n }\n return '';\n}\n"],"mappings":";;;;;;;AAGA,
|
|
1
|
+
{"version":3,"file":"mime-type-utils.js","names":["DATA_URL_PATTERN","MIME_TYPE_PATTERN","parseMIMEType","mimeString","matches","exec","parseMIMETypeFromURL","url"],"sources":["../../../../src/lib/utils/mime-type-utils.ts"],"sourcesContent":["// TODO - build/integrate proper MIME type parsing\n// https://mimesniff.spec.whatwg.org/\n\nconst DATA_URL_PATTERN = /^data:([-\\w.]+\\/[-\\w.+]+)(;|,)/;\nconst MIME_TYPE_PATTERN = /^([-\\w.]+\\/[-\\w.+]+)/;\n\n/**\n * Remove extra data like `charset` from MIME types\n * @param mimeString\n * @returns A clean MIME type, or an empty string\n *\n * @todo - handle more advanced MIMETYpes, multiple types\n * @todo - extract charset etc\n */\nexport function parseMIMEType(mimeString: string): string {\n // If resource is a data url, extract any embedded mime type\n const matches = MIME_TYPE_PATTERN.exec(mimeString);\n if (matches) {\n return matches[1];\n }\n return mimeString;\n}\n\n/**\n * Extract MIME type from data URL\n *\n * @param mimeString\n * @returns A clean MIME type, or an empty string\n *\n * @todo - handle more advanced MIMETYpes, multiple types\n * @todo - extract charset etc\n */\nexport function parseMIMETypeFromURL(url: string): string {\n // If resource is a data URL, extract any embedded mime type\n const matches = DATA_URL_PATTERN.exec(url);\n if (matches) {\n return matches[1];\n }\n return '';\n}\n"],"mappings":";;;;;;;AAGA,MAAMA,gBAAgB,GAAG,gCAAgC;AACzD,MAAMC,iBAAiB,GAAG,sBAAsB;AAUzC,SAASC,aAAaA,CAACC,UAAkB,EAAU;EAExD,MAAMC,OAAO,GAAGH,iBAAiB,CAACI,IAAI,CAACF,UAAU,CAAC;EAClD,IAAIC,OAAO,EAAE;IACX,OAAOA,OAAO,CAAC,CAAC,CAAC;EACnB;EACA,OAAOD,UAAU;AACnB;AAWO,SAASG,oBAAoBA,CAACC,GAAW,EAAU;EAExD,MAAMH,OAAO,GAAGJ,gBAAgB,CAACK,IAAI,CAACE,GAAG,CAAC;EAC1C,IAAIH,OAAO,EAAE;IACX,OAAOA,OAAO,CAAC,CAAC,CAAC;EACnB;EACA,OAAO,EAAE;AACX"}
|
|
@@ -11,11 +11,11 @@ var _mimeTypeUtils = require("./mime-type-utils");
|
|
|
11
11
|
var _urlUtils = require("./url-utils");
|
|
12
12
|
function getResourceUrl(resource) {
|
|
13
13
|
if ((0, _isType.isResponse)(resource)) {
|
|
14
|
-
|
|
14
|
+
const response = resource;
|
|
15
15
|
return response.url;
|
|
16
16
|
}
|
|
17
17
|
if ((0, _isType.isBlob)(resource)) {
|
|
18
|
-
|
|
18
|
+
const blob = resource;
|
|
19
19
|
return blob.name || '';
|
|
20
20
|
}
|
|
21
21
|
if (typeof resource === 'string') {
|
|
@@ -25,13 +25,13 @@ function getResourceUrl(resource) {
|
|
|
25
25
|
}
|
|
26
26
|
function getResourceMIMEType(resource) {
|
|
27
27
|
if ((0, _isType.isResponse)(resource)) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const response = resource;
|
|
29
|
+
const contentTypeHeader = response.headers.get('content-type') || '';
|
|
30
|
+
const noQueryUrl = (0, _urlUtils.stripQueryString)(response.url);
|
|
31
31
|
return (0, _mimeTypeUtils.parseMIMEType)(contentTypeHeader) || (0, _mimeTypeUtils.parseMIMETypeFromURL)(noQueryUrl);
|
|
32
32
|
}
|
|
33
33
|
if ((0, _isType.isBlob)(resource)) {
|
|
34
|
-
|
|
34
|
+
const blob = resource;
|
|
35
35
|
return blob.type || '';
|
|
36
36
|
}
|
|
37
37
|
if (typeof resource === 'string') {
|
|
@@ -41,11 +41,11 @@ function getResourceMIMEType(resource) {
|
|
|
41
41
|
}
|
|
42
42
|
function getResourceContentLength(resource) {
|
|
43
43
|
if ((0, _isType.isResponse)(resource)) {
|
|
44
|
-
|
|
44
|
+
const response = resource;
|
|
45
45
|
return response.headers['content-length'] || -1;
|
|
46
46
|
}
|
|
47
47
|
if ((0, _isType.isBlob)(resource)) {
|
|
48
|
-
|
|
48
|
+
const blob = resource;
|
|
49
49
|
return blob.size;
|
|
50
50
|
}
|
|
51
51
|
if (typeof resource === 'string') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-utils.js","names":["_isType","require","_mimeTypeUtils","_urlUtils","getResourceUrl","resource","isResponse","response","url","isBlob","blob","name","getResourceMIMEType","contentTypeHeader","headers","get","noQueryUrl","stripQueryString","parseMIMEType","parseMIMETypeFromURL","type","getResourceContentLength","size","length","ArrayBuffer","byteLength","isView"],"sources":["../../../../src/lib/utils/resource-utils.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {isResponse, isBlob} from '../../javascript-utils/is-type';\nimport {parseMIMEType, parseMIMETypeFromURL} from './mime-type-utils';\nimport {stripQueryString} from './url-utils';\n\n/**\n * A loadable resource. Includes:\n * `Response`, `Blob` (`File` is a subclass), string URLs and data URLs\n */\nexport type Resource = Response | Blob | string;\n\n/**\n * Returns the URL associated with this resource.\n * The returned value may include a query string and need further processing.\n * If it cannot determine url, the corresponding value will be an empty string\n *\n * @todo string parameters are assumed to be URLs\n */\nexport function getResourceUrl(resource: unknown): string {\n // If resource is a `Response`, it contains the information directly as a field\n if (isResponse(resource)) {\n const response = resource as Response;\n return response.url;\n }\n\n // If the resource is a Blob or a File (subclass of Blob)\n if (isBlob(resource)) {\n const blob = resource as Blob;\n // File objects have a \"name\" property. Blob objects don't have any\n // url (name) information\n return blob.name || '';\n }\n\n if (typeof resource === 'string') {\n return resource;\n }\n\n // Unknown\n return '';\n}\n\n/**\n * Returns the URL associated with this resource.\n * The returned value may include a query string and need further processing.\n * If it cannot determine url, the corresponding value will be an empty string\n *\n * @todo string parameters are assumed to be URLs\n */\nexport function getResourceMIMEType(resource: unknown): string {\n // If resource is a response, it contains the information directly\n if (isResponse(resource)) {\n const response = resource as Response;\n const contentTypeHeader = response.headers.get('content-type') || '';\n const noQueryUrl = stripQueryString(response.url);\n return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);\n }\n\n // If the resource is a Blob or a File (subclass of Blob)\n if (isBlob(resource)) {\n const blob = resource as Blob;\n return blob.type || '';\n }\n\n if (typeof resource === 'string') {\n return parseMIMETypeFromURL(resource);\n }\n\n // Unknown\n return '';\n}\n\n/**\n * Returns (approximate) content length for a resource if it can be determined.\n * Returns -1 if content length cannot be determined.\n * @param resource\n\n * @note string parameters are NOT assumed to be URLs\n */\nexport function getResourceContentLength(resource: unknown): number {\n if (isResponse(resource)) {\n const response = resource as Response;\n return response.headers['content-length'] || -1;\n }\n if (isBlob(resource)) {\n const blob = resource as Blob;\n return blob.size;\n }\n if (typeof resource === 'string') {\n // TODO - handle data URL?\n return resource.length;\n }\n if (resource instanceof ArrayBuffer) {\n return resource.byteLength;\n }\n if (ArrayBuffer.isView(resource)) {\n return resource.byteLength;\n }\n return -1;\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAeO,SAASG,cAAcA,CAACC,QAAiB,EAAU;EAExD,IAAI,IAAAC,kBAAU,EAACD,QAAQ,CAAC,EAAE;IACxB,
|
|
1
|
+
{"version":3,"file":"resource-utils.js","names":["_isType","require","_mimeTypeUtils","_urlUtils","getResourceUrl","resource","isResponse","response","url","isBlob","blob","name","getResourceMIMEType","contentTypeHeader","headers","get","noQueryUrl","stripQueryString","parseMIMEType","parseMIMETypeFromURL","type","getResourceContentLength","size","length","ArrayBuffer","byteLength","isView"],"sources":["../../../../src/lib/utils/resource-utils.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {isResponse, isBlob} from '../../javascript-utils/is-type';\nimport {parseMIMEType, parseMIMETypeFromURL} from './mime-type-utils';\nimport {stripQueryString} from './url-utils';\n\n/**\n * A loadable resource. Includes:\n * `Response`, `Blob` (`File` is a subclass), string URLs and data URLs\n */\nexport type Resource = Response | Blob | string;\n\n/**\n * Returns the URL associated with this resource.\n * The returned value may include a query string and need further processing.\n * If it cannot determine url, the corresponding value will be an empty string\n *\n * @todo string parameters are assumed to be URLs\n */\nexport function getResourceUrl(resource: unknown): string {\n // If resource is a `Response`, it contains the information directly as a field\n if (isResponse(resource)) {\n const response = resource as Response;\n return response.url;\n }\n\n // If the resource is a Blob or a File (subclass of Blob)\n if (isBlob(resource)) {\n const blob = resource as Blob;\n // File objects have a \"name\" property. Blob objects don't have any\n // url (name) information\n return blob.name || '';\n }\n\n if (typeof resource === 'string') {\n return resource;\n }\n\n // Unknown\n return '';\n}\n\n/**\n * Returns the URL associated with this resource.\n * The returned value may include a query string and need further processing.\n * If it cannot determine url, the corresponding value will be an empty string\n *\n * @todo string parameters are assumed to be URLs\n */\nexport function getResourceMIMEType(resource: unknown): string {\n // If resource is a response, it contains the information directly\n if (isResponse(resource)) {\n const response = resource as Response;\n const contentTypeHeader = response.headers.get('content-type') || '';\n const noQueryUrl = stripQueryString(response.url);\n return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);\n }\n\n // If the resource is a Blob or a File (subclass of Blob)\n if (isBlob(resource)) {\n const blob = resource as Blob;\n return blob.type || '';\n }\n\n if (typeof resource === 'string') {\n return parseMIMETypeFromURL(resource);\n }\n\n // Unknown\n return '';\n}\n\n/**\n * Returns (approximate) content length for a resource if it can be determined.\n * Returns -1 if content length cannot be determined.\n * @param resource\n\n * @note string parameters are NOT assumed to be URLs\n */\nexport function getResourceContentLength(resource: unknown): number {\n if (isResponse(resource)) {\n const response = resource as Response;\n return response.headers['content-length'] || -1;\n }\n if (isBlob(resource)) {\n const blob = resource as Blob;\n return blob.size;\n }\n if (typeof resource === 'string') {\n // TODO - handle data URL?\n return resource.length;\n }\n if (resource instanceof ArrayBuffer) {\n return resource.byteLength;\n }\n if (ArrayBuffer.isView(resource)) {\n return resource.byteLength;\n }\n return -1;\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAeO,SAASG,cAAcA,CAACC,QAAiB,EAAU;EAExD,IAAI,IAAAC,kBAAU,EAACD,QAAQ,CAAC,EAAE;IACxB,MAAME,QAAQ,GAAGF,QAAoB;IACrC,OAAOE,QAAQ,CAACC,GAAG;EACrB;EAGA,IAAI,IAAAC,cAAM,EAACJ,QAAQ,CAAC,EAAE;IACpB,MAAMK,IAAI,GAAGL,QAAgB;IAG7B,OAAOK,IAAI,CAACC,IAAI,IAAI,EAAE;EACxB;EAEA,IAAI,OAAON,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAOA,QAAQ;EACjB;EAGA,OAAO,EAAE;AACX;AASO,SAASO,mBAAmBA,CAACP,QAAiB,EAAU;EAE7D,IAAI,IAAAC,kBAAU,EAACD,QAAQ,CAAC,EAAE;IACxB,MAAME,QAAQ,GAAGF,QAAoB;IACrC,MAAMQ,iBAAiB,GAAGN,QAAQ,CAACO,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE;IACpE,MAAMC,UAAU,GAAG,IAAAC,0BAAgB,EAACV,QAAQ,CAACC,GAAG,CAAC;IACjD,OAAO,IAAAU,4BAAa,EAACL,iBAAiB,CAAC,IAAI,IAAAM,mCAAoB,EAACH,UAAU,CAAC;EAC7E;EAGA,IAAI,IAAAP,cAAM,EAACJ,QAAQ,CAAC,EAAE;IACpB,MAAMK,IAAI,GAAGL,QAAgB;IAC7B,OAAOK,IAAI,CAACU,IAAI,IAAI,EAAE;EACxB;EAEA,IAAI,OAAOf,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAO,IAAAc,mCAAoB,EAACd,QAAQ,CAAC;EACvC;EAGA,OAAO,EAAE;AACX;AASO,SAASgB,wBAAwBA,CAAChB,QAAiB,EAAU;EAClE,IAAI,IAAAC,kBAAU,EAACD,QAAQ,CAAC,EAAE;IACxB,MAAME,QAAQ,GAAGF,QAAoB;IACrC,OAAOE,QAAQ,CAACO,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;EACjD;EACA,IAAI,IAAAL,cAAM,EAACJ,QAAQ,CAAC,EAAE;IACpB,MAAMK,IAAI,GAAGL,QAAgB;IAC7B,OAAOK,IAAI,CAACY,IAAI;EAClB;EACA,IAAI,OAAOjB,QAAQ,KAAK,QAAQ,EAAE;IAEhC,OAAOA,QAAQ,CAACkB,MAAM;EACxB;EACA,IAAIlB,QAAQ,YAAYmB,WAAW,EAAE;IACnC,OAAOnB,QAAQ,CAACoB,UAAU;EAC5B;EACA,IAAID,WAAW,CAACE,MAAM,CAACrB,QAAQ,CAAC,EAAE;IAChC,OAAOA,QAAQ,CAACoB,UAAU;EAC5B;EACA,OAAO,CAAC,CAAC;AACX"}
|
|
@@ -1,195 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.checkResponse = checkResponse;
|
|
8
7
|
exports.checkResponseSync = checkResponseSync;
|
|
9
8
|
exports.makeResponse = makeResponse;
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
9
|
var _isType = require("../../javascript-utils/is-type");
|
|
13
10
|
var _resourceUtils = require("./resource-utils");
|
|
14
|
-
function makeResponse(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
initialDataUrl = _context.sent;
|
|
43
|
-
if (initialDataUrl) {
|
|
44
|
-
headers['x-first-bytes'] = initialDataUrl;
|
|
45
|
-
}
|
|
46
|
-
if (typeof resource === 'string') {
|
|
47
|
-
resource = new TextEncoder().encode(resource);
|
|
48
|
-
}
|
|
49
|
-
response = new Response(resource, {
|
|
50
|
-
headers: headers
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(response, 'url', {
|
|
53
|
-
value: url
|
|
54
|
-
});
|
|
55
|
-
return _context.abrupt("return", response);
|
|
56
|
-
case 16:
|
|
57
|
-
case "end":
|
|
58
|
-
return _context.stop();
|
|
59
|
-
}
|
|
60
|
-
}, _callee);
|
|
61
|
-
}));
|
|
62
|
-
return _makeResponse.apply(this, arguments);
|
|
63
|
-
}
|
|
64
|
-
function checkResponse(_x2) {
|
|
65
|
-
return _checkResponse.apply(this, arguments);
|
|
11
|
+
async function makeResponse(resource) {
|
|
12
|
+
if ((0, _isType.isResponse)(resource)) {
|
|
13
|
+
return resource;
|
|
14
|
+
}
|
|
15
|
+
const headers = {};
|
|
16
|
+
const contentLength = (0, _resourceUtils.getResourceContentLength)(resource);
|
|
17
|
+
if (contentLength >= 0) {
|
|
18
|
+
headers['content-length'] = String(contentLength);
|
|
19
|
+
}
|
|
20
|
+
const url = (0, _resourceUtils.getResourceUrl)(resource);
|
|
21
|
+
const type = (0, _resourceUtils.getResourceMIMEType)(resource);
|
|
22
|
+
if (type) {
|
|
23
|
+
headers['content-type'] = type;
|
|
24
|
+
}
|
|
25
|
+
const initialDataUrl = await getInitialDataUrl(resource);
|
|
26
|
+
if (initialDataUrl) {
|
|
27
|
+
headers['x-first-bytes'] = initialDataUrl;
|
|
28
|
+
}
|
|
29
|
+
if (typeof resource === 'string') {
|
|
30
|
+
resource = new TextEncoder().encode(resource);
|
|
31
|
+
}
|
|
32
|
+
const response = new Response(resource, {
|
|
33
|
+
headers
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(response, 'url', {
|
|
36
|
+
value: url
|
|
37
|
+
});
|
|
38
|
+
return response;
|
|
66
39
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
case 0:
|
|
73
|
-
if (response.ok) {
|
|
74
|
-
_context2.next = 5;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
_context2.next = 3;
|
|
78
|
-
return getResponseError(response);
|
|
79
|
-
case 3:
|
|
80
|
-
message = _context2.sent;
|
|
81
|
-
throw new Error(message);
|
|
82
|
-
case 5:
|
|
83
|
-
case "end":
|
|
84
|
-
return _context2.stop();
|
|
85
|
-
}
|
|
86
|
-
}, _callee2);
|
|
87
|
-
}));
|
|
88
|
-
return _checkResponse.apply(this, arguments);
|
|
40
|
+
async function checkResponse(response) {
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
const message = await getResponseError(response);
|
|
43
|
+
throw new Error(message);
|
|
44
|
+
}
|
|
89
45
|
}
|
|
90
46
|
function checkResponseSync(response) {
|
|
91
47
|
if (!response.ok) {
|
|
92
|
-
|
|
48
|
+
let message = "".concat(response.status, " ").concat(response.statusText);
|
|
93
49
|
message = message.length > 60 ? "".concat(message.slice(0, 60), "...") : message;
|
|
94
50
|
throw new Error(message);
|
|
95
51
|
}
|
|
96
52
|
}
|
|
97
|
-
function getResponseError(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
text = response.statusText;
|
|
110
|
-
if (!contentType.includes('application/json')) {
|
|
111
|
-
_context3.next = 11;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
_context3.t0 = text;
|
|
115
|
-
_context3.t1 = " ";
|
|
116
|
-
_context3.next = 9;
|
|
117
|
-
return response.text();
|
|
118
|
-
case 9:
|
|
119
|
-
_context3.t2 = _context3.sent;
|
|
120
|
-
text = _context3.t0 += _context3.t1.concat.call(_context3.t1, _context3.t2);
|
|
121
|
-
case 11:
|
|
122
|
-
message += text;
|
|
123
|
-
message = message.length > 60 ? "".concat(message.slice(0, 60), "...") : message;
|
|
124
|
-
_context3.next = 17;
|
|
125
|
-
break;
|
|
126
|
-
case 15:
|
|
127
|
-
_context3.prev = 15;
|
|
128
|
-
_context3.t3 = _context3["catch"](1);
|
|
129
|
-
case 17:
|
|
130
|
-
return _context3.abrupt("return", message);
|
|
131
|
-
case 18:
|
|
132
|
-
case "end":
|
|
133
|
-
return _context3.stop();
|
|
134
|
-
}
|
|
135
|
-
}, _callee3, null, [[1, 15]]);
|
|
136
|
-
}));
|
|
137
|
-
return _getResponseError.apply(this, arguments);
|
|
138
|
-
}
|
|
139
|
-
function getInitialDataUrl(_x4) {
|
|
140
|
-
return _getInitialDataUrl.apply(this, arguments);
|
|
53
|
+
async function getResponseError(response) {
|
|
54
|
+
let message = "Failed to fetch resource ".concat(response.url, " (").concat(response.status, "): ");
|
|
55
|
+
try {
|
|
56
|
+
const contentType = response.headers.get('Content-Type');
|
|
57
|
+
let text = response.statusText;
|
|
58
|
+
if (contentType.includes('application/json')) {
|
|
59
|
+
text += " ".concat(await response.text());
|
|
60
|
+
}
|
|
61
|
+
message += text;
|
|
62
|
+
message = message.length > 60 ? "".concat(message.slice(0, 60), "...") : message;
|
|
63
|
+
} catch (error) {}
|
|
64
|
+
return message;
|
|
141
65
|
}
|
|
142
|
-
function
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
var _event$target;
|
|
165
|
-
return resolve(event === null || event === void 0 ? void 0 : (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result);
|
|
166
|
-
};
|
|
167
|
-
reader.readAsDataURL(blobSlice);
|
|
168
|
-
});
|
|
169
|
-
case 7:
|
|
170
|
-
return _context4.abrupt("return", _context4.sent);
|
|
171
|
-
case 8:
|
|
172
|
-
if (!(resource instanceof ArrayBuffer)) {
|
|
173
|
-
_context4.next = 12;
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
slice = resource.slice(0, INITIAL_DATA_LENGTH);
|
|
177
|
-
base64 = arrayBufferToBase64(slice);
|
|
178
|
-
return _context4.abrupt("return", "data:base64,".concat(base64));
|
|
179
|
-
case 12:
|
|
180
|
-
return _context4.abrupt("return", null);
|
|
181
|
-
case 13:
|
|
182
|
-
case "end":
|
|
183
|
-
return _context4.stop();
|
|
184
|
-
}
|
|
185
|
-
}, _callee4);
|
|
186
|
-
}));
|
|
187
|
-
return _getInitialDataUrl.apply(this, arguments);
|
|
66
|
+
async function getInitialDataUrl(resource) {
|
|
67
|
+
const INITIAL_DATA_LENGTH = 5;
|
|
68
|
+
if (typeof resource === 'string') {
|
|
69
|
+
return "data:,".concat(resource.slice(0, INITIAL_DATA_LENGTH));
|
|
70
|
+
}
|
|
71
|
+
if (resource instanceof Blob) {
|
|
72
|
+
const blobSlice = resource.slice(0, 5);
|
|
73
|
+
return await new Promise(resolve => {
|
|
74
|
+
const reader = new FileReader();
|
|
75
|
+
reader.onload = event => {
|
|
76
|
+
var _event$target;
|
|
77
|
+
return resolve(event === null || event === void 0 ? void 0 : (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result);
|
|
78
|
+
};
|
|
79
|
+
reader.readAsDataURL(blobSlice);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (resource instanceof ArrayBuffer) {
|
|
83
|
+
const slice = resource.slice(0, INITIAL_DATA_LENGTH);
|
|
84
|
+
const base64 = arrayBufferToBase64(slice);
|
|
85
|
+
return "data:base64,".concat(base64);
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
188
88
|
}
|
|
189
89
|
function arrayBufferToBase64(buffer) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
for (
|
|
90
|
+
let binary = '';
|
|
91
|
+
const bytes = new Uint8Array(buffer);
|
|
92
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
193
93
|
binary += String.fromCharCode(bytes[i]);
|
|
194
94
|
}
|
|
195
95
|
return btoa(binary);
|