Skip to content

Commit

Permalink
Merge pull request #17328 from Snuffleupagus/fetchData-blob
Browse files Browse the repository at this point in the history
Use the `fetchData` helper function in more cases
  • Loading branch information
Snuffleupagus authored Nov 25, 2023
2 parents 5831636 + fd7a7e2 commit 3d9f68c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -419,6 +421,7 @@ async function fetchData(url, type = "text") {
let data;
switch (type) {
case "arraybuffer":
case "blob":
case "json":
data = request.response;
break;
Expand Down
14 changes: 7 additions & 7 deletions src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 9 additions & 9 deletions web/l10n_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

/** @typedef {import("./interfaces").IL10n} IL10n */

import { fetchData, shadow } from "pdfjs-lib";
import { FluentBundle, FluentResource } from "fluent-bundle";
import { DOMLocalization } from "fluent-dom";
import { L10n } from "./l10n.js";
import { shadow } from "pdfjs-lib";

/**
* @implements {IL10n}
Expand All @@ -32,14 +32,14 @@ class ConstL10n extends L10n {
}

static async *#generateBundles(lang) {
let text;
if (typeof PDFJSDev === "undefined") {
const url = new URL(`./locale/${lang}/viewer.ftl`, window.location.href);
const data = await fetch(url);
text = await data.text();
} else {
text = PDFJSDev.eval("DEFAULT_FTL");
}
const text =
typeof PDFJSDev === "undefined"
? await fetchData(
new URL(`./locale/${lang}/viewer.ftl`, window.location.href),
/* type = */ "text"
)
: PDFJSDev.eval("DEFAULT_FTL");

const resource = new FluentResource(text);
const bundle = new FluentBundle(lang);
const errors = bundle.addResource(resource);
Expand Down

0 comments on commit 3d9f68c

Please sign in to comment.