-
Notifications
You must be signed in to change notification settings - Fork 3
frontend: route downloads by size (#577) #578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for auto-drive-storage ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| const MiB = 1024 * 1024; | ||
| const MAX_CACHEABLE_FILE_SIZE = 150 * MiB; | ||
| const MAX_ANONYMOUS_DOWNLOAD_SIZE = Number( | ||
| process.env.NEXT_PUBLIC_MAX_ANONYMOUS_DOWNLOAD_SIZE ?? 100 * MiB, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new environment variable? Added to the relevant places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is initially how I was going to approach this, via setting up a new ENV variable. The original MAX_ANONYMOUS_DOWNLOAD_SIZE is coming from backend and not directly accessible on frontend, hence why I initially introduced a new env variable.
Now I'm thinking that is likely an incorrect approach - that would require us to maintain essentially the same variable in two places, which is a bad practice. I have adjusted the code to take another approach and eliminate this issue. Please review the latest commit.
TLDR: The frontend now always starts the download as an anonymous request (no auth headers) and lets the backend decide if the file is too big for anonymous downloads. If the backend rejects it as “too large/402”, the frontend retries with your logged-in session (or shows a “please login” message if you’re not signed in).
Co-authored-by: Jim Counter <jimcounter@hotmail.com>
…downloaded anonymously
jim-counter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the config and behaviour propagate from the backend is cleaner. Nice!
Summary
Behavior
Changes