Merge pull request #270 from ikatson/bep-47-2

BEP-47 - UI support and updates
This commit is contained in:
Igor Katson 2024-11-07 16:14:08 +00:00 committed by GitHub
commit 8d2aa93a78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 31 deletions

View file

@ -4,7 +4,7 @@ use anyhow::Context;
use buffers::ByteBufOwned; use buffers::ByteBufOwned;
use dht::{DhtStats, Id20}; use dht::{DhtStats, Id20};
use http::StatusCode; use http::StatusCode;
use librqbit_core::torrent_metainfo::TorrentMetaV1Info; use librqbit_core::torrent_metainfo::{FileDetailsAttrs, TorrentMetaV1Info};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::UnboundedSender; use tokio::sync::mpsc::UnboundedSender;
use tracing::warn; use tracing::warn;
@ -498,6 +498,7 @@ pub struct TorrentDetailsResponseFile {
pub components: Vec<String>, pub components: Vec<String>,
pub length: u64, pub length: u64,
pub included: bool, pub included: bool,
pub attributes: FileDetailsAttrs,
} }
#[derive(Default, Serialize)] #[derive(Default, Serialize)]
@ -551,6 +552,7 @@ fn make_torrent_details(
components, components,
length: d.len, length: d.len,
included, included,
attributes: d.attrs(),
} }
}) })
.collect(); .collect();

View file

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

View file

@ -9,6 +9,14 @@ export interface TorrentFile {
components: string[]; components: string[];
length: number; length: number;
included: boolean; included: boolean;
attributes: TorrentFileAttributes;
}
export interface TorrentFileAttributes {
symlink: boolean;
hidden: boolean;
padding: boolean;
executable: boolean;
} }
// Interface for the Torrent Details API response // Interface for the Torrent Details API response

View file

@ -73,15 +73,20 @@ const newFileTree = (
return newFileTreeInner( return newFileTreeInner(
"", "",
"filetree-root", "filetree-root",
torrentDetails.files.map((file, id) => { torrentDetails.files
return { .map((file, id) => {
id, if (file.attributes.padding) {
filename: file.components[file.components.length - 1], return null;
pathComponents: file.components, }
length: file.length, return {
have_bytes: stats ? stats.file_progress[id] ?? 0 : 0, 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, 0,
); );
}; };
@ -156,10 +161,7 @@ const FileTreeComponent: React.FC<{
}; };
const fileLink = (file: TorrentFileForCheckbox) => { const fileLink = (file: TorrentFileForCheckbox) => {
if ( if (allowStream && torrentId != null) {
allowStream &&
torrentId != null
) {
return API.getTorrentStreamUrl(torrentId, file.id, file.filename); return API.getTorrentStreamUrl(torrentId, file.id, file.filename);
} }
}; };

View file

@ -185,7 +185,7 @@ where
} }
} }
#[derive(Default, Debug, Clone, Copy)] #[derive(Serialize, Deserialize, Default, Debug, Clone, Copy)]
pub struct FileDetailsAttrs { pub struct FileDetailsAttrs {
pub symlink: bool, pub symlink: bool,
pub hidden: bool, pub hidden: bool,