From 5975552105c57874a12496559ba484378e554957 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 11 Aug 2025 17:38:20 +0300 Subject: [PATCH] use local File type --- src/public.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/public.rs b/src/public.rs index 34327bf..2264eba 100644 --- a/src/public.rs +++ b/src/public.rs @@ -1,12 +1,13 @@ use chrono::{DateTime, Utc}; -use std::{ - fs::{self, DirEntry}, - io::Error, - path::PathBuf, -}; +use std::{fs, io::Error, path::PathBuf, time::SystemTime}; const EXTENSION: &str = "torrent"; +struct File { + modified: SystemTime, + path: PathBuf, +} + #[derive(Clone, Debug, Default)] pub enum Sort { #[default] @@ -73,8 +74,8 @@ impl Public { let mut b = Vec::with_capacity(l); for file in f.into_iter().skip(start.unwrap_or_default()).take(l) { b.push(Torrent { - bytes: fs::read(file.path())?, - time: file.metadata()?.modified()?.into(), + bytes: fs::read(file.path)?, + time: file.modified.into(), }) } Ok((t, b)) @@ -101,7 +102,7 @@ impl Public { &self, keyword: Option<&str>, sort_order: Option<(Sort, Order)>, - ) -> Result, Error> { + ) -> Result, Error> { let mut b = Vec::with_capacity(self.default_capacity); for entry in fs::read_dir(&self.root)? { let e = entry?; @@ -130,16 +131,19 @@ impl Public { }) { continue; } - b.push((e.metadata()?.modified()?, e)) + b.push(File { + path: e.path(), + modified: e.metadata()?.modified()?, + }) } if let Some((sort, order)) = sort_order { match sort { Sort::Modified => match order { - Order::Asc => b.sort_by(|a, b| a.0.cmp(&b.0)), - Order::Desc => b.sort_by(|a, b| b.0.cmp(&a.0)), + Order::Asc => b.sort_by(|a, b| a.modified.cmp(&b.modified)), + Order::Desc => b.sort_by(|a, b| b.modified.cmp(&a.modified)), }, } } - Ok(b.into_iter().map(|e| e.1).collect()) + Ok(b) } }