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,12 +0,0 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "INSERT OR IGNORE INTO queue (hash, date, priority) VALUES (?, ?, 1)",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 2
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "091ccc5f03da1f11d8efafe1a0082e62f7973dc2d35835693dd5bdd696759de0"
|
||||
}
|
||||
12
.sqlx/query-aaf84d58ad3670609cf7cb28243a242829f0b5a65e39e98070664533621bc4c2.json
generated
Normal file
12
.sqlx/query-aaf84d58ad3670609cf7cb28243a242829f0b5a65e39e98070664533621bc4c2.json
generated
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"db_name": "SQLite",
|
||||
"query": "INSERT INTO queue (hash, date, priority) VALUES (?, ?, ?) ON CONFLICT (hash) DO UPDATE SET priority = excluded.priority WHERE priority < excluded.priority ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Right": 3
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "aaf84d58ad3670609cf7cb28243a242829f0b5a65e39e98070664533621bc4c2"
|
||||
}
|
||||
39
Cargo.lock
generated
39
Cargo.lock
generated
|
|
@ -234,6 +234,31 @@ dependencies = [
|
|||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-extra"
|
||||
version = "0.7.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a93e433be9382c737320af3924f7d5fc6f89c155cf2bf88949d8f5126fab283f"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-core",
|
||||
"axum-macros",
|
||||
"bytes",
|
||||
"form_urlencoded",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"mime",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"serde",
|
||||
"serde_html_form",
|
||||
"tokio",
|
||||
"tower",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-macros"
|
||||
version = "0.3.8"
|
||||
|
|
@ -2678,6 +2703,19 @@ dependencies = [
|
|||
"syn 2.0.28",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_html_form"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cde65b75f2603066b78d6fa239b2c07b43e06ead09435f60554d3912962b4a3c"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"indexmap 2.0.0",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.104"
|
||||
|
|
@ -3130,6 +3168,7 @@ dependencies = [
|
|||
"askama",
|
||||
"askama_axum",
|
||||
"axum",
|
||||
"axum-extra",
|
||||
"clap",
|
||||
"directories",
|
||||
"flate2",
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ anyhow = "1.0.72"
|
|||
askama = { version = "0.12.0", features = ["with-axum"] }
|
||||
askama_axum = "0.3.0"
|
||||
axum = { version = "0.6.19", features = ["macros", "headers"] }
|
||||
axum-extra = { version = "0.7.7", features = ["typed-routing"] }
|
||||
clap = { version = "4.3.19", features = ["derive", "deprecated"] }
|
||||
directories = "5.0.1"
|
||||
flate2 = "1.0.26"
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@
|
|||
title="{% call util::commit_title(reachable) %}">{{ message }}</pre>
|
||||
</div>
|
||||
|
||||
<form method="post" action="{{ base.root }}commit/{{ hash }}/enqueue">
|
||||
<button>Enqueue</button>
|
||||
<form method="post" action="{{ base.root }}{{ link_admin_queue_add }}">
|
||||
<input type="hidden" name="hash" value="{{ hash }}">
|
||||
<label>Priority: <input type="number" name="priority" value="0" min="-2147483648" max="2147483647"></label>
|
||||
<button>Add to queue</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue