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

[UPY-11] Implement the rename file fucntion #12

Merged
merged 1 commit into from
Feb 17, 2025

Conversation

farmisen
Copy link
Owner

@farmisen farmisen commented Feb 17, 2025

Implements file rename functionality for both sync and async uploadthing clients

Adds new rename_files() method to both client implementations allowing files to be renamed using either file keys or custom IDs. Includes comprehensive test coverage and example implementations.

Changes

  • Added new rename_files() method to UTApi and AsyncUTApi classes
  • Implemented new RenameFilesResponse schema class for handling rename operation results
  • Updated base client interface with abstract rename_files method
  • Added documentation and examples for rename functionality in README.md

Impact

  • Extends API functionality with new file management capability
  • All changes are backwards compatible - no breaking modifications
  • New rename functionality requires additional API calls per operation
  • Minimal memory/performance impact as operations are HTTP-based

Summary by CodeRabbit

  • New Features

    • Introduced a file renaming capability for uploaded files, allowing users to update file names using either default identifiers or custom IDs with built-in verification to confirm updates.
  • Documentation

    • Enhanced the user guide with a new section and clear examples demonstrating how to leverage the file renaming feature.
    • Added details about the response structure for file renaming operations.
  • Tests

    • Expanded test coverage for the file renaming functionality with new asynchronous and synchronous test cases.

Copy link

coderabbitai bot commented Feb 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce a new file renaming feature across the project. A new method rename_files is added to both synchronous and asynchronous API clients alongside its corresponding response model, RenameFilesResponse. Documentation in the README is updated with usage examples, and the functionality is demonstrated in example scripts. Additionally, extensive tests have been added in both synchronous and asynchronous test suites. The abstract base client is updated to include the new method, and the public interface is extended with the new schema.

Changes

File(s) Change Summary
README.md Added a new section documenting the rename_files method, its parameters, examples, and the new RenameFilesResponse model.
examples/async_main.py, examples/main.py Introduced new code to execute file renaming, capture the rename result, and verify that the operation updated file names as expected.
tests/test_async_client.py, tests/test_client.py Added new tests: test_rename_files, test_rename_files_with_custom_id, and test_rename_files_mixed_updates to validate the renaming functionality under various scenarios.
upyloadthing/client.py, upyloadthing/async_client.py, upyloadthing/base_client.py Introduced rename_files methods in both synchronous and asynchronous API clients; updated the abstract base client with the new method signature.
upyloadthing/schemas.py, upyloadthing/__init__.py Added the new RenameFilesResponse class and updated the module’s public interface to export it.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Client as UTApi/AsyncUTApi
  participant API as UploadThingAPI

  User->>Client: rename_files(updates)
  Client->>API: POST /v6/renameFiles (with updates)
  API-->>Client: RenameFilesResponse (success, renamed_count)
  Client-->>User: RenameFilesResponse
Loading

Possibly Related PRs

  • [UPY-7] Support async operations #6: Implements similar changes by introducing and testing the rename_files functionality in both UTApi and AsyncUTApi, directly relevant to the current modifications.

Poem

I'm a bunny with a coding flair,
Hopping through changes without a care.
Files get new names with a simple twist,
A neat little feature you can't resist.
Celebrate with hops, code, and cheer—
Renaming's here, so let's all cheer! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f396f8 and 1cd2f27.

