Fix redirect response on POST by explicitly sending the page URI
This commit is contained in:
parent
8f2bc7ebc6
commit
ddda6cc1cf
2 changed files with 19 additions and 14 deletions
File diff suppressed because one or more lines are too long
31
src/main.rs
31
src/main.rs
|
@ -1,4 +1,4 @@
|
|||
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
|
||||
use actix_web::{get, post, web, App, HttpRequest, HttpResponse, HttpServer, Responder};
|
||||
use forgejo_api::{Auth, Forgejo};
|
||||
use lazy_static::lazy_static;
|
||||
use rand::prelude::*;
|
||||
|
@ -157,8 +157,8 @@ fn approx_score(score: f32) -> ApproxScore {
|
|||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn index(data: web::Data<AppState>, q: web::Query<SortSetting>) -> impl Responder {
|
||||
eprintln!("GET /");
|
||||
async fn index(data: web::Data<AppState>, q: web::Query<SortSetting>, req: HttpRequest) -> impl Responder {
|
||||
eprintln!("GET {}", req.uri());
|
||||
|
||||
let db = &data.db.lock().unwrap();
|
||||
|
||||
|
@ -208,13 +208,18 @@ async fn index(data: web::Data<AppState>, q: web::Query<SortSetting>) -> impl Re
|
|||
HttpResponse::Ok().body(page)
|
||||
}
|
||||
|
||||
async fn post_classified(data: web::Data<AppState>, req: web::Form<HashMap<i64, String>>, overwrite: bool, redirect: &str) -> impl Responder {
|
||||
eprintln!("POST /");
|
||||
async fn post_classified(
|
||||
data: web::Data<AppState>,
|
||||
form: web::Form<HashMap<i64, String>>,
|
||||
req: HttpRequest,
|
||||
overwrite: bool
|
||||
) -> impl Responder {
|
||||
eprintln!("POST {}", req.uri());
|
||||
|
||||
let db = &mut data.db.lock().unwrap();
|
||||
let classifier = &mut data.classifier.lock().unwrap();
|
||||
|
||||
let updates: Vec<(UserId, bool)> = req
|
||||
let updates: Vec<(UserId, bool)> = form
|
||||
.iter()
|
||||
.map(|(id, classification)| (UserId(*id), classification == "spam"))
|
||||
.collect();
|
||||
|
@ -228,23 +233,23 @@ async fn post_classified(data: web::Data<AppState>, req: web::Form<HashMap<i64,
|
|||
|
||||
eprintln!("done");
|
||||
HttpResponse::SeeOther()
|
||||
.insert_header(("Location", redirect))
|
||||
.insert_header(("Location", req.uri().to_string()))
|
||||
.finish()
|
||||
}
|
||||
|
||||
#[post("/")]
|
||||
async fn post_classified_index(data: web::Data<AppState>, req: web::Form<HashMap<i64, String>>) -> impl Responder {
|
||||
post_classified(data, req, false, "/").await
|
||||
async fn post_classified_index(data: web::Data<AppState>, form: web::Form<HashMap<i64, String>>, req: HttpRequest) -> impl Responder {
|
||||
post_classified(data, form, req, false).await
|
||||
}
|
||||
|
||||
#[post("/classified")]
|
||||
async fn post_classified_edit(data: web::Data<AppState>, req: web::Form<HashMap<i64, String>>) -> impl Responder {
|
||||
post_classified(data, req, true, "/classified").await
|
||||
async fn post_classified_edit(data: web::Data<AppState>, form: web::Form<HashMap<i64, String>>, req: HttpRequest) -> impl Responder {
|
||||
post_classified(data, form, req, true).await
|
||||
}
|
||||
|
||||
#[get("/classified")]
|
||||
async fn classified(data: web::Data<AppState>, _q: web::Query<SortSetting>) -> impl Responder {
|
||||
eprintln!("GET /classified");
|
||||
async fn classified(data: web::Data<AppState>, _q: web::Query<SortSetting>, req: HttpRequest) -> impl Responder {
|
||||
eprintln!("GET {}", req.uri());
|
||||
|
||||
let db = &data.db.lock().unwrap();
|
||||
|
||||
|
|
Loading…
Reference in a new issue