Skip to content

Commit 5d00de3

Browse files
committed
fix: Download images using axios instead of node-fetch
1 parent 40c6bec commit 5d00de3

File tree

4 files changed

+77
-37
lines changed

4 files changed

+77
-37
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ node_modules/
66
version.json
77
docs/
88
*.orig
9+
10+
css/docu-notion-styles.css

package-lock.json

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

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,33 @@
1212
"tsc": "tsc",
1313
"// test out with a private sample notion db": "",
1414
"large-site-test": "npm run ts -- -n $SIL_BLOOM_DOCS_NOTION_TOKEN -r $SIL_BLOOM_DOCS_NOTION_ROOT_PAGE --locales en,fr --log-level debug",
15-
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
15+
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level info --status-tag test",
1616
"pull-test-css": "npm run ts -- --css-output-directory ./test/css -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
1717
"pull-sample-site": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE --log-level debug",
1818
"// test with a semi-stable/public site:": "",
1919
"pull-sample": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE -m ./sample --locales en,es,fr,de --log-level verbose",
2020
"pull-sample-with-paths": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE -m ./sample --img-output-path ./sample_img"
2121
},
2222
"//file-type": "have to use this version before they switched to ESM, which gives a compile error related to require()",
23-
"//[email protected]": "have to use this version before they switched to ESM, which gives a compile error related to require()",
2423
"//chalk@4": "also ESM related problem",
2524
"//notion-client@4": "also ESM related problem",
2625
"//note: ts-node": "really is a runtime dependency",
2726
"dependencies": {
2827
"@notionhq/client": "2.2.3",
28+
"axios": "^1.6.8",
2929
"chalk": "^4.1.2",
3030
"commander": "^9.2.0",
3131
"cosmiconfig": "^8.0.0",
3232
"cosmiconfig-typescript-loader": "^4.3.0",
33-
"file-type": "16.5.1",
33+
"file-type": "16.5.3",
3434
"fs-extra": "^10.1.0",
3535
"limiter": "^2.1.0",
3636
"markdown-table": "^2.0.0",
37-
"node-fetch": "2.6.6",
3837
"notion-client": "^4",
3938
"notion-to-md": "3.1.1",
4039
"path": "^0.12.7",
41-
"ts-node": "^10.2.1",
42-
"sanitize-filename": "^1.6.3"
40+
"sanitize-filename": "^1.6.3",
41+
"ts-node": "^10.2.1"
4342
},
4443
"devDependencies": {
4544
"@types/fs-extra": "^9.0.13",

src/images.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from "fs-extra";
22
import FileType, { FileTypeResult } from "file-type";
3-
import fetch from "node-fetch";
3+
import axios from "axios";
44
import * as Path from "path";
55
import { makeImagePersistencePlan } from "./MakeImagePersistencePlan";
66
import { warning, logDebug, verbose, info } from "./log";
@@ -150,9 +150,12 @@ async function processImageBlock(
150150
}
151151

152152
async function readPrimaryImage(imageSet: ImageSet) {
153-
const response = await fetch(imageSet.primaryUrl);
154-
const arrayBuffer = await response.arrayBuffer();
155-
imageSet.primaryBuffer = Buffer.from(arrayBuffer);
153+
// In Mar 2024, we started having a problem getting a particular gif from imgur using
154+
// node-fetch. Switching to axios resolved it. I don't know why.
155+
const response = await axios.get(imageSet.primaryUrl, {
156+
responseType: "arraybuffer",
157+
});
158+
imageSet.primaryBuffer = Buffer.from(response.data, "utf-8");
156159
imageSet.fileType = await FileType.fromBuffer(imageSet.primaryBuffer);
157160
}
158161

0 commit comments

Comments
 (0)