add generation

This commit is contained in:
2025-03-24 21:30:37 +03:00
parent edd86af7ef
commit 4320b5dc13
2 changed files with 128 additions and 38 deletions

View File

@@ -1,9 +1,9 @@
use rocket::fs::NamedFile;
use rocket::http::Method;
use rocket::http::Status;
use rocket::response::{Responder, status};
use rocket::serde::{Deserialize, json::Json};
use rocket::{self, get, launch, post, routes};
use rocket::http::Method;
use rocket_cors::{AllowedOrigins, CorsOptions};
use std::env;
use std::path::Path;
@@ -206,18 +206,20 @@ async fn generate(request: Json<GenerationRequest<'_>>) -> Result<NamedFile, Gen
#[launch]
fn rocket() -> _ {
let cors = CorsOptions::default()
.allowed_origins(AllowedOrigins::all())
.allowed_methods(
vec![Method::Get, Method::Post]
.into_iter()
.map(From::from)
.collect(),
)
.allow_credentials(true);
let cors = CorsOptions::default()
.allowed_origins(AllowedOrigins::all())
.allowed_methods(
vec![Method::Get, Method::Post]
.into_iter()
.map(From::from)
.collect(),
)
.allow_credentials(true);
rocket::build().mount(
"/api/v1",
routes![index, list_directories, list_directory, get_file, generate],
).attach(cors.to_cors().unwrap())
rocket::build()
.mount(
"/api/v1",
routes![index, list_directories, list_directory, get_file, generate],
)
.attach(cors.to_cors().unwrap())
}