📒 Files selected for processing (10)
  • README.md (3 hunks)
  • examples/async_main.py (1 hunks)
  • examples/main.py (1 hunks)
  • tests/test_async_client.py (2 hunks)
  • tests/test_client.py (2 hunks)
  • upyloadthing/__init__.py (2 hunks)
  • upyloadthing/async_client.py (2 hunks)
  • upyloadthing/base_client.py (2 hunks)
  • upyloadthing/client.py (2 hunks)
  • upyloadthing/schemas.py (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
examples/main.py (1)

63-70: Enhance verification logic to be more precise.

The current verification using issubset only checks if the new names exist but doesn't verify that the old names were actually replaced.

Consider this more thorough verification:

-    expected_names = {"renamed_test.png", "renamed_test.jpg"}
-    actual_names = {file.name for file in updated_files.files}
-    if expected_names.issubset(actual_names):
+    old_names = {"test.png", "test.jpg"}
+    new_names = {"renamed_test.png", "renamed_test.jpg"}
+    actual_names = {file.name for file in updated_files.files}
+    if new_names.issubset(actual_names) and not old_names.intersection(actual_names):
examples/async_main.py (1)

74-81: Enhance verification logic to be more precise.

Similar to the synchronous example, the verification could be more thorough by also checking that old names were replaced.

Consider this more thorough verification:

-    expected_names = {"renamed_test.png", "renamed_test.jpg"}
-    actual_names = {file.name for file in updated_files.files}
-    if expected_names.issubset(actual_names):
+    old_names = {"test.png", "test.jpg"}
+    new_names = {"renamed_test.png", "renamed_test.jpg"}
+    actual_names = {file.name for file in updated_files.files}
+    if new_names.issubset(actual_names) and not old_names.intersection(actual_names):
tests/test_async_client.py (1)

311-332: Consider adding test cases for error scenarios.

While the current test thoroughly verifies the mixed update functionality, consider adding test cases for:

  • Error cases (e.g., invalid file key, invalid custom ID)
  • Empty updates list
  • Invalid response from the API
README.md (1)

63-84: Consider adding examples for error handling and response usage.

While the examples are clear and comprehensive, consider adding:

  • Error handling example (similar to the general error handling section)
  • Example showing how to use the response (e.g., checking success and renamed count)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc437eb and 9f396f8.

📒 Files selected for processing (10)
  • README.md (3 hunks)
  • examples/async_main.py (1 hunks)
  • examples/main.py (1 hunks)
  • tests/test_async_client.py (2 hunks)
  • tests/test_client.py (2 hunks)
  • upyloadthing/__init__.py (2 hunks)
  • upyloadthing/async_client.py (2 hunks)
  • upyloadthing/base_client.py (2 hunks)
  • upyloadthing/client.py (2 hunks)
  • upyloadthing/schemas.py (1 hunks)
👮 Files not reviewed due to content moderation or server errors (4)
  • upyloadthing/client.py
  • upyloadthing/async_client.py
  • upyloadthing/base_client.py
  • tests/test_client.py
🔇 Additional comments (4)
upyloadthing/__init__.py (1)

7-7: LGTM!

The RenameFilesResponse schema is correctly imported and exposed in the public interface, maintaining consistency with other response types.

Also applies to: 21-21

upyloadthing/schemas.py (1)

37-40: LGTM!

The RenameFilesResponse schema follows the established pattern, with appropriate field types and clear purpose.

tests/test_async_client.py (2)

267-286: LGTM!

The test case thoroughly verifies the file renaming functionality using file keys, including response type checking and attribute validation.


288-309: LGTM!

The test case thoroughly verifies the file renaming functionality using custom IDs, including response type checking and attribute validation.

README.md Outdated
Comment on lines 161 to 167
- `rename_files(updates: List[dict[str, str]]) -> RenameFilesResponse`
- Rename files or update their custom IDs
- Updates list should contain dicts with:
- `fileKey` (required) and either:
- `newName` or `customId`
- Returns rename operation result

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix inconsistency in method documentation.

The documentation states that fileKey is required, but the examples show that either fileKey or customId is required.

Apply this diff to fix the documentation:

-    - `fileKey` (required) and either:
-    - `newName` or `customId`
+    - Either `fileKey` or `customId` (one is required)
+    - `newName` (required)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- `rename_files(updates: List[dict[str, str]]) -> RenameFilesResponse`
- Rename files or update their custom IDs
- Updates list should contain dicts with:
- `fileKey` (required) and either:
- `newName` or `customId`
- Returns rename operation result
- `rename_files(updates: List[dict[str, str]]) -> RenameFilesResponse`
- Rename files or update their custom IDs
- Updates list should contain dicts with:
- Either `fileKey` or `customId` (one is required)
- `newName` (required)
- Returns rename operation result

@farmisen farmisen force-pushed the farmisen/upy-11-implement-the-rename-file-fucntion branch from 9f396f8 to 1cd2f27 Compare February 17, 2025 21:12
@farmisen farmisen merged commit 54c942a into main Feb 17, 2025
2 of 3 checks passed
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.

1 participant