Skip to content

Commit

Permalink
fix: Download images using axios instead of node-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-polk committed Apr 2, 2024
1 parent 40c6bec commit 5d00de3
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules/
version.json
docs/
*.orig

css/docu-notion-styles.css
90 changes: 63 additions & 27 deletions package-lock.json

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

11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,33 @@
"tsc": "tsc",
"// test out with a private sample notion db": "",
"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",
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level info --status-tag test",
"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",
"pull-sample-site": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE --log-level debug",
"// test with a semi-stable/public site:": "",
"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",
"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"
},
"//file-type": "have to use this version before they switched to ESM, which gives a compile error related to require()",
"//[email protected]": "have to use this version before they switched to ESM, which gives a compile error related to require()",
"//chalk@4": "also ESM related problem",
"//notion-client@4": "also ESM related problem",
"//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",
"cosmiconfig-typescript-loader": "^4.3.0",
"file-type": "16.5.1",
"file-type": "16.5.3",
"fs-extra": "^10.1.0",
"limiter": "^2.1.0",
"markdown-table": "^2.0.0",
"node-fetch": "2.6.6",
"notion-client": "^4",
"notion-to-md": "3.1.1",
"path": "^0.12.7",
"ts-node": "^10.2.1",
"sanitize-filename": "^1.6.3"
"sanitize-filename": "^1.6.3",
"ts-node": "^10.2.1"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
Expand Down
11 changes: 7 additions & 4 deletions src/images.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "fs-extra";
import FileType, { FileTypeResult } from "file-type";
import fetch from "node-fetch";
import axios from "axios";
import * as Path from "path";
import { makeImagePersistencePlan } from "./MakeImagePersistencePlan";
import { warning, logDebug, verbose, info } from "./log";
Expand Down Expand Up @@ -150,9 +150,12 @@ async function processImageBlock(
}

async function readPrimaryImage(imageSet: ImageSet) {
const response = await fetch(imageSet.primaryUrl);
const arrayBuffer = await response.arrayBuffer();
imageSet.primaryBuffer = Buffer.from(arrayBuffer);
// 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");
imageSet.fileType = await FileType.fromBuffer(imageSet.primaryBuffer);
}

Expand Down

0 comments on commit 5d00de3

Please sign in to comment.