From c3c413c14b06244846938e2bd47f1ec3c069fc2a Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Thu, 7 Nov 2024 16:07:16 +0000 Subject: [PATCH] Do not display padding files in UI --- crates/librqbit/src/api.rs | 4 ++- crates/librqbit/webui/src/api-types.ts | 8 ++++++ .../webui/src/components/FileListInput.tsx | 28 ++++++++++--------- crates/librqbit_core/src/torrent_metainfo.rs | 2 +- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/crates/librqbit/src/api.rs b/crates/librqbit/src/api.rs index aea4aba7..230274ca 100644 --- a/crates/librqbit/src/api.rs +++ b/crates/librqbit/src/api.rs @@ -4,7 +4,7 @@ use anyhow::Context; use buffers::ByteBufOwned; use dht::{DhtStats, Id20}; use http::StatusCode; -use librqbit_core::torrent_metainfo::TorrentMetaV1Info; +use librqbit_core::torrent_metainfo::{FileDetailsAttrs, TorrentMetaV1Info}; use serde::{Deserialize, Serialize}; use tokio::sync::mpsc::UnboundedSender; use tracing::warn; @@ -498,6 +498,7 @@ pub struct TorrentDetailsResponseFile { pub components: Vec, pub length: u64, pub included: bool, + pub attributes: FileDetailsAttrs, } #[derive(Default, Serialize)] @@ -551,6 +552,7 @@ fn make_torrent_details( components, length: d.len, included, + attributes: d.attrs(), } }) .collect(); diff --git a/crates/librqbit/webui/src/api-types.ts b/crates/librqbit/webui/src/api-types.ts index c62197aa..58436e7f 100644 --- a/crates/librqbit/webui/src/api-types.ts +++ b/crates/librqbit/webui/src/api-types.ts @@ -9,6 +9,14 @@ export interface TorrentFile { components: string[]; length: number; included: boolean; + attributes: TorrentFileAttributes; +} + +export interface TorrentFileAttributes { + symlink: boolean; + hidden: boolean; + padding: boolean; + executable: boolean; } // Interface for the Torrent Details API response diff --git a/crates/librqbit/webui/src/components/FileListInput.tsx b/crates/librqbit/webui/src/components/FileListInput.tsx index 323ba1c0..ba3c9dcf 100644 --- a/crates/librqbit/webui/src/components/FileListInput.tsx +++ b/crates/librqbit/webui/src/components/FileListInput.tsx @@ -73,15 +73,20 @@ const newFileTree = ( return newFileTreeInner( "", "filetree-root", - torrentDetails.files.map((file, id) => { - return { - id, - filename: file.components[file.components.length - 1], - pathComponents: file.components, - length: file.length, - have_bytes: stats ? stats.file_progress[id] ?? 0 : 0, - }; - }), + torrentDetails.files + .map((file, id) => { + if (file.attributes.padding) { + return null; + } + return { + id, + filename: file.components[file.components.length - 1], + pathComponents: file.components, + length: file.length, + have_bytes: stats ? (stats.file_progress[id] ?? 0) : 0, + }; + }) + .filter((f) => f !== null), 0, ); }; @@ -156,10 +161,7 @@ const FileTreeComponent: React.FC<{ }; const fileLink = (file: TorrentFileForCheckbox) => { - if ( - allowStream && - torrentId != null - ) { + if (allowStream && torrentId != null) { return API.getTorrentStreamUrl(torrentId, file.id, file.filename); } }; diff --git a/crates/librqbit_core/src/torrent_metainfo.rs b/crates/librqbit_core/src/torrent_metainfo.rs index 89aa1850..2a22a90f 100644 --- a/crates/librqbit_core/src/torrent_metainfo.rs +++ b/crates/librqbit_core/src/torrent_metainfo.rs @@ -185,7 +185,7 @@ where } } -#[derive(Default, Debug, Clone, Copy)] +#[derive(Serialize, Deserialize, Default, Debug, Clone, Copy)] pub struct FileDetailsAttrs { pub symlink: bool, pub hidden: bool,