💥 Nukes rust and replaces with kotlin

This commit is contained in:
Daniel Svitan
2025-05-11 10:44:14 +02:00
parent 1413ed58b9
commit 1d4db39b2a
26 changed files with 866 additions and 1912 deletions
-56
View File
@@ -1,56 +0,0 @@
use rocket::Response;
use rocket::http::Status;
use rocket::request::{FromRequest, Outcome, Request};
use serde::Serialize;
use serde_json::json;
use std::io::Cursor;
pub struct ApiKey {}
#[derive(Serialize)]
pub struct GenericResponse {
pub message: String,
}
#[rocket::async_trait]
impl<'r> FromRequest<'r> for ApiKey {
type Error = Response<'r>;
async fn from_request(req: &'r Request<'_>) -> Outcome<Self, Response<'r>> {
fn is_valid(key: &str) -> bool {
key == dotenv::var("API_KEY").unwrap()
}
match req.headers().get_one("Authorization") {
None => {
let body = json!(GenericResponse {
message: "auth token not found".to_string()
})
.to_string();
Outcome::Error((
Status::Unauthorized,
Response::build()
.status(Status::Unauthorized)
.sized_body(body.len(), Cursor::new(body))
.finalize(),
))
}
Some(key) if is_valid(key) => Outcome::Success(ApiKey {}),
Some(_) => {
let body = json!(GenericResponse {
message: "invalid auth token".to_string()
})
.to_string();
Outcome::Error((
Status::Unauthorized,
Response::build()
.status(Status::Unauthorized)
.sized_body(body.len(), Cursor::new(body))
.finalize(),
))
}
}
}
}