Skip to content

Commit af56a19

Browse files
committed
Use fetch to get images instead of axios (BL-14629)
1 parent b8e6e9c commit af56a19

File tree

3 files changed

+9
-54
lines changed

3 files changed

+9
-54
lines changed

package-lock.json

-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"//note: ts-node": "really is a runtime dependency",
2727
"dependencies": {
2828
"@notionhq/client": "2.2.3",
29-
"axios": "^1.6.8",
3029
"chalk": "^4.1.2",
3130
"commander": "^9.2.0",
3231
"cosmiconfig": "^8.0.0",

src/images.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fs from "fs-extra";
22
import FileType, { FileTypeResult } from "file-type";
3-
import axios from "axios";
43
import { makeImagePersistencePlan } from "./MakeImagePersistencePlan";
54
import { warning, logDebug, verbose, info } from "./log";
65
import { ListBlockChildrenResponseResult } from "notion-to-md/build/types";
@@ -150,10 +149,15 @@ async function processImageBlock(
150149
async function readPrimaryImage(imageSet: ImageSet) {
151150
// In Mar 2024, we started having a problem getting a particular gif from imgur using
152151
// node-fetch. Switching to axios resolved it. I don't know why.
153-
const response = await axios.get(imageSet.primaryUrl, {
154-
responseType: "arraybuffer",
155-
});
156-
imageSet.primaryBuffer = Buffer.from(response.data, "utf-8");
152+
// Then, in Apr 2025, we started getting 429 responses from imgur through axios,
153+
// so we switched to node's built-in fetch (different than the node-fetch package).
154+
// Just a guess, but probably imgur keeps locking down what it suspects as code running
155+
// to scrape images.
156+
// Apparently, imgur is getting to be more and more of a liability,
157+
// so we should probably stop using it.
158+
const response = await fetch(imageSet.primaryUrl);
159+
const arrayBuffer = await response.arrayBuffer();
160+
imageSet.primaryBuffer = Buffer.from(arrayBuffer);
157161
imageSet.fileType = await FileType.fromBuffer(imageSet.primaryBuffer);
158162
}
159163

0 commit comments

Comments
 (0)