Skip to content

Save attachments to disk - #29

Open
immersivegamer wants to merge 2 commits into
ReachFive:masterfrom
immersivegamer:save-attachments
Open

immersivegamer wants to merge 2 commits into
ReachFive:masterfrom
immersivegamer:save-attachments

Conversation

@immersivegamer

Copy link
Copy Markdown

See comment for commit 1ac09ec

Adds the option to save attachments to disk to help speed up page loading for emails with large attachments (size or quantity).

Running `npm install` caused warning about security. I ran the following:

    npm audit fix

    npm aduit fix --force

    npm upgrade

Also removed `homepage` field from package.json. This is supposed to be the
relative point to the app, not the source code's project home page. Removing
this also means we can remove the PUBLIC_URL env var in the build script
command which was causing problems when building on Windows.
Added the options:

--save       Flag to save to enable files to disk
--savepath   Dir to save files to relative to script (default: ./downloads/)

Was running into a problem where I wanted to test many emails with
attachments. The current method of rendering the page sends all attachments
embedded in the JSON. This causes very long page loads for even a few emails.

I decided to add an option to instead save the attachments to disk when the
email is parsed. The code still uses the simpleParse method so initially
attachments are buffered into memory. However, after it is parsed and the
option is enabled it is saved to disk and the `attachment.content` property
is deleted and should be released from memory.

Since we are saving to disk a new API was needed. Each attachment saved to
disk gets a `shortid` to make it unique. This ID is also sent in the API call
and using express's res.sendFile() makes it a one liner.

The button openAttachment method was also updated in App.js so that if an
attachment was saved then it will use the API as a link.

To help with clean up the delete emails API will also delete any attachment
files it knows of. It doesn't delete everything in the save folder as it
might accidentally delete files that the user didn't want to be deleted.
Manual clean up will be needed if the service is restarted.

This has helped improve load time of the web page for display of the emails.
@immersivegamer

Copy link
Copy Markdown
Author

If I have time I will submit a commit to clean up white space changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant