subhamX / notion-easy-export

πŸ“˜ Notion easy export converts your notion documents & databases into an ebook.
https://www.npmjs.com/package/notion-easy-export
Apache License 2.0
62 stars 4 forks source link

No longer works? #5

Closed jtomaszewski closed 1 year ago

jtomaszewski commented 1 year ago

I've followed readme and here's the result I receive:

$ node index.js
info: wkhtmltopdf is installed and in PATH. πŸ₯³πŸ₯³
info: Starting current session...
info: Removing all files in session Files Dir!!!
info: Creating directories in session Files Dir!!!
info: Starting Html Export Subroutine
error: main: Error: Something went wrong! Couldn't get the taskId.

I tried changing the corresponding line for returning the error to throw Error(Something went wrong! Couldn't get the taskId. Result from notion: ${JSON.stringify(res)});

and then I receive this:

...
error: main: Error: Something went wrong! Couldn't get the taskId. Result from notion: {"message":"Something went wrong."}

Seems like something happened with the https://www.notion.so/api/v3/enqueueTask endpoint?

It seems to be private API replicating their Export functionality? So I looked up how it works currently in the browser and the payload looks like this:

image

So then I changed the notion_api_utils.js source code to make the payload resemble it more:

image

But then I get following output:

image

So I look up the files in session_files and I only see tmp/data.zip which is actually a HTML page showing Access denied! error:

image

Does it seem like they have blocked the endpoint, at least to non-enterprise users?

Well, I checked it again manually, and they didn't. I've managed to download the file myself by repeating all the requests from the Notion tab in Chrome browser.

So perhaps there's something else that has changed, maybe the request to download the file has different authorization or URL or something.

Anyways, here's where my investigation has stopped for now; just informing the others for now.

subhamX commented 1 year ago

Thank you @jtomaszewski for sharing it. Earlier they weren't expecting spaceId in /api/v3/enqueueTask, but now they do. Fixing it by providing this additional param.

subhamX commented 1 year ago

Idk, for some reasons I'm unable to publish to npm. Shall look at the issue after sometime.

furqansafdar commented 1 year ago

Even after fixing the spaceId thing, it is still not working, The zip file downloading is failing at my end.

info: wkhtmltopdf is installed and in PATH. πŸ₯³πŸ₯³
info: Starting current session...
info: Removing all files in session Files Dir!!!
info: Creating directories in session Files Dir!!!
info: Starting Html Export Subroutine
Process Completed!
info: Task Id: 26eb46e4-54f6-4f48-bc17-09b0618a59a0
info: Current Task status: success
info: Got the S3 download URL
info: Starting file download
info: File download successful
info: Removing all non dot files and folders from D:\notion-to-ebook\session_files\input
info: Files removal success
info: Starting file extraction
error: main: Error: end of central directory record signature not found
subhamX commented 1 year ago

Ok. I should've been more thorough. Actually you need to get the file_token from one of the endpoint too. (The merged CR referenced above includes this thing too).

I recently performed a run (using the code in master branch) and it ran fine: (Do note that this is v1.0.4 currently not published to npm. I've reached out the support, and hopefully I should be able to publish this new version very soon). 🀞

subhmx@bcd0741610ce notion-to-ebook % NTEB_pageId='920be5e64bd04f34b3c4450ad3fcc80e' npm run test

> @subhamx/notion-to-ebook@1.0.4 test
> node lib/tests/index.js

Testing standalone doc generation
info: wkhtmltopdf is installed and in PATH. πŸ₯³πŸ₯³
info: Starting current session...
info: Removing all files in session Files Dir!!!
info: Creating directories in session Files Dir!!!
info: Starting Html Export Subroutine
info: spaceId: 5d3a7bc6-4712-43c6-9642-a7717fc757cb
info: Task Id: fa2e203f-f0da-4d42-b132-d9205d33b4ad
info: Current Task status: success
info: Got the S3 download URL
info: Starting file download
info: File download successful
info: Removing all non dot files and folders from /Users/subhmx/Personal/notion-to-ebook/session_files/input
info: Files removal success
info: Starting file extraction
info: File extracted successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/subhmx/Personal/notion-to-ebook/session_files/output/standalone/Projects 920be5e64bd04f34b3c4450ad3fcc80e/FormAssist 24b55bd600aa4f048e9431834801137b.pdf]
Loading pages (1/6)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                      
info: Ebook Saved Successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/subhmx/Personal/notion-to-ebook/session_files/output/standalone/Projects 920be5e64bd04f34b3c4450ad3fcc80e/GitHub Project Bot 61319115f9f9431a8fe2d07496a2ca66.pdf]
Loading pages (1/6)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                      
info: Ebook Saved Successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/subhmx/Personal/notion-to-ebook/session_files/output/standalone/Projects 920be5e64bd04f34b3c4450ad3fcc80e/RISCV Heritage e72fa8c001c74632995ba936c3bb9761.pdf]
Loading pages (1/6)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                      
info: Ebook Saved Successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/subhmx/Personal/notion-to-ebook/session_files/output/standalone/Projects 920be5e64bd04f34b3c4450ad3fcc80e/Train Ticketing 28204c1e64ea4f8d89f2ad69b1c5562f.pdf]
Loading pages (1/6)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                      
info: Ebook Saved Successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/subhmx/Personal/notion-to-ebook/session_files/output/standalone/Projects 920be5e64bd04f34b3c4450ad3fcc80e.pdf]
Loading pages (1/6)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                      
info: Ebook Saved Successfully
Testing merged doc generation
info: Current session is already called. Using the previous Notion export
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [/Users/subhmx/Personal/notion-to-ebook/session_files/output/merged/prime_book.pdf]
Loading pages (1/6)
Counting pages (2/6)                                               
Loading TOC (3/6)                                                           
Resolving links (4/6)                                              
Loading headers and footers (5/6)                                           
Printing pages (6/6)                                               
Done                                                                        
info: Ebook Saved Successfully
info: Operation Successful. Exiting.
subhmx@bcd0741610ce notion-to-ebook % 
subhamX commented 1 year ago

Published as a new package https://www.npmjs.com/package/notion-easy-export. Idk why I was unable to publish to @subhamX/notion-to-ebook. The NPM support was horrible, and I don't have any more patience to deal with their utterly stupid and delayed response. πŸ˜“

Thank you again, @jtomaszewski for initial investigation, and @furqansafdar for following this conversation.