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

feat: implement BEP-53 support #248

Merged
merged 5 commits into from
Oct 2, 2024

Conversation

PastaPastaPasta
Copy link
Contributor

Implement support for BEP-53 Select Only magnet extension

This does not include full support in the GUI / web interface. When initially adding a torrent with SO, the gui will show ALL as selected, even though the actual download will only download the sections needed for that file. Once a torrent has been added, the file list then becomes accurate.

See below patch, for how I tried to have the UI be reactive to so= however, this patch didn't work. I'd love to get feedback on a patch that works, but even without I think this PR is valuable and net positive

diff --git a/crates/librqbit/webui/src/components/modal/FileSelectionModal.tsx b/crates/librqbit/webui/src/components/modal/FileSelectionModal.tsx
index 0a41f33..d767c60 100644
--- a/crates/librqbit/webui/src/components/modal/FileSelectionModal.tsx
+++ b/crates/librqbit/webui/src/components/modal/FileSelectionModal.tsx
@@ -1,5 +1,5 @@
 import { useContext, useEffect, useState } from "react";
-import { AddTorrentResponse, AddTorrentOptions } from "../../api-types";
+import {AddTorrentResponse, AddTorrentOptions, TorrentDetails} from "../../api-types";
 import { APIContext } from "../../context";
 import { ErrorComponent } from "../ErrorComponent";
 import { ErrorWithLabel } from "../../rqbit-web";
@@ -34,6 +34,8 @@ export const FileSelectionModal = (props: {
   const [uploadError, setUploadError] = useState<ErrorWithLabel | null>(null);
   const [unpopularTorrent, setUnpopularTorrent] = useState(false);
   const [outputFolder, setOutputFolder] = useState<string>("");
+  const [detailsResponse, updateDetailsResponse] =
+      useState<TorrentDetails | null>(null);
   const refreshTorrents = useTorrentStore((state) => state.refreshTorrents);
   const API = useContext(APIContext);
 
@@ -76,6 +78,18 @@ export const FileSelectionModal = (props: {
         () => {
           onHide();
           refreshTorrents();
+          useEffect(() => {
+            console.log('trying to set selected files');
+            setSelectedFiles(
+                new Set<number>(
+                    detailsResponse?.files
+                        .map((f, id) => ({ f, id }))
+                        .filter(({ f }) => f.included)
+                        .map(({ id }) => id) ?? []
+                )
+            );
+          }, [detailsResponse]);
+
         },
         (e) => {
           setUploadError({ text: "Error starting torrent", details: e });

@ikatson
Copy link
Owner

ikatson commented Oct 2, 2024

Thanks @PastaPastaPasta for the PR! Agree it makes sense even without UI support, so can merge this first. Added a few minor comments, should be very quick to address.

@ikatson ikatson merged commit 7ca3232 into ikatson:main Oct 2, 2024
6 checks passed
@PastaPastaPasta PastaPastaPasta deleted the feat/bep-53-support branch October 2, 2024 20:30
@ikatson
Copy link
Owner

ikatson commented Oct 2, 2024

@PastaPastaPasta if you want to fix the UI, I think an easy fix would be to:

  1. in Rust, include only_files as part of AddTorrentResponse, including list_only. This would carry "so" and only_files logic all the way back through the API to JS
  2. In JS FileSelectionModal, use that instead of this piece
setSelectedFiles(
    new Set(listTorrentResponse?.details.files.map((_, i) => i)),
);

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.

3 participants