-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
TorBox Integration #132
base: main
Are you sure you want to change the base?
TorBox Integration #132
Conversation
…external searching, using cors anywhere
… Added TorBox to readme
Warning Rate limit exceeded@anonymous-org-za has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 43 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe recent changes enhance the media library management system by integrating the TorBox service. This addition improves user authentication, torrent management, and API interactions. Notable updates include the expansion of the user interface to support TorBox, modifications to existing components for better state management, and the introduction of new utilities for handling torrents specifically from TorBox. Overall, these updates significantly enhance functionality and user experience. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant App
participant TorBoxAPI
User->>App: Requests to add torrent
App->>TorBoxAPI: send add torrent request
TorBoxAPI-->>App: Returns success/failure
App-->>User: Notify user of success/failure
sequenceDiagram
participant User
participant App
participant AuthService
User->>App: Initiates login
App->>AuthService: Check login with TorBox
AuthService-->>App: Return user info
App-->>User: Display user dashboard
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
Handles #109 |
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.
Actionable comments posted: 12
Outside diff range, codebase verification and nitpick comments (7)
src/pages/torbox/login.tsx (1)
37-40
: Enhance error handling for API key submission.Consider providing user feedback after setting the API key, such as redirecting or showing a success message.
+ if (!regexTest) { + setError("Not a valid TorBox API key."); + } else { + setApiKey(submittedApiKey); + // Consider showing a success message or redirecting + }src/services/torbox.ts (1)
87-103
: Consider adding a success message indeleteTorBoxTorrent
.Currently, the function only logs errors. Consider logging a success message for confirmation when a torrent is deleted.
console.log(`Successfully deleted torrent with ID: ${id}`);README.md (3)
9-9
: Remove the comma before 'because'.The clause is essential to the meaning, so the comma is unnecessary.
- without worrying about storage limits, because the files are shared among all users. + without worrying about storage limits because the files are shared among all users.Tools
LanguageTool
[formatting] ~9-~9: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...nt without worrying about storage limits, because the files are shared among all users. Y...(COMMA_BEFORE_BECAUSE)
19-19
: Use a more formal term than 'amazing'.Consider using 'exceptional' or 'outstanding' for a more formal tone.
- the amazing service + the exceptional serviceTools
LanguageTool
[style] ~19-~19: Consider using a more formal and expressive alternative to ‘amazing’.
Context: ... ## Features This builds on top of the amazing service brought by [Real-Debrid](http:/...(AWESOME)
47-47
: Clarify the External Search API setup.Ensure the instructions clearly explain the purpose of changing
EXTERNAL_SEARCH_API_HOSTNAME
.- If you don't want to build your own library, edit the config + To use an external search API instead of building your own library, edit the configsrc/utils/addMagnet.ts (1)
161-163
: Clarify the purpose ofhandleRestartTorBoxTorrent
.Consider adding a comment explaining why the function only displays a toast and does not perform any operations.
// TorBox does not support restarting torrents, hence only a notification is provided.
src/pages/index.tsx (1)
30-32
: Refine the error message fortbError
.Consider providing a more detailed error message to help users troubleshoot issues with TorBox integration.
- 'TorBox get user info failed, try clearing DMM site data and login again' + 'Failed to retrieve TorBox user information. Please clear your DMM site data and try logging in again.'
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (24)
- README.md (4 hunks)
- next.config.js (2 hunks)
- src/hooks/auth.ts (7 hunks)
- src/pages/anime/[animeid].tsx (8 hunks)
- src/pages/animesearch.tsx (2 hunks)
- src/pages/browse/anime.tsx (1 hunks)
- src/pages/browse/recent.tsx (1 hunks)
- src/pages/hashlist.tsx (18 hunks)
- src/pages/index.tsx (5 hunks)
- src/pages/library.tsx (20 hunks)
- src/pages/movie/[imdbid].tsx (10 hunks)
- src/pages/search.tsx (2 hunks)
- src/pages/show/[imdbid]/[seasonNum].tsx (9 hunks)
- src/pages/start.tsx (2 hunks)
- src/pages/torbox/login.tsx (1 hunks)
- src/services/mediasearch.ts (2 hunks)
- src/services/torbox.ts (1 hunks)
- src/torrent/userTorrent.ts (1 hunks)
- src/utils/addMagnet.ts (3 hunks)
- src/utils/deleteTorrent.ts (2 hunks)
- src/utils/fetchTorrents.ts (3 hunks)
- src/utils/instantChecks.ts (3 hunks)
- src/utils/showInfo.ts (2 hunks)
- src/utils/withAuth.tsx (3 hunks)
Additional context used
LanguageTool
README.md
[formatting] ~9-~9: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...nt without worrying about storage limits, because the files are shared among all users. Y...(COMMA_BEFORE_BECAUSE)
[style] ~19-~19: Consider using a more formal and expressive alternative to ‘amazing’.
Context: ... ## Features This builds on top of the amazing service brought by [Real-Debrid](http:/...(AWESOME)
Additional comments not posted (45)
src/utils/deleteTorrent.ts (1)
35-47
: LGTM! The functionhandleDeleteTbTorrent
is well-implemented.The addition of
handleDeleteTbTorrent
follows the existing pattern for handling torrent deletions and maintains consistency in error handling and notifications.src/utils/withAuth.tsx (1)
1-1
: LGTM! The authentication logic is enhanced to include TorBox support.The integration of
useTorBoxApiKey
and updates to the authentication logic ensure that the application handles the TorBox API key correctly. The changes maintain consistency with existing logic.Also applies to: 15-15, 21-21, 30-30
src/services/mediasearch.ts (1)
21-21
: LGTM! But verify the usage oftbAvailable
.The addition of
tbAvailable
toSearchResult
andEnrichedHashlistTorrent
looks good and maintains backward compatibility.Ensure that the new
tbAvailable
property is correctly utilized and handled across the codebase.Also applies to: 43-43
Verification successful
tbAvailable
Property Usage VerifiedThe
tbAvailable
property is actively used in the codebase, specifically insrc/utils/instantChecks.ts
, where it is set totrue
orfalse
. This confirms that the property is integrated into the application's logic. No further issues were found regarding its usage.
- Files Involved:
src/utils/instantChecks.ts
: ModifiestbAvailable
.src/services/mediasearch.ts
: DefinestbAvailable
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of the `tbAvailable` property in the codebase. # Test: Search for the usage of `tbAvailable`. Expect: Occurrences where it is being used or checked. rg --type typescript 'tbAvailable'Length of output: 69
Script:
#!/bin/bash # Description: Verify the usage of the `tbAvailable` property in the codebase. # Test: Search for the usage of `tbAvailable`. Expect: Occurrences where it is being used or checked. rg --glob '*.ts' 'tbAvailable'Length of output: 378
next.config.js (1)
49-54
: LGTM! But verify the usage of new configurations.The addition of a new media source and the TorBox API endpoint in the configuration looks good.
Ensure that the new media source and the
torboxHostname
are correctly utilized in the application.Also applies to: 71-71
src/pages/browse/anime.tsx (1)
19-21
: Verify the impact of commenting out path encoding.Commenting out the encoding logic for
path
may affect URL formatting. Ensure that this change does not introduce issues with API requests.src/pages/browse/recent.tsx (1)
19-21
: Verify the impact of disabling path encoding.The conditional logic for encoding the
path
has been commented out. Ensure that the API endpoint can handle special characters in paths without encoding.src/pages/torbox/login.tsx (1)
32-34
: Ensure regex pattern covers all valid API key formats.The regex pattern used for API key validation seems correct, but ensure it matches all valid formats for TorBox API keys.
Verification successful
Regex pattern appears to be correct for UUID format.
The regex pattern used in
src/pages/torbox/login.tsx
matches the standard UUID format, which is commonly used for API keys. Ensure this format is consistent with all valid TorBox API key formats. If TorBox uses a different or additional format, the regex will need to be updated accordingly.
- File:
src/pages/torbox/login.tsx
- Lines: 32-34
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the regex pattern for API key validation. # Test: Check if the regex pattern is consistent with TorBox API key format. rg --type javascript -A 5 $'const apiKeyRegex' | grep 'apiKeyRegex'Length of output: 101
Script:
#!/bin/bash # Description: Verify the regex pattern for API key validation. # Test: Check for occurrences of the apiKeyRegex pattern in the codebase. rg 'const apiKeyRegex' -A 5Length of output: 502
src/pages/start.tsx (1)
81-97
: VerifyloginWithTorBox
implementation.Ensure that the
loginWithTorBox
function is implemented correctly in theuseDebridLogin
hook.Verification successful
loginWithTorBox
is implemented and used correctly.The function
loginWithTorBox
is defined insrc/hooks/auth.ts
and is correctly used insrc/pages/start.tsx
. It is part of theuseDebridLogin
hook's return value, confirming its integration.
src/hooks/auth.ts
: Definition ofloginWithTorBox
.src/pages/start.tsx
: Usage ofloginWithTorBox
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of `loginWithTorBox` in the `useDebridLogin` hook. # Test: Search for the `loginWithTorBox` function in the `useDebridLogin` hook. ast-grep --lang javascript --pattern $'function useDebridLogin() { $$$ function loginWithTorBox($_) { $$$ } $$$ }'Length of output: 129
Script:
#!/bin/bash # Description: Search for the `loginWithTorBox` function across the entire codebase. # Test: Search for the `loginWithTorBox` function definition. ast-grep --lang javascript --pattern 'function loginWithTorBox($_) { $$$ }'Length of output: 79
Script:
#!/bin/bash # Description: Search for references to `loginWithTorBox` across the entire codebase. # Test: Search for any usage or import of `loginWithTorBox`. rg 'loginWithTorBox'Length of output: 274
src/hooks/auth.ts (4)
34-48
: InterfaceTorBoxUser
looks good.The interface is well-structured and includes relevant user attributes for TorBox.
61-63
: FunctionloginWithTorBox
is correctly implemented.The function correctly navigates to the TorBox login page using the router.
109-112
: FunctionuseTorBoxApiKey
is correctly implemented.The function successfully retrieves the TorBox API key from local storage.
122-132
: Integration of TorBox inuseCurrentUser
is well-implemented.The hook now correctly manages state for TorBox user data and error handling.
Ensure that the
getTorBoxUser
function is correctly implemented and handles errors properly.Verification successful
Let's perform a broader search for
getTorBoxUser
to identify its definition or usage in the codebase.
The
getTorBoxUser
function is correctly implemented and integrated.
- The function is defined in
src/services/torbox.ts
and includes proper API interaction and error handling.- It is correctly used in
src/hooks/auth.ts
to fetch and manage TorBox user data.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of `getTorBoxUser`. # Test: Search for the function implementation. Expect: Correct error handling and API interaction. ast-grep --lang typescript --pattern $'function getTorBoxUser($_) { $$$ }'Length of output: 77
Script:
#!/bin/bash # Description: Broad search for `getTorBoxUser` to find its definition or usage. rg 'getTorBoxUser' -A 3Length of output: 817
src/pages/animesearch.tsx (2)
51-53
: Verify the impact of commenting out path encoding infetchMiscData
.Commenting out the encoding logic may affect how API requests are constructed. Ensure this change is intentional and doesn't disrupt functionality.
70-72
: Verify the impact of commenting out path encoding infetchData
.Commenting out the encoding logic may affect how API requests are constructed. Ensure this change is intentional and doesn't disrupt functionality.
src/pages/search.tsx (2)
52-54
: Verify the impact of commenting out path encoding infetchMiscData
.Commenting out the encoding logic may affect how API requests are constructed. Ensure this change is intentional and doesn't disrupt functionality.
72-74
: Verify the impact of commenting out path encoding infetchData
.Commenting out the encoding logic may affect how API requests are constructed. Ensure this change is intentional and doesn't disrupt functionality.
Verification successful
Commenting out path encoding in
fetchData
is likely intentional and non-disruptive.The
decodedQuery
is already decoded usingdecodeURIComponent
before being passed tofetchData
, making the previous encoding step redundant.
src/pages/search.tsx
:decodedQuery
is derived fromsearchQuery
usingdecodeURIComponent
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify if the commented encoding logic affects API requests. # Test: Search for the usage of `fetchData`. Expect: No issues with API requests. rg --type tsx 'fetchData'Length of output: 53
Script:
#!/bin/bash # Description: Verify if the commented encoding logic affects API requests. # Test: Search for the usage of `fetchData` in all files. rg 'fetchData'Length of output: 1122
Script:
#!/bin/bash # Description: Search for the definition and usage of `decodedQuery` in `src/pages/search.tsx`. # Search for `decodedQuery` in `src/pages/search.tsx`. rg 'decodedQuery' src/pages/search.tsxLength of output: 221
src/pages/index.tsx (1)
122-139
: LGTM! Rendering logic fortbUser
is consistent.The conditional rendering of
tbUser
information is consistent with other user types and enhances user experience.src/utils/instantChecks.ts (1)
408-475
: LGTM!The function
instantHashListCheckInTb
is well-implemented and correctly integrates theinstant
property check.src/pages/anime/[animeid].tsx (3)
1-11
: Imports look good!The new imports for TorBox integration are correctly added and align with the new functionality.
66-66
: State management for TorBox is correctly implemented.The
tbKey
state variable is correctly initialized and used in the component.
521-542
: UI enhancements for TorBox are well-integrated.The new buttons for TorBox operations are conditionally rendered and consistent with existing UI patterns.
src/pages/movie/[imdbid].tsx (3)
2-12
: Imports look good!The new imports for TorBox integration are correctly added and align with the new functionality.
67-67
: State management for TorBox is correctly implemented.The
tbKey
state variable is correctly initialized and used in the component.
525-542
: UI enhancements for TorBox are well-integrated.The new buttons for TorBox operations are conditionally rendered and consistent with existing UI patterns.
src/pages/hashlist.tsx (6)
Line range hint
1-42
:
Imports and State Management Look Good!The imports for TorBox integration and the state variable
isClient
are correctly added to support the new functionality.
94-94
: TorBox Integration infetchUserTorrentsList
is Well-Implemented!The addition of TorBox support is consistent with the existing pattern for Real-Debrid and AllDebrid.
287-302
:downloadNonDupeTorrentsInTb
Function is Consistent and Correct!The function aligns with the established pattern for downloading torrents from other services, ensuring consistency.
324-330
:addTb
Function is Implemented Correctly!The function uses the correct utility functions and updates the database appropriately for TorBox.
360-372
:deleteTb
Function is Implemented Correctly!The function follows the correct pattern for deleting torrents and updating the state for TorBox.
Line range hint
445-647
:
Button Rendering Logic for TorBox is Correctly Integrated!The conditional rendering ensures that the UI reflects the availability of the TorBox service, maintaining consistency with other services.
src/pages/show/[imdbid]/[seasonNum].tsx (5)
Line range hint
2-70
:
Imports and State Management Look Good!The imports for TorBox integration and the state variable
tbKey
are correctly added to support the new functionality.
Line range hint
118-176
:
Filtering Logic for TorBox is Well-Integrated!The addition of
tbAvailable
is consistent with the existing logic for other services, ensuring comprehensive filtering.
268-275
:addTb
Function is Implemented Correctly!The function uses the correct utility functions and updates the database appropriately for TorBox.
277-289
:deleteTb
Function is Implemented Correctly!The function follows the correct pattern for deleting torrents and updating the state for TorBox.
585-605
: Button Rendering Logic for TorBox is Correctly Integrated!The conditional rendering ensures that the UI reflects the availability of the TorBox service, maintaining consistency with other services.
src/pages/library.tsx (10)
Line range hint
1-29
: Imports for TorBox Functionality Look Good.The added imports related to TorBox functionality are necessary for the integration and appear to be correctly implemented.
72-72
: State Initialization for TorBox Syncing Looks Good.The
tbSyncing
state variable is initialized correctly and follows the existing pattern for managing loading states of other services.
85-85
: API Key Retrieval for TorBox is Correct.The
useTorBoxApiKey
hook is used consistently with other API key retrievals, ensuring proper integration.
369-375
: Initialization with TorBox Support is Correct.The
initialize
function now includesfetchLatestTBTorrents
, ensuring that TorBox torrents are fetched during the component's initial load.
1178-1188
: Information Display for TorBox Torrents is Well-Implemented.The
handleShowInfoForTB
function is consistent with similar functions for other services, ensuring uniformity in information display.
1523-1531
: Event Handling for TorBox Torrents is Correct.The event handlers have been updated to include logic for TorBox torrents, ensuring they are handled correctly alongside other services.
Also applies to: 1595-1603, 1609-1617, 1642-1650, 1656-1664
1015-1017
: Adding TorBox Magnets is Implemented Correctly.The logic for adding TorBox magnets in
handleAddMagnet
is consistent with the logic for other services, ensuring seamless integration.
1695-1700
: TorBox Torrent Deletion is Properly Handled.The usage of
handleDeleteTbTorrent
is consistent with other deletion functions, ensuring proper handling of TorBox torrent deletions.
1759-1761
: Refreshing TorBox Torrents After Reinsertion is Correct.The invocation of
fetchLatestTBTorrents
after reinserting torrents ensures that the TorBox torrent list is up-to-date.
286-353
: TorBox Torrent Fetching Logic Looks Good.The
fetchLatestTBTorrents
function correctly implements fetching, updating, and deleting logic for TorBox torrents, consistent with other services.Ensure that this function is correctly integrated and invoked where necessary in the codebase.
Verification successful
Function
fetchLatestTBTorrents
is Properly Integrated.The
fetchLatestTBTorrents
function is well-integrated withinsrc/pages/library.tsx
. It is invoked in various contexts, ensuring its functionality is utilized throughout the component.
- Locations of Integration:
- Used within asynchronous operations and callbacks.
- Part of a batch fetch operation alongside other torrent fetching functions.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the integration of `fetchLatestTBTorrents` function. # Test: Search for the function usage. Expect: Occurrences within the initialization and torrent handling logic. rg --type tsx -A 5 $'fetchLatestTBTorrents'Length of output: 70
Script:
#!/bin/bash # Description: Verify the integration of `fetchLatestTBTorrents` function. # Test: Search for the function usage. Expect: Occurrences within the initialization and torrent handling logic. rg --type ts -A 5 $'fetchLatestTBTorrents'Length of output: 2790
@@ -28,6 +28,7 @@ export interface UserTorrent { | |||
speed: number; | |||
rdData?: TorrentInfoResponse; | |||
adData?: MagnetStatus; | |||
tbData?: any; |
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.
Consider specifying a more precise type for tbData
.
Using any
can lead to potential type safety issues. If possible, define a specific type or interface for tbData
to enhance type safety and maintainability.
let size = file.size < 1024 ** 3 ? file.size / 1024 ** 2 : file.size / 1024 ** 3; | ||
let unit = file.size < 1024 ** 3 ? 'MB' : 'GB'; |
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.
Consider using a utility function for file size calculation.
The logic for calculating file size in MB or GB can be abstracted into a utility function to improve readability and maintainability.
function formatFileSize(bytes: number): { size: number, unit: string } {
const size = bytes < 1024 ** 3 ? bytes / 1024 ** 2 : bytes / 1024 ** 3;
const unit = bytes < 1024 ** 3 ? 'MB' : 'GB';
return { size, unit };
}
// Usage
const { size, unit } = formatFileSize(file.size);
@@ -32,7 +32,7 @@ You can share your whole collection or select specific items you want to share. | |||
|
|||
## Setup | |||
|
|||
0. Signup for a free tier plan at [PlanetScale](https://planetscale.com/) - this is a serverless MySQL database hosted in the cloud | |||
0. Signup for a free tier plan at [Filess](https://filess.io/) - this is a serverless MySQL database hosted in the cloud |
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.
Update database connection instructions.
The instructions still mention getting a connection string from PlanetScale, which should be updated to reflect the new database service, Filess.
- Get your Prisma database connection string from PlanetScale console
+ Get your Prisma database connection string from Filess console
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.
0. Signup for a free tier plan at [Filess](https://filess.io/) - this is a serverless MySQL database hosted in the cloud | |
0. Signup for a free tier plan at [Filess](https://filess.io/) - this is a serverless MySQL database hosted in the cloud | |
Get your Prisma database connection string from Filess console |
export const handleAddAsMagnetInTb = async ( | ||
tbKey: string, | ||
hash: string, | ||
callback?: () => Promise<void> | ||
) => { | ||
try { | ||
await createTorBoxTorrent(tbKey, [hash]); | ||
if (callback) await callback(); | ||
toast('Successfully added torrent to TorBox!', magnetToastOptions); | ||
} catch (error) { | ||
toast.error(error as any); | ||
throw error; | ||
} | ||
}; |
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.
Improve error handling in handleAddAsMagnetInTb
.
The error message is directly passed to the toast. Consider providing a more user-friendly message.
toast.error('Failed to add torrent to TorBox. Please try again.');
Hopefully with today's news it'll kick this PR and also debridmediamanager/zurg-testing#106 up a notch in terms of getting TorBox supported fully. |
Adds support for TorBox in DMM!
Please make sure to go through and check things are correct. There was testing done, but we might have missed something small. We are also not sure about hash list support as it looks like it is on a different site.
We also changed some things in the Readme regarding TorBox support, and also changed the Database used (previously PlanetScale) and also changed the Proxy used (previously proxyme.org).
Note: there were some issues with rendering on /hashlist, maybe it is because there was no way to really locally test, but do some testing on that page specifically.
Further concerning hashlists, it seems as though the hashlist site has code elsewhere, with RD and AD specific code that will need to be modified.
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Style