Skip to content

Commit

Permalink
Merge pull request #270 from ikatson/bep-47-2
Browse files Browse the repository at this point in the history
BEP-47 - UI support and updates
  • Loading branch information
ikatson authored Nov 7, 2024
2 parents cc002a4 + c3c413c commit 8d2aa93
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
4 changes: 3 additions & 1 deletion crates/librqbit/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -498,6 +498,7 @@ pub struct TorrentDetailsResponseFile {
pub components: Vec<String>,
pub length: u64,
pub included: bool,
pub attributes: FileDetailsAttrs,
}

#[derive(Default, Serialize)]
Expand Down Expand Up @@ -551,6 +552,7 @@ fn make_torrent_details(
components,
length: d.len,
included,
attributes: d.attrs(),
}
})
.collect();
Expand Down
30 changes: 14 additions & 16 deletions crates/librqbit/src/storage/filesystem/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,19 @@ impl TorrentStorage for FilesystemStorage {
let relative_path = &file_details.relative_filename;
full_path.push(relative_path);

if file_details.attrs.padding {
files.push(OpenedFile::new_dummy());
continue;
};
std::fs::create_dir_all(full_path.parent().context("bug: no parent")?)?;
let file = if file_details.attrs.padding {
OpenedFile::new_dummy()
} else if meta.options.allow_overwrite {
OpenedFile::new(
OpenOptions::new()
.create(true)
.truncate(false)
.read(true)
.write(true)
.open(&full_path)
.with_context(|| {
format!("error opening {full_path:?} in read/write mode")
})?,
)
let f = if meta.options.allow_overwrite {
OpenOptions::new()
.create(true)
.truncate(false)
.read(true)
.write(true)
.open(&full_path)
.with_context(|| format!("error opening {full_path:?} in read/write mode"))?
} else {
// create_new does not seem to work with read(true), so calling this twice.
OpenOptions::new()
Expand All @@ -183,9 +181,9 @@ impl TorrentStorage for FilesystemStorage {
&full_path
)
})?;
OpenedFile::new(OpenOptions::new().read(true).write(true).open(&full_path)?)
OpenOptions::new().read(true).write(true).open(&full_path)?
};
files.push(file);
files.push(OpenedFile::new(f));
}

self.opened_files = files;
Expand Down
8 changes: 8 additions & 0 deletions crates/librqbit/webui/src/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 15 additions & 13 deletions crates/librqbit/webui/src/components/FileListInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
};
Expand Down Expand Up @@ -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);
}
};
Expand Down
2 changes: 1 addition & 1 deletion crates/librqbit_core/src/torrent_metainfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8d2aa93

Please sign in to comment.