Quick patch:
- Changed 302 responses to 200 where needed - Fixed a bug where expiring pastas cause MicroBin to crahs - Fixed a bug where water.css didn't have the correct MIME type - Fixed a bug where missing doctype declaration caused styling issues in Firefox
This commit is contained in:
parent
35d4df2cb8
commit
be3ac27920
10 changed files with 32 additions and 25 deletions
|
@ -18,7 +18,7 @@ struct IndexTemplate<'a> {
|
|||
|
||||
#[get("/")]
|
||||
pub async fn index() -> impl Responder {
|
||||
HttpResponse::Found()
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body(IndexTemplate { args: &ARGS }.render().unwrap())
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
|
|||
.append_header(("Location", "/"))
|
||||
.finish();
|
||||
}
|
||||
return HttpResponse::Found().content_type("text/html").body(
|
||||
return HttpResponse::Ok().content_type("text/html").body(
|
||||
EditTemplate {
|
||||
pasta: &pasta,
|
||||
args: &ARGS,
|
||||
|
@ -42,7 +42,7 @@ pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
|
|||
}
|
||||
}
|
||||
|
||||
HttpResponse::Found()
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ pub async fn post_edit(
|
|||
}
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Found()
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ pub struct ErrorTemplate<'a> {
|
|||
}
|
||||
|
||||
pub async fn not_found() -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::Found()
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ struct Help<'a> {
|
|||
|
||||
#[get("/help")]
|
||||
pub async fn help() -> HttpResponse {
|
||||
HttpResponse::Found().content_type("text/html").body(
|
||||
HttpResponse::Ok().content_type("text/html").body(
|
||||
Help {
|
||||
args: &ARGS,
|
||||
_marker: Default::default(),
|
||||
|
|
|
@ -27,7 +27,7 @@ pub async fn getpasta(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
|
|||
|
||||
for pasta in pastas.iter() {
|
||||
if pasta.id == id {
|
||||
return HttpResponse::Found().content_type("text/html").body(
|
||||
return HttpResponse::Ok().content_type("text/html").body(
|
||||
PastaTemplate {
|
||||
pasta: &pasta,
|
||||
args: &ARGS,
|
||||
|
@ -38,7 +38,7 @@ pub async fn getpasta(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
|
|||
}
|
||||
}
|
||||
|
||||
HttpResponse::Found()
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
||||
}
|
||||
|
@ -54,18 +54,18 @@ pub async fn redirecturl(data: web::Data<AppState>, id: web::Path<String>) -> Ht
|
|||
for pasta in pastas.iter() {
|
||||
if pasta.id == id {
|
||||
if pasta.pasta_type == "url" {
|
||||
return HttpResponse::Found()
|
||||
return HttpResponse::Ok()
|
||||
.append_header(("Location", String::from(&pasta.content)))
|
||||
.finish();
|
||||
} else {
|
||||
return HttpResponse::Found()
|
||||
return HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HttpResponse::Found()
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ pub async fn list(data: web::Data<AppState>) -> HttpResponse {
|
|||
|
||||
remove_expired(&mut pastas);
|
||||
|
||||
HttpResponse::Found().content_type("text/html").body(
|
||||
HttpResponse::Ok().content_type("text/html").body(
|
||||
PastaListTemplate {
|
||||
pastas: &pastas,
|
||||
args: &ARGS,
|
||||
|
|
|
@ -10,9 +10,7 @@ use askama::Template;
|
|||
#[get("/remove/{id}")]
|
||||
pub async fn remove(data: web::Data<AppState>, id: web::Path<String>) -> HttpResponse {
|
||||
if ARGS.readonly {
|
||||
return HttpResponse::Found()
|
||||
.append_header(("Location", "/"))
|
||||
.finish();
|
||||
return HttpResponse::Ok().append_header(("Location", "/")).finish();
|
||||
}
|
||||
|
||||
let mut pastas = data.pastas.lock().unwrap();
|
||||
|
@ -24,13 +22,13 @@ pub async fn remove(data: web::Data<AppState>, id: web::Path<String>) -> HttpRes
|
|||
for (i, pasta) in pastas.iter().enumerate() {
|
||||
if pasta.id == id {
|
||||
pastas.remove(i);
|
||||
return HttpResponse::Found()
|
||||
return HttpResponse::Ok()
|
||||
.append_header(("Location", "/pastalist"))
|
||||
.finish();
|
||||
}
|
||||
}
|
||||
|
||||
HttpResponse::Found()
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ struct WaterCSS<'a> {
|
|||
#[get("/static/{resource}")]
|
||||
pub async fn static_resources(resource_id: web::Path<String>) -> HttpResponse {
|
||||
match resource_id.into_inner().as_str() {
|
||||
"water.css" => HttpResponse::Found().content_type("text/html").body(
|
||||
"water.css" => HttpResponse::Ok().content_type("text/css").body(
|
||||
WaterCSS {
|
||||
_marker: Default::default(),
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
|||
use linkify::{LinkFinder, LinkKind};
|
||||
use std::fs;
|
||||
|
||||
use crate::Pasta;
|
||||
use crate::{dbio, Pasta};
|
||||
|
||||
pub fn remove_expired(pastas: &mut Vec<Pasta>) {
|
||||
// get current time - this will be needed to check which pastas have expired
|
||||
|
@ -22,17 +22,25 @@ pub fn remove_expired(pastas: &mut Vec<Pasta>) {
|
|||
true
|
||||
} else {
|
||||
// remove the file itself
|
||||
fs::remove_file(format!("./pasta_data/{}/{}", p.id_as_animals(), p.file))
|
||||
.expect(&*format!("Failed to delete file {}!", p.file));
|
||||
match fs::remove_file(format!("./pasta_data/{}/{}", p.id_as_animals(), p.file)) {
|
||||
Ok(_) => {}
|
||||
Err(_) => {
|
||||
log::error!("Failed to delete file {}!", p.file)
|
||||
}
|
||||
}
|
||||
// and remove the containing directory
|
||||
fs::remove_dir(format!("./pasta_data/{}/", p.id_as_animals())).expect(&*format!(
|
||||
"Failed to delete directory {}!",
|
||||
p.id_as_animals()
|
||||
));
|
||||
match fs::remove_dir(format!("./pasta_data/{}/", p.id_as_animals())) {
|
||||
Ok(_) => {}
|
||||
Err(_) => {
|
||||
log::error!("Failed to delete directory {}!", p.file)
|
||||
}
|
||||
}
|
||||
// remove
|
||||
false
|
||||
}
|
||||
});
|
||||
|
||||
dbio::save_to_file(pastas);
|
||||
}
|
||||
|
||||
pub fn is_valid_url(url: &str) -> bool {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
{% if args.footer_text.as_ref().is_none() %}
|
||||
|
|
Loading…
Reference in a new issue