34 lines
1.2 KiB
Rust
34 lines
1.2 KiB
Rust
use actix_web::{web::{self, Form}, HttpResponse, http::header::{ContentType, self}, Responder, HttpRequest};
|
|
|
|
use crate::{models::{AppState, BinaryCache}, templates};
|
|
|
|
use super::check_authentication;
|
|
|
|
|
|
pub async fn new_binary_cache(app_state: web::Data<AppState<'_>>, req: HttpRequest) -> impl Responder {
|
|
if check_authentication(&app_state, req).await.is_ok() {
|
|
let response = templates::new_binary_cache(app_state.hbs.clone()).unwrap();
|
|
HttpResponse::Ok()
|
|
.content_type(ContentType::html())
|
|
.body(response)
|
|
} else {
|
|
HttpResponse::SeeOther()
|
|
.content_type(ContentType::plaintext())
|
|
.append_header((header::LOCATION, "/login"))
|
|
.body("please log in")
|
|
}
|
|
}
|
|
|
|
pub async fn new_binary_cache_post(app_state: web::Data<AppState<'_>>, req: HttpRequest, form: Form<BinaryCache>) -> impl Responder {
|
|
if check_authentication(&app_state, req).await.is_ok() {
|
|
app_state.create_binary_cache(&form).await.unwrap();
|
|
HttpResponse::SeeOther()
|
|
.content_type(ContentType::plaintext())
|
|
.append_header((header::LOCATION, "/"))
|
|
.body("new binary cache created")
|
|
} else {
|
|
HttpResponse::Forbidden()
|
|
.finish()
|
|
}
|
|
}
|