diff --git a/src/server/web.rs b/src/server/web.rs index 6b5b471..ba5d955 100644 --- a/src/server/web.rs +++ b/src/server/web.rs @@ -1,8 +1,9 @@ mod admin; -pub mod api; +mod api; mod commit; mod index; mod link; +pub mod paths; mod queue; mod r#static; mod worker; diff --git a/src/server/web/admin/queue.rs b/src/server/web/admin/queue.rs index e14c884..5de92a3 100644 --- a/src/server/web/admin/queue.rs +++ b/src/server/web/admin/queue.rs @@ -3,16 +3,11 @@ use axum::{ response::{IntoResponse, Redirect}, Form, }; -use axum_extra::routing::TypedPath; use serde::Deserialize; use sqlx::SqlitePool; use time::OffsetDateTime; -use crate::{config::Config, somehow}; - -#[derive(Deserialize, TypedPath)] -#[typed_path("/admin/queue/add")] -pub struct PathAdminQueueAdd {} +use crate::{config::Config, server::web::paths::PathAdminQueueAdd, somehow}; #[derive(Deserialize)] pub struct FormAdminQueueAdd { diff --git a/src/server/web/api/worker.rs b/src/server/web/api/worker.rs index 679eb62..a6d17ea 100644 --- a/src/server/web/api/worker.rs +++ b/src/server/web/api/worker.rs @@ -12,9 +12,7 @@ use axum::{ response::{IntoResponse, Response}, Json, TypedHeader, }; -use axum_extra::routing::TypedPath; use gix::{ObjectId, ThreadSafeRepository}; -use serde::Deserialize; use sqlx::{Acquire, SqlitePool}; use time::OffsetDateTime; use tracing::debug; @@ -22,6 +20,10 @@ use tracing::debug; use crate::{ config::Config, server::{ + web::paths::{ + PathApiWorkerBenchRepoByHashTreeTarGz, PathApiWorkerRepoByHashTreeTarGz, + PathApiWorkerStatus, + }, workers::{WorkerInfo, Workers}, BenchRepo, Repo, }, @@ -116,10 +118,6 @@ async fn save_work(finished: FinishedRun, db: &SqlitePool) -> somehow::Result<() Ok(()) } -#[derive(Deserialize, TypedPath)] -#[typed_path("/api/worker/status")] -pub struct PathApiWorkerStatus {} - pub async fn post_api_worker_status( _path: PathApiWorkerStatus, State(config): State<&'static Config>, @@ -199,12 +197,6 @@ fn stream_response(repo: Arc, id: ObjectId) -> impl IntoRe ) } -#[derive(Deserialize, TypedPath)] -#[typed_path("/api/worker/repo/:hash/tree.tar.gz")] -pub struct PathApiWorkerRepoByHashTreeTarGz { - pub hash: String, -} - pub async fn get_api_worker_repo_by_hash_tree_tar_gz( path: PathApiWorkerRepoByHashTreeTarGz, State(config): State<&'static Config>, @@ -224,12 +216,6 @@ pub async fn get_api_worker_repo_by_hash_tree_tar_gz( Ok(stream_response(repo.0, id).into_response()) } -#[derive(Deserialize, TypedPath)] -#[typed_path("/api/worker/bench_repo/:hash/tree.tar.gz")] -pub struct PathApiWorkerBenchRepoByHashTreeTarGz { - pub hash: String, -} - pub async fn get_api_worker_bench_repo_by_hash_tree_tar_gz( path: PathApiWorkerBenchRepoByHashTreeTarGz, State(config): State<&'static Config>, diff --git a/src/server/web/commit.rs b/src/server/web/commit.rs index 55adafc..ded8266 100644 --- a/src/server/web/commit.rs +++ b/src/server/web/commit.rs @@ -9,7 +9,7 @@ use sqlx::SqlitePool; use crate::{config::Config, server::util, somehow}; -use super::{admin::queue::PathAdminQueueAdd, link::CommitLink, Base, Tab}; +use super::{link::CommitLink, paths::PathAdminQueueAdd, Base, Tab}; #[derive(Template)] #[template(path = "commit.html")] diff --git a/src/server/web/paths.rs b/src/server/web/paths.rs new file mode 100644 index 0000000..7f4aa84 --- /dev/null +++ b/src/server/web/paths.rs @@ -0,0 +1,76 @@ +use axum_extra::routing::TypedPath; +use serde::Deserialize; + +//////////////// +// Html pages // +//////////////// + +#[derive(Deserialize, TypedPath)] +#[typed_path("/")] +pub struct PathIndex {} + +#[derive(Deserialize, TypedPath)] +#[typed_path("/queue")] +pub struct PathQueue {} + +#[derive(Deserialize, TypedPath)] +#[typed_path("/queue/inner")] +pub struct PathQueueInner {} + +#[derive(Deserialize, TypedPath)] +#[typed_path("/commit/:hash")] +pub struct PathCommitByHash { + pub hash: String, +} + +#[derive(Deserialize, TypedPath)] +#[typed_path("/run/:id")] +pub struct PathRunById { + pub id: String, +} + +#[derive(Deserialize, TypedPath)] +#[typed_path("/worker/:name")] +pub struct PathWorkerByName { + pub name: String, +} + +/////////////////// +// Admin actions // +/////////////////// + +#[derive(Deserialize, TypedPath)] +#[typed_path("/admin/queue/add")] +pub struct PathAdminQueueAdd {} + +#[derive(Deserialize, TypedPath)] +#[typed_path("/admin/queue/delete")] +pub struct PathAdminQueueDelete {} + +#[derive(Deserialize, TypedPath)] +#[typed_path("/admin/queue/increase")] +pub struct PathAdminQueueIncrease {} + +#[derive(Deserialize, TypedPath)] +#[typed_path("/admin/queue/decrease")] +pub struct PathAdminQueueDecrease {} + +///////// +// Api // +///////// + +#[derive(Deserialize, TypedPath)] +#[typed_path("/api/worker/status")] +pub struct PathApiWorkerStatus {} + +#[derive(Deserialize, TypedPath)] +#[typed_path("/api/worker/repo/:hash/tree.tar.gz")] +pub struct PathApiWorkerRepoByHashTreeTarGz { + pub hash: String, +} + +#[derive(Deserialize, TypedPath)] +#[typed_path("/api/worker/bench_repo/:hash/tree.tar.gz")] +pub struct PathApiWorkerBenchRepoByHashTreeTarGz { + pub hash: String, +} diff --git a/src/worker/server.rs b/src/worker/server.rs index 13f290d..921ba3a 100644 --- a/src/worker/server.rs +++ b/src/worker/server.rs @@ -7,7 +7,7 @@ use tracing::{debug, warn}; use crate::{ config::{Config, WorkerServerConfig}, - server::web::api::worker::{ + server::web::paths::{ PathApiWorkerBenchRepoByHashTreeTarGz, PathApiWorkerRepoByHashTreeTarGz, PathApiWorkerStatus, },