mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 09:05:30 +00:00
use local File type
This commit is contained in:
parent
a0a5610f9b
commit
5975552105
1 changed files with 16 additions and 12 deletions
|
|
@ -1,12 +1,13 @@
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use std::{
|
use std::{fs, io::Error, path::PathBuf, time::SystemTime};
|
||||||
fs::{self, DirEntry},
|
|
||||||
io::Error,
|
|
||||||
path::PathBuf,
|
|
||||||
};
|
|
||||||
|
|
||||||
const EXTENSION: &str = "torrent";
|
const EXTENSION: &str = "torrent";
|
||||||
|
|
||||||
|
struct File {
|
||||||
|
modified: SystemTime,
|
||||||
|
path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub enum Sort {
|
pub enum Sort {
|
||||||
#[default]
|
#[default]
|
||||||
|
|
@ -73,8 +74,8 @@ impl Public {
|
||||||
let mut b = Vec::with_capacity(l);
|
let mut b = Vec::with_capacity(l);
|
||||||
for file in f.into_iter().skip(start.unwrap_or_default()).take(l) {
|
for file in f.into_iter().skip(start.unwrap_or_default()).take(l) {
|
||||||
b.push(Torrent {
|
b.push(Torrent {
|
||||||
bytes: fs::read(file.path())?,
|
bytes: fs::read(file.path)?,
|
||||||
time: file.metadata()?.modified()?.into(),
|
time: file.modified.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Ok((t, b))
|
Ok((t, b))
|
||||||
|
|
@ -101,7 +102,7 @@ impl Public {
|
||||||
&self,
|
&self,
|
||||||
keyword: Option<&str>,
|
keyword: Option<&str>,
|
||||||
sort_order: Option<(Sort, Order)>,
|
sort_order: Option<(Sort, Order)>,
|
||||||
) -> Result<Vec<DirEntry>, Error> {
|
) -> Result<Vec<File>, Error> {
|
||||||
let mut b = Vec::with_capacity(self.default_capacity);
|
let mut b = Vec::with_capacity(self.default_capacity);
|
||||||
for entry in fs::read_dir(&self.root)? {
|
for entry in fs::read_dir(&self.root)? {
|
||||||
let e = entry?;
|
let e = entry?;
|
||||||
|
|
@ -130,16 +131,19 @@ impl Public {
|
||||||
}) {
|
}) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
b.push((e.metadata()?.modified()?, e))
|
b.push(File {
|
||||||
|
path: e.path(),
|
||||||
|
modified: e.metadata()?.modified()?,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if let Some((sort, order)) = sort_order {
|
if let Some((sort, order)) = sort_order {
|
||||||
match sort {
|
match sort {
|
||||||
Sort::Modified => match order {
|
Sort::Modified => match order {
|
||||||
Order::Asc => b.sort_by(|a, b| a.0.cmp(&b.0)),
|
Order::Asc => b.sort_by(|a, b| a.modified.cmp(&b.modified)),
|
||||||
Order::Desc => b.sort_by(|a, b| b.0.cmp(&a.0)),
|
Order::Desc => b.sort_by(|a, b| b.modified.cmp(&a.modified)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(b.into_iter().map(|e| e.1).collect())
|
Ok(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue