mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
Merge pull request #17328 from Snuffleupagus/fetchData-blob
Use the `fetchData` helper function in more cases
This commit is contained in:
commit
3d9f68cb97
3 changed files with 19 additions and 16 deletions
|
@ -399,6 +399,8 @@ async function fetchData(url, type = "text") {
|
|||
switch (type) {
|
||||
case "arraybuffer":
|
||||
return response.arrayBuffer();
|
||||
case "blob":
|
||||
return response.blob();
|
||||
case "json":
|
||||
return response.json();
|
||||
}
|
||||
|
@ -419,6 +421,7 @@ async function fetchData(url, type = "text") {
|
|||
let data;
|
||||
switch (type) {
|
||||
case "arraybuffer":
|
||||
case "blob":
|
||||
case "json":
|
||||
data = request.response;
|
||||
break;
|
||||
|
|
|
@ -27,7 +27,12 @@ import {
|
|||
Util,
|
||||
warn,
|
||||
} from "../../shared/util.js";
|
||||
import { getColorValues, getRGB, PixelsPerInch } from "../display_utils.js";
|
||||
import {
|
||||
fetchData,
|
||||
getColorValues,
|
||||
getRGB,
|
||||
PixelsPerInch,
|
||||
} from "../display_utils.js";
|
||||
|
||||
function bindEvents(obj, element, names) {
|
||||
for (const name of names) {
|
||||
|
@ -116,12 +121,7 @@ class ImageManager {
|
|||
let image;
|
||||
if (typeof rawData === "string") {
|
||||
data.url = rawData;
|
||||
|
||||
const response = await fetch(rawData);
|
||||
if (!response.ok) {
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
image = await response.blob();
|
||||
image = await fetchData(rawData, "blob");
|
||||
} else {
|
||||
image = data.file = rawData;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue