Move /commit/:hash/enqueue to /admin/queue/add
This commit is contained in:
parent
08e240d7db
commit
087ecfd783
9 changed files with 113 additions and 40 deletions
|
|
@ -1,3 +1,4 @@
|
|||
mod admin;
|
||||
mod api;
|
||||
mod commit;
|
||||
mod index;
|
||||
|
|
@ -6,13 +7,13 @@ mod queue;
|
|||
mod r#static;
|
||||
mod worker;
|
||||
|
||||
use axum::{
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
use axum::{routing::get, Router};
|
||||
use axum_extra::routing::RouterExt;
|
||||
|
||||
use crate::{config::Config, somehow};
|
||||
|
||||
use self::admin::queue::post_admin_queue_add;
|
||||
|
||||
use super::Server;
|
||||
|
||||
pub enum Tab {
|
||||
|
|
@ -49,10 +50,10 @@ pub async fn run(server: Server) -> somehow::Result<()> {
|
|||
let app = Router::new()
|
||||
.route("/", get(index::get))
|
||||
.route("/commit/:hash", get(commit::get))
|
||||
.route("/commit/:hash/enqueue", post(commit::post_enqueue))
|
||||
.route("/queue/", get(queue::get))
|
||||
.route("/queue/inner", get(queue::get_inner))
|
||||
.route("/worker/:name", get(worker::get))
|
||||
.typed_post(post_admin_queue_add)
|
||||
.merge(api::router(&server))
|
||||
.fallback(get(r#static::static_handler))
|
||||
.with_state(server.clone());
|
||||
|
|
|
|||
1
src/server/web/admin.rs
Normal file
1
src/server/web/admin.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod queue;
|
||||
46
src/server/web/admin/queue.rs
Normal file
46
src/server/web/admin/queue.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
use axum::{
|
||||
extract::State,
|
||||
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 {}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FormAdminQueueAdd {
|
||||
hash: String,
|
||||
#[serde(default)]
|
||||
priority: i32,
|
||||
}
|
||||
|
||||
pub async fn post_admin_queue_add(
|
||||
_path: PathAdminQueueAdd,
|
||||
State(config): State<&'static Config>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminQueueAdd>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let date = OffsetDateTime::now_utc();
|
||||
sqlx::query!(
|
||||
"\
|
||||
INSERT INTO queue (hash, date, priority) VALUES (?, ?, ?) \
|
||||
ON CONFLICT (hash) DO UPDATE \
|
||||
SET priority = excluded.priority WHERE priority < excluded.priority \
|
||||
",
|
||||
form.hash,
|
||||
date,
|
||||
form.priority,
|
||||
)
|
||||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
// TODO Replace with typed link
|
||||
Ok(Redirect::to(&format!("{}queue/", config.web_base)))
|
||||
}
|
||||
|
|
@ -2,15 +2,14 @@ use askama::Template;
|
|||
use axum::{
|
||||
extract::{Path, State},
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Redirect, Response},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use futures::TryStreamExt;
|
||||
use sqlx::SqlitePool;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use crate::{config::Config, server::util, somehow};
|
||||
|
||||
use super::{link::CommitLink, Base, Tab};
|
||||
use super::{admin::queue::PathAdminQueueAdd, link::CommitLink, Base, Tab};
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "commit.html")]
|
||||
|
|
@ -26,6 +25,7 @@ struct CommitTemplate {
|
|||
summary: String,
|
||||
message: String,
|
||||
reachable: i64,
|
||||
link_admin_queue_add: PathAdminQueueAdd,
|
||||
}
|
||||
|
||||
pub async fn get(
|
||||
|
|
@ -96,24 +96,7 @@ pub async fn get(
|
|||
summary: util::format_commit_summary(&commit.message),
|
||||
message: commit.message.trim_end().to_string(),
|
||||
reachable: commit.reachable,
|
||||
link_admin_queue_add: PathAdminQueueAdd {},
|
||||
}
|
||||
.into_response())
|
||||
}
|
||||
|
||||
// TODO Move to /admin/queue/add
|
||||
pub async fn post_enqueue(
|
||||
Path(hash): Path<String>,
|
||||
State(config): State<&'static Config>,
|
||||
State(db): State<SqlitePool>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let date = OffsetDateTime::now_utc();
|
||||
sqlx::query!(
|
||||
"INSERT OR IGNORE INTO queue (hash, date, priority) VALUES (?, ?, 1)",
|
||||
hash,
|
||||
date,
|
||||
)
|
||||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
Ok(Redirect::to(&format!("{}queue/", config.web_base)))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue