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("/")]
|
#[get("/")]
|
||||||
pub async fn index() -> impl Responder {
|
pub async fn index() -> impl Responder {
|
||||||
HttpResponse::Found()
|
HttpResponse::Ok()
|
||||||
.content_type("text/html")
|
.content_type("text/html")
|
||||||
.body(IndexTemplate { args: &ARGS }.render().unwrap())
|
.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", "/"))
|
.append_header(("Location", "/"))
|
||||||
.finish();
|
.finish();
|
||||||
}
|
}
|
||||||
return HttpResponse::Found().content_type("text/html").body(
|
return HttpResponse::Ok().content_type("text/html").body(
|
||||||
EditTemplate {
|
EditTemplate {
|
||||||
pasta: &pasta,
|
pasta: &pasta,
|
||||||
args: &ARGS,
|
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")
|
.content_type("text/html")
|
||||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
.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")
|
.content_type("text/html")
|
||||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
|
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub struct ErrorTemplate<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn not_found() -> Result<HttpResponse, Error> {
|
pub async fn not_found() -> Result<HttpResponse, Error> {
|
||||||
Ok(HttpResponse::Found()
|
Ok(HttpResponse::Ok()
|
||||||
.content_type("text/html")
|
.content_type("text/html")
|
||||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
|
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct Help<'a> {
|
||||||
|
|
||||||
#[get("/help")]
|
#[get("/help")]
|
||||||
pub async fn help() -> HttpResponse {
|
pub async fn help() -> HttpResponse {
|
||||||
HttpResponse::Found().content_type("text/html").body(
|
HttpResponse::Ok().content_type("text/html").body(
|
||||||
Help {
|
Help {
|
||||||
args: &ARGS,
|
args: &ARGS,
|
||||||
_marker: Default::default(),
|
_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() {
|
for pasta in pastas.iter() {
|
||||||
if pasta.id == id {
|
if pasta.id == id {
|
||||||
return HttpResponse::Found().content_type("text/html").body(
|
return HttpResponse::Ok().content_type("text/html").body(
|
||||||
PastaTemplate {
|
PastaTemplate {
|
||||||
pasta: &pasta,
|
pasta: &pasta,
|
||||||
args: &ARGS,
|
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")
|
.content_type("text/html")
|
||||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
.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() {
|
for pasta in pastas.iter() {
|
||||||
if pasta.id == id {
|
if pasta.id == id {
|
||||||
if pasta.pasta_type == "url" {
|
if pasta.pasta_type == "url" {
|
||||||
return HttpResponse::Found()
|
return HttpResponse::Ok()
|
||||||
.append_header(("Location", String::from(&pasta.content)))
|
.append_header(("Location", String::from(&pasta.content)))
|
||||||
.finish();
|
.finish();
|
||||||
} else {
|
} else {
|
||||||
return HttpResponse::Found()
|
return HttpResponse::Ok()
|
||||||
.content_type("text/html")
|
.content_type("text/html")
|
||||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap());
|
.body(ErrorTemplate { args: &ARGS }.render().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse::Found()
|
HttpResponse::Ok()
|
||||||
.content_type("text/html")
|
.content_type("text/html")
|
||||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub async fn list(data: web::Data<AppState>) -> HttpResponse {
|
||||||
|
|
||||||
remove_expired(&mut pastas);
|
remove_expired(&mut pastas);
|
||||||
|
|
||||||
HttpResponse::Found().content_type("text/html").body(
|
HttpResponse::Ok().content_type("text/html").body(
|
||||||
PastaListTemplate {
|
PastaListTemplate {
|
||||||
pastas: &pastas,
|
pastas: &pastas,
|
||||||
args: &ARGS,
|
args: &ARGS,
|
||||||
|
|
|
@ -10,9 +10,7 @@ use askama::Template;
|
||||||
#[get("/remove/{id}")]
|
#[get("/remove/{id}")]
|
||||||
pub async fn remove(data: web::Data<AppState>, id: web::Path<String>) -> HttpResponse {
|
pub async fn remove(data: web::Data<AppState>, id: web::Path<String>) -> HttpResponse {
|
||||||
if ARGS.readonly {
|
if ARGS.readonly {
|
||||||
return HttpResponse::Found()
|
return HttpResponse::Ok().append_header(("Location", "/")).finish();
|
||||||
.append_header(("Location", "/"))
|
|
||||||
.finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut pastas = data.pastas.lock().unwrap();
|
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() {
|
for (i, pasta) in pastas.iter().enumerate() {
|
||||||
if pasta.id == id {
|
if pasta.id == id {
|
||||||
pastas.remove(i);
|
pastas.remove(i);
|
||||||
return HttpResponse::Found()
|
return HttpResponse::Ok()
|
||||||
.append_header(("Location", "/pastalist"))
|
.append_header(("Location", "/pastalist"))
|
||||||
.finish();
|
.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse::Found()
|
HttpResponse::Ok()
|
||||||
.content_type("text/html")
|
.content_type("text/html")
|
||||||
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ struct WaterCSS<'a> {
|
||||||
#[get("/static/{resource}")]
|
#[get("/static/{resource}")]
|
||||||
pub async fn static_resources(resource_id: web::Path<String>) -> HttpResponse {
|
pub async fn static_resources(resource_id: web::Path<String>) -> HttpResponse {
|
||||||
match resource_id.into_inner().as_str() {
|
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 {
|
WaterCSS {
|
||||||
_marker: Default::default(),
|
_marker: Default::default(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use linkify::{LinkFinder, LinkKind};
|
use linkify::{LinkFinder, LinkKind};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use crate::Pasta;
|
use crate::{dbio, Pasta};
|
||||||
|
|
||||||
pub fn remove_expired(pastas: &mut Vec<Pasta>) {
|
pub fn remove_expired(pastas: &mut Vec<Pasta>) {
|
||||||
// get current time - this will be needed to check which pastas have expired
|
// 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
|
true
|
||||||
} else {
|
} else {
|
||||||
// remove the file itself
|
// remove the file itself
|
||||||
fs::remove_file(format!("./pasta_data/{}/{}", p.id_as_animals(), p.file))
|
match fs::remove_file(format!("./pasta_data/{}/{}", p.id_as_animals(), p.file)) {
|
||||||
.expect(&*format!("Failed to delete file {}!", p.file));
|
Ok(_) => {}
|
||||||
|
Err(_) => {
|
||||||
|
log::error!("Failed to delete file {}!", p.file)
|
||||||
|
}
|
||||||
|
}
|
||||||
// and remove the containing directory
|
// and remove the containing directory
|
||||||
fs::remove_dir(format!("./pasta_data/{}/", p.id_as_animals())).expect(&*format!(
|
match fs::remove_dir(format!("./pasta_data/{}/", p.id_as_animals())) {
|
||||||
"Failed to delete directory {}!",
|
Ok(_) => {}
|
||||||
p.id_as_animals()
|
Err(_) => {
|
||||||
));
|
log::error!("Failed to delete directory {}!", p.file)
|
||||||
|
}
|
||||||
|
}
|
||||||
// remove
|
// remove
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dbio::save_to_file(pastas);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_valid_url(url: &str) -> bool {
|
pub fn is_valid_url(url: &str) -> bool {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
{% if args.footer_text.as_ref().is_none() %}
|
{% if args.footer_text.as_ref().is_none() %}
|
||||||
|
|
Loading…
Reference in a new issue