Skip to content

Commit 449cc0e

Browse files
committed
fix: Ne pas télécharger les fichiers audio / vidéos.
1 parent 8a82ee6 commit 449cc0e

4 files changed

Lines changed: 32 additions & 9 deletions

File tree

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"clean": "rm -rf .nyc_output/ build/ coverage/ jsdocs/ node_modules/"
3838
},
3939
"devDependencies": {
40+
"abort-controller": "3.0.0",
4041
"addons-linter": "^1.22.0",
4142
"david": "^12.0.0",
4243
"eslint": "^6.8.0",

src/core/scrapers.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,19 @@ export const extract = async function (url, options) {
116116
const content = {
117117
html: cacheable(async () => {
118118
try {
119-
const response = await fetch(url.href);
119+
const controller = new AbortController();
120+
const response = await fetch(url.href, {
121+
signal: controller.signal,
122+
});
120123
const contentType = response.headers.get("Content-Type");
121124
if (null !== contentType &&
122125
(contentType.startsWith("text/html") ||
123126
contentType.startsWith("application/xhtml+xml"))) {
124127
const text = await response.text();
125128
return new DOMParser().parseFromString(text, "text/html");
126129
}
130+
// Si ce n'est pas du HTML : annuler la requête.
131+
controller.abort();
127132
} catch {
128133
// Ignorer le cas où l'URL n'est pas accessible.
129134
}

test/polyfill.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { URL } from "url";
2-
import { JSDOM } from "jsdom";
3-
import { browser } from "./polyfill/browser.js";
4-
import { fetch } from "./polyfill/fetch.js";
1+
import { URL } from "url";
2+
import AbortController from "abort-controller";
3+
import { JSDOM } from "jsdom";
4+
import { browser } from "./polyfill/browser.js";
5+
import { fetch } from "./polyfill/fetch.js";
56

6-
globalThis.URL = URL;
7-
globalThis.DOMParser = new JSDOM().window.DOMParser;
8-
globalThis.browser = browser;
9-
globalThis.fetch = fetch;
7+
globalThis.URL = URL;
8+
globalThis.AbortController = AbortController;
9+
globalThis.DOMParser = new JSDOM().window.DOMParser;
10+
globalThis.browser = browser;
11+
globalThis.fetch = fetch;

0 commit comments

Comments
 (0)