Skip to content
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

refactor(server): asset serve files #2052

Merged
merged 1 commit into from
Mar 24, 2023
Merged

Conversation

jrasm91
Copy link
Contributor

@jrasm91 jrasm91 commented Mar 23, 2023

There was a lot of duplicate code related to reading and returning a file (etag check, file readability check, setting headers, creating read stream, etc.). This has been refactored so there's no more duplicate code related to reading and streaming files.

@vercel
Copy link

vercel bot commented Mar 23, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated
immich ⬜️ Ignored (Inspect) Mar 23, 2023 at 2:32PM (UTC)

@@ -264,81 +247,18 @@ export class AssetService {
res: Res,
headers: Record<string, string>,
) {
const allowOriginalFile = !authUser.isPublicUser || authUser.isAllowDownload;
const allowOriginalFile = !!(!authUser.isPublicUser || authUser.isAllowDownload);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the different between the old vs the new logic here?

Copy link
Contributor Author

@jrasm91 jrasm91 Mar 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old logic resulted in a type of boolean | undefined. That is OK because undefined also is falsy. However, it's now being passed into a function that has a type boolean, so this (!!) is just a fancy way to turn undefined into false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change in logic, just a coercion of type to align with the new method I added.

Copy link
Contributor

@alextran1502 alextran1502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and everything looks good!

@alextran1502 alextran1502 merged commit bbd897b into main Mar 24, 2023
@alextran1502 alextran1502 deleted the refactor/asset-serve-files branch March 24, 2023 02:40
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.

2 participants