Skip to content

Use fetch to get images instead of axios (BL-14629) #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"//note: ts-node": "really is a runtime dependency",
"dependencies": {
"@notionhq/client": "2.2.3",
"axios": "^1.6.8",
"chalk": "^4.1.2",
"commander": "^9.2.0",
"cosmiconfig": "^8.0.0",
Expand Down
14 changes: 9 additions & 5 deletions src/images.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from "fs-extra";
import FileType, { FileTypeResult } from "file-type";
import axios from "axios";
import { makeImagePersistencePlan } from "./MakeImagePersistencePlan";
import { warning, logDebug, verbose, info } from "./log";
import { ListBlockChildrenResponseResult } from "notion-to-md/build/types";
Expand Down Expand Up @@ -150,10 +149,15 @@ async function processImageBlock(
async function readPrimaryImage(imageSet: ImageSet) {
// In Mar 2024, we started having a problem getting a particular gif from imgur using
// node-fetch. Switching to axios resolved it. I don't know why.
const response = await axios.get(imageSet.primaryUrl, {
responseType: "arraybuffer",
});
imageSet.primaryBuffer = Buffer.from(response.data, "utf-8");
// Then, in Apr 2025, we started getting 429 responses from imgur through axios,
// so we switched to node's built-in fetch (different than the node-fetch package).
// Just a guess, but probably imgur keeps locking down what it suspects as code running
// to scrape images.
// Apparently, imgur is getting to be more and more of a liability,
// so we should probably stop using it.
const response = await fetch(imageSet.primaryUrl);
const arrayBuffer = await response.arrayBuffer();
imageSet.primaryBuffer = Buffer.from(arrayBuffer);
imageSet.fileType = await FileType.fromBuffer(imageSet.primaryBuffer);
}

Expand Down