mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
store file names as the PathBuf
This commit is contained in:
parent
88dfbab0f7
commit
bff6b209c9
4 changed files with 20 additions and 27 deletions
|
|
@ -102,7 +102,7 @@ fn info(
|
|||
#[derive(Serialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
struct F {
|
||||
name: String,
|
||||
path: String,
|
||||
size: String,
|
||||
}
|
||||
let torrent = Torrent::from_storage(&t.bytes, t.time).map_err(|e| {
|
||||
|
|
@ -118,7 +118,7 @@ fn info(
|
|||
files_list: torrent.files.as_ref().map(|f| {
|
||||
f.iter()
|
||||
.map(|f| F {
|
||||
name: f.name(),
|
||||
path: f.path(),
|
||||
size: f.size(),
|
||||
})
|
||||
.collect::<Vec<F>>()
|
||||
|
|
|
|||
|
|
@ -44,28 +44,20 @@ impl Torrent {
|
|||
.unwrap_or_default(),
|
||||
files: i.info.files.map(|files| {
|
||||
let mut b = Vec::with_capacity(files.len());
|
||||
for f in files.iter() {
|
||||
for f in files {
|
||||
let mut p = std::path::PathBuf::new();
|
||||
b.push(File {
|
||||
name: String::from_utf8(
|
||||
f.path
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(n, b)| {
|
||||
if n == 0 {
|
||||
b.0.to_vec()
|
||||
} else {
|
||||
let mut p = vec![b'/'];
|
||||
p.extend(b.0.to_vec());
|
||||
p
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
.ok(),
|
||||
length: f.length,
|
||||
path: match f.full_path(&mut p) {
|
||||
Ok(()) => Some(p),
|
||||
Err(e) => {
|
||||
warn!("Filename decode error: {e}");
|
||||
None
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
b.sort_by(|a, b| a.name.cmp(&b.name)); // @TODO optional
|
||||
b.sort_by(|a, b| a.path.cmp(&b.path)); // @TODO optional
|
||||
b
|
||||
}),
|
||||
publisher_url: i.publisher_url.map(|u| u.to_string()),
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
use rocket::serde::Serialize;
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[derive(Clone, Debug, rocket::serde::Serialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct File {
|
||||
pub name: Option<String>,
|
||||
pub path: Option<std::path::PathBuf>,
|
||||
pub length: u64,
|
||||
}
|
||||
|
||||
impl File {
|
||||
pub fn name(&self) -> String {
|
||||
self.name.as_deref().unwrap_or("?").into()
|
||||
pub fn path(&self) -> String {
|
||||
self.path
|
||||
.as_ref()
|
||||
.map(|p| p.to_string_lossy().into())
|
||||
.unwrap_or("?".into())
|
||||
}
|
||||
pub fn size(&self) -> String {
|
||||
super::size(self.length)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue