cleanup of various clippy lints, bad practices and simplificaiton of some code
Signed-off-by: Jade <obsidianical@gmail.com>
This commit is contained in:
parent
fa67edc8c5
commit
528a7b6899
11 changed files with 34 additions and 45 deletions
|
@ -37,7 +37,7 @@ pub async fn create(
|
|||
.finish());
|
||||
}
|
||||
|
||||
let mut pastas = data.pastas.lock().unwrap();
|
||||
let mut pastas = data.pastas.lock().await;
|
||||
|
||||
let timenow: i64 = match SystemTime::now().duration_since(UNIX_EPOCH) {
|
||||
Ok(n) => n.as_secs(),
|
||||
|
@ -65,18 +65,15 @@ pub async fn create(
|
|||
while let Some(mut field) = payload.try_next().await? {
|
||||
match field.name() {
|
||||
"editable" => {
|
||||
// while let Some(_chunk) = field.try_next().await? {}
|
||||
new_pasta.editable = true;
|
||||
continue;
|
||||
}
|
||||
"private" => {
|
||||
// while let Some(_chunk) = field.try_next().await? {}
|
||||
new_pasta.private = true;
|
||||
continue;
|
||||
}
|
||||
"expiration" => {
|
||||
while let Some(chunk) = field.try_next().await? {
|
||||
new_pasta.expiration = match std::str::from_utf8(&chunk).unwrap() {
|
||||
// TODO: customizable times
|
||||
"1min" => timenow + 60,
|
||||
"10min" => timenow + 60 * 10,
|
||||
"1hour" => timenow + 60 * 60,
|
||||
|
@ -96,12 +93,12 @@ pub async fn create(
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
"burn_after" => {
|
||||
while let Some(chunk) = field.try_next().await? {
|
||||
new_pasta.burn_after_reads = match std::str::from_utf8(&chunk).unwrap() {
|
||||
// TODO: also make customizable
|
||||
// maybe options in config files, with defaults
|
||||
// give an extra read because the user will be redirected to the pasta page automatically
|
||||
"1" => 2,
|
||||
"10" => 10,
|
||||
|
@ -115,8 +112,6 @@ pub async fn create(
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
"content" => {
|
||||
let mut content = String::from("");
|
||||
|
@ -132,13 +127,11 @@ pub async fn create(
|
|||
String::from("text")
|
||||
};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
"syntax-highlight" => {
|
||||
while let Some(chunk) = field.try_next().await? {
|
||||
new_pasta.extension = std::str::from_utf8(&chunk).unwrap().to_string();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
"file" => {
|
||||
if ARGS.no_file_upload {
|
||||
|
|
|
@ -19,7 +19,7 @@ struct EditTemplate<'a> {
|
|||
|
||||
#[get("/edit/{id}")]
|
||||
pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpResponse {
|
||||
let mut pastas = data.pastas.lock().unwrap();
|
||||
let mut pastas = data.pastas.lock().await;
|
||||
|
||||
let id = if ARGS.hash_ids {
|
||||
hashid_to_u64(&id).unwrap_or(0)
|
||||
|
@ -65,7 +65,7 @@ pub async fn post_edit(
|
|||
to_u64(&id.into_inner()).unwrap_or(0)
|
||||
};
|
||||
|
||||
let mut pastas = data.pastas.lock().unwrap();
|
||||
let mut pastas = data.pastas.lock().await;
|
||||
|
||||
remove_expired(&mut pastas);
|
||||
|
||||
|
|
|
@ -9,15 +9,15 @@ use askama::Template;
|
|||
struct Info<'a> {
|
||||
args: &'a Args,
|
||||
pastas: &'a Vec<Pasta>,
|
||||
status: &'a String,
|
||||
version_string: &'a String,
|
||||
message: &'a String,
|
||||
status: &'a str,
|
||||
version_string: &'a str,
|
||||
message: &'a str,
|
||||
}
|
||||
|
||||
#[get("/info")]
|
||||
pub async fn info(data: web::Data<AppState>) -> HttpResponse {
|
||||
// get access to the pasta collection
|
||||
let pastas = data.pastas.lock().unwrap();
|
||||
let pastas = data.pastas.lock().await;
|
||||
|
||||
// todo status report more sophisticated
|
||||
let mut status = "OK";
|
||||
|
@ -32,9 +32,9 @@ pub async fn info(data: web::Data<AppState>) -> HttpResponse {
|
|||
Info {
|
||||
args: &ARGS,
|
||||
pastas: &pastas,
|
||||
status: &String::from(status),
|
||||
version_string: &String::from("1.2.0-20221107"),
|
||||
message: &String::from(message),
|
||||
status,
|
||||
version_string: env!("CARGO_PKG_VERSION"),
|
||||
message
|
||||
}
|
||||
.render()
|
||||
.unwrap(),
|
||||
|
|
|
@ -21,7 +21,7 @@ struct PastaTemplate<'a> {
|
|||
#[get("/pasta/{id}")]
|
||||
pub async fn getpasta(data: web::Data<AppState>, id: web::Path<String>) -> HttpResponse {
|
||||
// get access to the pasta collection
|
||||
let mut pastas = data.pastas.lock().unwrap();
|
||||
let mut pastas = data.pastas.lock().await;
|
||||
|
||||
let id = if ARGS.hash_ids {
|
||||
hashid_to_u64(&id).unwrap_or(0)
|
||||
|
@ -85,7 +85,7 @@ pub async fn getpasta(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
|
|||
#[get("/url/{id}")]
|
||||
pub async fn redirecturl(data: web::Data<AppState>, id: web::Path<String>) -> HttpResponse {
|
||||
// get access to the pasta collection
|
||||
let mut pastas = data.pastas.lock().unwrap();
|
||||
let mut pastas = data.pastas.lock().await;
|
||||
|
||||
let id = if ARGS.hash_ids {
|
||||
hashid_to_u64(&id).unwrap_or(0)
|
||||
|
@ -152,7 +152,7 @@ pub async fn redirecturl(data: web::Data<AppState>, id: web::Path<String>) -> Ht
|
|||
#[get("/raw/{id}")]
|
||||
pub async fn getrawpasta(data: web::Data<AppState>, id: web::Path<String>) -> String {
|
||||
// get access to the pasta collection
|
||||
let mut pastas = data.pastas.lock().unwrap();
|
||||
let mut pastas = data.pastas.lock().await;
|
||||
|
||||
let id = if ARGS.hash_ids {
|
||||
hashid_to_u64(&id).unwrap_or(0)
|
||||
|
|
|
@ -21,7 +21,7 @@ pub async fn list(data: web::Data<AppState>) -> HttpResponse {
|
|||
.finish();
|
||||
}
|
||||
|
||||
let mut pastas = data.pastas.lock().unwrap();
|
||||
let mut pastas = data.pastas.lock().await;
|
||||
|
||||
remove_expired(&mut pastas);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ struct QRTemplate<'a> {
|
|||
#[get("/qr/{id}")]
|
||||
pub async fn getqr(data: web::Data<AppState>, id: web::Path<String>) -> HttpResponse {
|
||||
// get access to the pasta collection
|
||||
let mut pastas = data.pastas.lock().unwrap();
|
||||
let mut pastas = data.pastas.lock().await;
|
||||
|
||||
let u64_id = if ARGS.hash_ids {
|
||||
hashid_to_u64(&id).unwrap_or(0)
|
||||
|
|
|
@ -18,7 +18,7 @@ pub async fn remove(data: web::Data<AppState>, id: web::Path<String>) -> HttpRes
|
|||
.finish();
|
||||
}
|
||||
|
||||
let mut pastas = data.pastas.lock().unwrap();
|
||||
let mut pastas = data.pastas.lock().await;
|
||||
|
||||
let id = if ARGS.hash_ids {
|
||||
hashid_to_u64(&id).unwrap_or(0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue