feature(web): Added option to download file and copy stream url#209
feature(web): Added option to download file and copy stream url#209PartyDonut merged 2 commits intodevelopfrom
Conversation
Reviewer's Guide by SourceryThis pull request adds the ability to download files and copy stream URLs on the web platform. It introduces two new buttons within the item action menu when the app is running on the web. These buttons allow users to download the file directly or copy the stream URL to their clipboard. Sequence diagram for file download and stream URL copy processsequenceDiagram
actor User
participant UI
participant AccountModel
participant UserProvider
participant Browser
User->>UI: Clicks download file button
UI->>AccountModel: Check canDownload
AccountModel-->>UI: Return download permission
UI->>UserProvider: createDownloadUrl(item)
UserProvider-->>UI: Return download URL
UI->>Browser: Trigger file download
User->>UI: Clicks copy stream URL button
UI->>UserProvider: createDownloadUrl(item)
UserProvider-->>UI: Return stream URL
UI->>Browser: Copy URL to clipboard
UI->>User: Show success notification
Class diagram showing modified componentsclassDiagram
class AccountModel {
+String server
+bool canDownload
+sameIdentity(AccountModel other) bool
}
class User {
+createDownloadUrl(ItemBaseModel item) String?
}
class ItemBaseModelExtensions {
+buildItemActions()
}
class FileDownloader {
+downloadFile(String url) Future~void~
}
ItemBaseModelExtensions ..> User: uses
ItemBaseModelExtensions ..> FileDownloader: uses
ItemBaseModelExtensions ..> AccountModel: uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @PartyDonut - I've reviewed your changes and found some issues that need to be addressed.
Blocking issues:
- Avoid hardcoding API keys directly in the URL. (link)
Overall Comments:
- Consider implementing proper error handling with user feedback in downloadFile() instead of just printing to console. Also, the download filename should be more user-friendly than the raw URL.
- Exposing API keys in copyable stream URLs is a security risk. Consider implementing temporary download tokens or another secure method for sharing URLs.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🔴 Security: 1 blocking issue, 1 other issue
- 🟢 Review instructions: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| Future<void> downloadFile(String url) async { | ||
| try { | ||
| html.AnchorElement anchorElement = html.AnchorElement(href: url); | ||
| anchorElement.download = url; |
There was a problem hiding this comment.
issue: The download attribute should be a filename, not the full URL
Consider extracting a meaningful filename from the URL or passing it as a parameter
|
|
||
| void deleteAllFilters() => state = state?.copyWith(savedFilters: []); | ||
|
|
||
| String? createDownloadUrl(ItemBaseModel item) => |
There was a problem hiding this comment.
🚨 issue (security): URL parameters should be properly encoded
Use Uri.encodeComponent() for the api_key and other parameters to ensure proper URL encoding
| action: () => showSyncItemDetails(context, syncedItem, ref), | ||
| label: Text(context.localized.syncDetails), | ||
| icon: const Icon(IconsaxOutline.document_download), | ||
| action: () => downloadFile(ref.read(userProvider.notifier).createDownloadUrl(this) ?? "Null"), |
There was a problem hiding this comment.
issue: Handle null download URL case more gracefully
Instead of passing "Null" as the URL, consider showing an error message to the user
lib/providers/user_provider.dart
Outdated
| void deleteAllFilters() => state = state?.copyWith(savedFilters: []); | ||
|
|
||
| String? createDownloadUrl(ItemBaseModel item) => | ||
| "${state?.server}/Items/${item.id}/Download?api_key=${state?.credentials.token}"; |
There was a problem hiding this comment.
🚨 issue (security): Avoid hardcoding API keys directly in the URL.
Exposing API keys like this can lead to unauthorized access. Consider using a more secure approach, such as storing the API key in secure storage and adding it to the request headers.
Pull Request Description
Adds two buttons on web only
Issue Being Fixed
Resolves #193