Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@phattantran1997
Copy link
Contributor

  • Each user now has a personal download folder based on their user ID.
  • Updated FileManager to dynamically use user-specific root paths instead of global /downloads

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @phattantran1997, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request implements user-specific download folders. It modifies the DownloadFromDirectLink.razor and DownloadVideoAudio.razor components to use a user ID to create a unique download path. The FileManager.razor component is updated to reflect these changes, and a ValidateUserDownloadFolder method is added to ensure that users can only access their own download folders. The DirectoryBrowser.cs file is updated to include a method for getting the user specific download path.

Highlights

  • User-Specific Download Folders: Each user now has a personal download folder based on their user ID, enhancing privacy and organization.
  • Dynamic Root Paths: The FileManager component dynamically uses user-specific root paths instead of a global /downloads directory.
  • Path Validation: A ValidateUserDownloadFolder method is implemented to prevent users from accessing download folders outside of their designated directory.

Changelog

Click here to see the changelog
  • SaveHere/SaveHere/Components/Download/DownloadFromDirectLink.razor
    • Added @using System.Security.Claims to access user claims.
    • Injected AuthenticationStateProvider to get user authentication state.
    • Passed UserId and userFolderPath parameters to the FileManager component.
    • Initialized userId and userFolderPath based on the authenticated user in OnInitializedAsync (lines 279-282).
    • Added ValidateUserDownloadFolder method to validate the download folder path (lines 675-686).
    • Modified the DownloadFolder property of FileDownloadQueueItem to use the validated folder path in AddDownloadItem and StartDownloadItem methods (lines 495-496, 525-526).
  • SaveHere/SaveHere/Components/Download/DownloadVideoAudio.razor
    • Added @using SaveHere.Helpers and @using System.Security.Claims.
    • Injected AuthenticationStateProvider.
    • Passed UserId and CurrentPath parameters to the FileManager component.
    • Initialized userId and userFolderPath based on the authenticated user in OnInitializedAsync (lines 251-254).
    • Added ValidateUserDownloadFolder method to validate the download folder path (lines 583-594).
    • Modified the DownloadFolder property of YoutubeDownloadQueueItem to use the validated folder path in AddDownloadItem and StartDownloadItem methods (lines 404-405, 428).
  • SaveHere/SaveHere/Components/Utility/FileManager.razor
    • Added UserId parameter.
    • Modified _currentDirectory to be an empty string initially.
    • Initialized _userRootPath and _currentDirectory based on UserId in OnInitializedAsync (lines 172-173).
    • Updated UpdateBreadcrumbs to use _userRootPath instead of DirectoryBrowser.DownloadsPath (lines 211-214).
    • Updated NavigateToDirectory to use _userRootPath when the path is null (line 226).
  • SaveHere/SaveHere/Helpers/DirectoryBrowser.cs
    • Added GetUserDownloadsPath method to create and retrieve the user-specific downloads path (lines 168-183).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A user's space,
A folder of their own files,
Privacy ensured.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces user-specific download folders, enhancing the application's file management capabilities. The changes involve updating the FileManager component and related services to dynamically use user-specific root paths instead of a global /downloads directory. This is a good step towards better user data isolation and organization.

Summary of Findings

  • Potential Security Vulnerability in Folder Validation: The ValidateUserDownloadFolder method in DownloadFromDirectLink.razor and DownloadVideoAudio.razor attempts to prevent path traversal vulnerabilities. However, the validation logic might be bypassed if the userFolderPath contains special characters or symbolic links. This could allow users to access directories outside their intended download folder.
  • Redundant Folder Validation: The ValidateUserDownloadFolder method is called multiple times before starting a download, which could lead to performance overhead. Consider validating the folder once and reusing the validated path.
  • Inconsistent Error Handling: The FileManager component displays an error message if the UserId parameter is null or empty. However, the DirectoryBrowser.GetUserDownloadsPath method throws an ArgumentException if the userId is null or empty. This inconsistency could lead to unexpected behavior.

Merge Readiness

The pull request introduces important changes for user-specific download folders. However, there are potential security vulnerabilities and inconsistencies in error handling that need to be addressed before merging. I recommend addressing the issues raised in the review comments before merging. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.

Comment on lines +167 to +170
if (string.IsNullOrEmpty(UserId))
{
_currentDirectory = CurrentPath;
errorMessage = "User ID is required.";
return;

Choose a reason for hiding this comment

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

medium

The FileManager component displays an error message if the UserId parameter is null or empty. However, the DirectoryBrowser.GetUserDownloadsPath method throws an ArgumentException if the userId is null or empty. Consider throwing an exception here as well to maintain consistency.

      if (string.IsNullOrEmpty(UserId))
      {
        throw new ArgumentException("User ID cannot be null or empty.", nameof(UserId));
      }

@phattantran1997
Copy link
Contributor Author

@gudarzi, hi, I have already created a new PR. Can you help check it? Thank you so much.ch.

@gudarzi gudarzi merged commit 8d486ed into gudarzi:v3.0 Apr 27, 2025
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