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)]
|
#[derive(Serialize)]
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
struct F {
|
struct F {
|
||||||
name: String,
|
path: String,
|
||||||
size: String,
|
size: String,
|
||||||
}
|
}
|
||||||
let torrent = Torrent::from_storage(&t.bytes, t.time).map_err(|e| {
|
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| {
|
files_list: torrent.files.as_ref().map(|f| {
|
||||||
f.iter()
|
f.iter()
|
||||||
.map(|f| F {
|
.map(|f| F {
|
||||||
name: f.name(),
|
path: f.path(),
|
||||||
size: f.size(),
|
size: f.size(),
|
||||||
})
|
})
|
||||||
.collect::<Vec<F>>()
|
.collect::<Vec<F>>()
|
||||||
|
|
|
||||||
|
|
@ -44,28 +44,20 @@ impl Torrent {
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
files: i.info.files.map(|files| {
|
files: i.info.files.map(|files| {
|
||||||
let mut b = Vec::with_capacity(files.len());
|
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 {
|
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,
|
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
|
b
|
||||||
}),
|
}),
|
||||||
publisher_url: i.publisher_url.map(|u| u.to_string()),
|
publisher_url: i.publisher_url.map(|u| u.to_string()),
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
use rocket::serde::Serialize;
|
#[derive(Clone, Debug, rocket::serde::Serialize)]
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
|
||||||
#[serde(crate = "rocket::serde")]
|
#[serde(crate = "rocket::serde")]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub name: Option<String>,
|
pub path: Option<std::path::PathBuf>,
|
||||||
pub length: u64,
|
pub length: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
pub fn name(&self) -> String {
|
pub fn path(&self) -> String {
|
||||||
self.name.as_deref().unwrap_or("?").into()
|
self.path
|
||||||
|
.as_ref()
|
||||||
|
.map(|p| p.to_string_lossy().into())
|
||||||
|
.unwrap_or("?".into())
|
||||||
}
|
}
|
||||||
pub fn size(&self) -> String {
|
pub fn size(&self) -> String {
|
||||||
super::size(self.length)
|
super::size(self.length)
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for file in files_list %}
|
{% for file in files_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ file.name }}</td>
|
<td>{{ file.path }}</td>
|
||||||
<td>{{ file.size }}</td>
|
<td>{{ file.size }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue