- 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
34 lines
962 B
Rust
34 lines
962 B
Rust
use actix_web::{get, web, HttpResponse};
|
|
|
|
use crate::args::ARGS;
|
|
use crate::endpoints::errors::ErrorTemplate;
|
|
use crate::util::animalnumbers::to_u64;
|
|
use crate::util::misc::remove_expired;
|
|
use crate::AppState;
|
|
use askama::Template;
|
|
|
|
#[get("/remove/{id}")]
|
|
pub async fn remove(data: web::Data<AppState>, id: web::Path<String>) -> HttpResponse {
|
|
if ARGS.readonly {
|
|
return HttpResponse::Ok().append_header(("Location", "/")).finish();
|
|
}
|
|
|
|
let mut pastas = data.pastas.lock().unwrap();
|
|
|
|
let id = to_u64(&*id.into_inner()).unwrap_or(0);
|
|
|
|
remove_expired(&mut pastas);
|
|
|
|
for (i, pasta) in pastas.iter().enumerate() {
|
|
if pasta.id == id {
|
|
pastas.remove(i);
|
|
return HttpResponse::Ok()
|
|
.append_header(("Location", "/pastalist"))
|
|
.finish();
|
|
}
|
|
}
|
|
|
|
HttpResponse::Ok()
|
|
.content_type("text/html")
|
|
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
|
|
}
|