richartkeil / notion-guardian

πŸ›‘βœοΈ Keeps your Notion workspace safe and version controlled at all times.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Export not unzipped?

fortran01 opened this issue Β· comments

Did I miss anything? It's the ZIP file that is committed. I have to do the following to unzip. πŸ™πŸ½

          # Find the zip file using the wildcard
          zip_file="$(ls *.zip | head -n1)"
          # Unzip the file
          unzip "$zip_file"
          # Get the top-level folder
          folder=$(unzip -Z1 "$zip_file" | awk -F/ '{print $1}' | sort | uniq)
          # Move the contents of the first-level folder to the current directory
          rsync "${folder%/}"/* .
          # Remove the first-level folder
          rm -r "${folder%/}"
          # Delete the zip file
          rm "$zip_file"

Have you altered the script in some way? Usually these two lines extract the .zip and remove it afterwards:

// ...
await extract(workspaceZip, { dir: workspaceDir });
await unlink(workspaceZip);
// ...

Also workspace.zip is in the .gitignore which prevents it from being committed.

Edit: I suspect this might be because of #10 β†’ I'll have a look at it.

No modifications. I have to do above, so I can unzip it. Some observations:

  • my output file is less than 500MB
  • the file name is not workspace.zip, it's some hash

Thanks for checking.

I encountered the same issue
I believe the reason is that when calling notion exportURL, it returns a zip package. The exportFromNotion function compresses the zip package again.

const stream = response.data.pipe(createWriteStream(destination));

My solution is to use the onEntry property of extract to detect and unzip the zip package again. The code looks like this:

  await extract(workspaceZip, {
    dir: workspaceDir, onEntry: async (entry, zipfile) => {
      if (entry.fileName.toLowerCase().endsWith('.zip')) {
        const nestedZipFile = join(workspaceDir, entry.fileName);
        zipfile.openReadStream(entry, (err, readStream) => {
          if (err) throw err;
          const writeStream = createWriteStream(nestedZipFile);
          readStream.pipe(writeStream);
          writeStream.on('finish', () => {
            extract(nestedZipFile, { dir: workspaceDir })
          });
        });
      }
    }
  });

This problem should be fixed now. Thank you @heibaikn for the PR (#17)! I tried using your approach, however it did not work when I tested it with a large export (~1GB), so I fell back to another solution and used the opportunity to clean up the repo a bit.