mirror of
https://codeberg.org/icewind/shelve.git
synced 2026-06-03 12:04:09 +02:00
clippy fixes
This commit is contained in:
parent
97c05ed684
commit
7cb6ab9d61
2 changed files with 23 additions and 15 deletions
|
|
@ -61,7 +61,7 @@ impl UploadId {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_expired(&self, time: u64) -> bool {
|
pub fn is_expired(&self, time: u64) -> bool {
|
||||||
return time >= self.get_expire();
|
time >= self.get_expire()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_string(&self) -> String {
|
pub fn as_string(&self) -> String {
|
||||||
|
|
@ -87,7 +87,7 @@ pub struct Expiration(u64);
|
||||||
impl PartialOrd for Expiration {
|
impl PartialOrd for Expiration {
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
// reverse the order so sort nearest expiration time first
|
// reverse the order so sort nearest expiration time first
|
||||||
other.0.partial_cmp(&self.0)
|
Some(other.0.cmp(&self.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
22
src/main.rs
22
src/main.rs
|
|
@ -103,7 +103,7 @@ async fn put_upload(
|
||||||
#[derive(Debug, Responder)]
|
#[derive(Debug, Responder)]
|
||||||
enum UploadResponse {
|
enum UploadResponse {
|
||||||
Data(String),
|
Data(String),
|
||||||
Redirect(Redirect),
|
Redirect(Box<Redirect>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
|
@ -144,7 +144,7 @@ async fn post_upload(
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
UploadResponse::Redirect(Redirect::to("/?error=invalid%20token"))
|
UploadResponse::Redirect(Box::new(Redirect::to("/?error=invalid%20token")))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match try_join_all(data.files.into_iter().filter(|file| file.len() > 0).map(
|
match try_join_all(data.files.into_iter().filter(|file| file.len() > 0).map(
|
||||||
|
|
@ -177,7 +177,7 @@ async fn post_upload(
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
UploadResponse::Redirect(Redirect::to(""))
|
UploadResponse::Redirect(Box::new(Redirect::to("")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => UploadResponse::Data(
|
Err(e) => UploadResponse::Data(
|
||||||
|
|
@ -241,8 +241,15 @@ fn rocket() -> _ {
|
||||||
|
|
||||||
fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<()> {
|
fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<()> {
|
||||||
spawn(move || {
|
spawn(move || {
|
||||||
for dir_entry in read_dir(&expire_basedir).expect("Failed to list base directory") {
|
let entries = match read_dir(&expire_basedir) {
|
||||||
if let Ok(entry) = dir_entry {
|
Ok(entries) => entries,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Failed to list base directory: {e:#}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for entry in entries.flatten() {
|
||||||
if let Some(upload_id) = entry
|
if let Some(upload_id) = entry
|
||||||
.file_name()
|
.file_name()
|
||||||
.to_str()
|
.to_str()
|
||||||
|
|
@ -251,7 +258,6 @@ fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<
|
||||||
expire_queue.push(upload_id);
|
expire_queue.push(upload_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
for expired in expire_queue.get_expired(now()) {
|
for expired in expire_queue.get_expired(now()) {
|
||||||
|
|
@ -266,7 +272,9 @@ fn expire_job(expire_basedir: PathBuf, expire_queue: ExpireQueue) -> JoinHandle<
|
||||||
fn filename_ext(name: &FileName) -> Option<&str> {
|
fn filename_ext(name: &FileName) -> Option<&str> {
|
||||||
let raw = name.dangerous_unsafe_unsanitized_raw().as_str();
|
let raw = name.dangerous_unsafe_unsanitized_raw().as_str();
|
||||||
let (name, ext) = raw.split_once('.')?;
|
let (name, ext) = raw.split_once('.')?;
|
||||||
if name.len() > 0 && ext.len() < 8 && ext.chars().all(|c| c.is_ascii_alphanumeric() || c == '.')
|
if !name.is_empty()
|
||||||
|
&& ext.len() < 8
|
||||||
|
&& ext.chars().all(|c| c.is_ascii_alphanumeric() || c == '.')
|
||||||
{
|
{
|
||||||
Some(ext)
|
Some(ext)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue