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): download file #1512

Merged
merged 4 commits into from Feb 3, 2023
Merged

refactor(server): download file #1512

merged 4 commits into from Feb 3, 2023

Conversation

jrasm91
Copy link
Contributor

@jrasm91 jrasm91 commented Feb 2, 2023

No description provided.

@vercel
Copy link

vercel bot commented Feb 2, 2023

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

Name Status Preview Updated
immich-code-coverage ✅ Ready (Inspect) Visit Preview Feb 2, 2023 at 5:37AM (UTC)
1 Ignored Deployment
Name Status Preview Updated
immich ⬜️ Ignored (Inspect) Feb 2, 2023 at 5:37AM (UTC)

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.

Looks good! I tested on mobile, web and public shared page. All worked as expected

this.assetService.checkDownloadAccess(authUser);
await this.assetService.checkAssetsAccess(authUser, [assetId]);
return this.assetService.downloadFile(query, assetId, res);
return this.assetService.downloadFile(authUser, assetId).then(asStreamableFile);
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this a bit hard to follow. Can you elaborate for documentation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, downloadFile return ImmichStream and you cast that to StreamableFile of Nestjs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could return a streamable file directly, but I'd prefer to keep that nestjs reference out of the domain, since it is specific to the api (not cli, graphql, etc.), so I made a separate interface with no nestjs specifics in it (immich readable file), and then map between the two here.

if (asset.type === AssetType.VIDEO) {
const { size } = await fileInfo(asset.originalPath);

res.set({
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't recal why I had to set the content-type and content-length here. But the testing went well even without these two header get explicitly set. Did you encounter anything not working right without the two headers get set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So these actually do get set, just through the options in the streamable file object. I'm trying to keep transport specific stuff like this outside of the "domain". The domain returns the value, then the controller maps the response into a streamable file. The second argument ends up being set as a header.

Copy link
Contributor

Choose a reason for hiding this comment

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

image
Through this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

@alextran1502 alextran1502 merged commit 2b0b2bb into main Feb 3, 2023
@alextran1502 alextran1502 deleted the refactor/download-file branch February 3, 2023 15:16
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.

None yet

2 participants