45 lines
1.8 KiB
Rust
45 lines
1.8 KiB
Rust
use actix_web::{web::{self, Form}, HttpResponse, http::header::{ContentType, self}, Responder, HttpRequest};
|
|
|
|
use crate::{models::{AppState, BinaryCache}, templates, s3::{check_bucket, create_client}};
|
|
|
|
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() {
|
|
let client = create_client(form.clone());
|
|
if ! check_bucket(&client, &form.bucket).await.is_ok() {
|
|
HttpResponse::BadRequest()
|
|
.content_type(ContentType::plaintext())
|
|
.body("can't connect to the binary cache")
|
|
} else {
|
|
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()
|
|
}
|
|
}
|
|
|
|
pub async fn get_binary_cache(_app_state: web::Data<AppState<'_>>, _req: HttpRequest, _path: web::Path<String>) -> impl Responder {
|
|
HttpResponse::NotImplemented().finish()
|
|
}
|