Small fix
This commit is contained in:
18
src/web.rs
18
src/web.rs
@@ -2,7 +2,7 @@ use crate::config::Config;
|
||||
use crate::processor::{cleanup_finished_jobs, fetch_all_jobs, process_spreadsheet};
|
||||
use axum::{
|
||||
extract::State,
|
||||
http::StatusCode,
|
||||
http::{header::CONTENT_TYPE, StatusCode},
|
||||
response::{Html, IntoResponse, Json},
|
||||
routing::{get, post},
|
||||
Router,
|
||||
@@ -11,7 +11,6 @@ use serde::Serialize;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use tower_http::services::ServeDir;
|
||||
use tower_http::trace::TraceLayer;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -90,7 +89,7 @@ impl JobInfo {
|
||||
|
||||
// web.rs - функция run_web_server
|
||||
pub async fn run_web_server(config: Config) -> anyhow::Result<()> {
|
||||
let web_port = config.web_port; // Берём порт из конфига
|
||||
let web_port = config.web_port;
|
||||
let state = AppState {
|
||||
config,
|
||||
last_generation: Arc::new(Mutex::new(None)),
|
||||
@@ -98,13 +97,13 @@ pub async fn run_web_server(config: Config) -> anyhow::Result<()> {
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(index_page))
|
||||
.route("/static/style.css", get(style_css))
|
||||
.route("/assets/logo.png", get(logo_png))
|
||||
.route("/api/jobs", get(list_jobs))
|
||||
.route("/api/generate", post(generate_jobs))
|
||||
.route("/api/cleanup", post(cleanup_jobs))
|
||||
.route("/api/status", get(get_status))
|
||||
.route("/api/jobs/stop-all", post(stop_all_jobs))
|
||||
.nest_service("/static", ServeDir::new("src/static"))
|
||||
.nest_service("/assets", ServeDir::new("assets"))
|
||||
.layer(TraceLayer::new_for_http())
|
||||
.with_state(state);
|
||||
|
||||
@@ -120,6 +119,15 @@ async fn index_page() -> Html<&'static str> {
|
||||
Html(include_str!("static/index.html"))
|
||||
}
|
||||
|
||||
async fn style_css() -> impl IntoResponse {
|
||||
([(CONTENT_TYPE, "text/css")], include_str!("static/style.css"))
|
||||
}
|
||||
|
||||
async fn logo_png() -> impl IntoResponse {
|
||||
([(CONTENT_TYPE, "image/png")], include_bytes!("../assets/logo.png").as_slice())
|
||||
}
|
||||
|
||||
|
||||
async fn list_jobs(State(state): State<AppState>) -> Result<Json<Vec<JobInfo>>, AppError> {
|
||||
let jobs_json = fetch_all_jobs(&state.config.nexrender_api_url)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user