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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
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.
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); |
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.
I find this a bit hard to follow. Can you elaborate for documentation?
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.
Ah, downloadFile return ImmichStream
and you cast that to StreamableFile of Nestjs
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.
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({ |
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.
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?
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.
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.
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.
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
No description provided.