Move typed paths to separate module

This commit is contained in:
Joscha 2023-08-13 16:32:13 +02:00
parent 3d5a277234
commit 058ed2e85c
6 changed files with 85 additions and 27 deletions

View file

@ -1,8 +1,9 @@
mod admin; mod admin;
pub mod api; mod api;
mod commit; mod commit;
mod index; mod index;
mod link; mod link;
pub mod paths;
mod queue; mod queue;
mod r#static; mod r#static;
mod worker; mod worker;

View file

@ -3,16 +3,11 @@ use axum::{
response::{IntoResponse, Redirect}, response::{IntoResponse, Redirect},
Form, Form,
}; };
use axum_extra::routing::TypedPath;
use serde::Deserialize; use serde::Deserialize;
use sqlx::SqlitePool; use sqlx::SqlitePool;
use time::OffsetDateTime; use time::OffsetDateTime;
use crate::{config::Config, somehow}; use crate::{config::Config, server::web::paths::PathAdminQueueAdd, somehow};
#[derive(Deserialize, TypedPath)]
#[typed_path("/admin/queue/add")]
pub struct PathAdminQueueAdd {}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct FormAdminQueueAdd { pub struct FormAdminQueueAdd {

View file

@ -12,9 +12,7 @@ use axum::{
response::{IntoResponse, Response}, response::{IntoResponse, Response},
Json, TypedHeader, Json, TypedHeader,
}; };
use axum_extra::routing::TypedPath;
use gix::{ObjectId, ThreadSafeRepository}; use gix::{ObjectId, ThreadSafeRepository};
use serde::Deserialize;
use sqlx::{Acquire, SqlitePool}; use sqlx::{Acquire, SqlitePool};
use time::OffsetDateTime; use time::OffsetDateTime;
use tracing::debug; use tracing::debug;
@ -22,6 +20,10 @@ use tracing::debug;
use crate::{ use crate::{
config::Config, config::Config,
server::{ server::{
web::paths::{
PathApiWorkerBenchRepoByHashTreeTarGz, PathApiWorkerRepoByHashTreeTarGz,
PathApiWorkerStatus,
},
workers::{WorkerInfo, Workers}, workers::{WorkerInfo, Workers},
BenchRepo, Repo, BenchRepo, Repo,
}, },
@ -116,10 +118,6 @@ async fn save_work(finished: FinishedRun, db: &SqlitePool) -> somehow::Result<()
Ok(()) Ok(())
} }
#[derive(Deserialize, TypedPath)]
#[typed_path("/api/worker/status")]
pub struct PathApiWorkerStatus {}
pub async fn post_api_worker_status( pub async fn post_api_worker_status(
_path: PathApiWorkerStatus, _path: PathApiWorkerStatus,
State(config): State<&'static Config>, State(config): State<&'static Config>,
@ -199,12 +197,6 @@ fn stream_response(repo: Arc<ThreadSafeRepository>, 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( pub async fn get_api_worker_repo_by_hash_tree_tar_gz(
path: PathApiWorkerRepoByHashTreeTarGz, path: PathApiWorkerRepoByHashTreeTarGz,
State(config): State<&'static Config>, 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()) 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( pub async fn get_api_worker_bench_repo_by_hash_tree_tar_gz(
path: PathApiWorkerBenchRepoByHashTreeTarGz, path: PathApiWorkerBenchRepoByHashTreeTarGz,
State(config): State<&'static Config>, State(config): State<&'static Config>,

View file

@ -9,7 +9,7 @@ use sqlx::SqlitePool;
use crate::{config::Config, server::util, somehow}; 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)] #[derive(Template)]
#[template(path = "commit.html")] #[template(path = "commit.html")]

76
src/server/web/paths.rs Normal file
View file

@ -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,
}

View file

@ -7,7 +7,7 @@ use tracing::{debug, warn};
use crate::{ use crate::{
config::{Config, WorkerServerConfig}, config::{Config, WorkerServerConfig},
server::web::api::worker::{ server::web::paths::{
PathApiWorkerBenchRepoByHashTreeTarGz, PathApiWorkerRepoByHashTreeTarGz, PathApiWorkerBenchRepoByHashTreeTarGz, PathApiWorkerRepoByHashTreeTarGz,
PathApiWorkerStatus, PathApiWorkerStatus,
}, },