Track and untrack refs
This commit is contained in:
parent
4af950b6a4
commit
7e0bf21223
10 changed files with 134 additions and 25 deletions
|
|
@ -17,6 +17,7 @@ use self::{
|
|||
post_admin_queue_add, post_admin_queue_add_batch, post_admin_queue_decrease,
|
||||
post_admin_queue_delete, post_admin_queue_increase,
|
||||
},
|
||||
refs::{post_admin_refs_track, post_admin_refs_untrack},
|
||||
repo::post_admin_repo_update,
|
||||
},
|
||||
api::worker::{
|
||||
|
|
@ -59,6 +60,8 @@ pub async fn run(server: Server) -> somehow::Result<()> {
|
|||
.typed_post(post_admin_queue_decrease)
|
||||
.typed_post(post_admin_queue_delete)
|
||||
.typed_post(post_admin_queue_increase)
|
||||
.typed_post(post_admin_refs_track)
|
||||
.typed_post(post_admin_refs_untrack)
|
||||
.typed_post(post_admin_repo_update)
|
||||
.merge(post_api_worker_status)
|
||||
.fallback(get(r#static::static_handler))
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
pub mod queue;
|
||||
pub mod refs;
|
||||
pub mod repo;
|
||||
|
|
|
|||
58
src/server/web/admin/refs.rs
Normal file
58
src/server/web/admin/refs.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use axum::{
|
||||
extract::State,
|
||||
response::{IntoResponse, Redirect},
|
||||
Form,
|
||||
};
|
||||
use log::info;
|
||||
use serde::Deserialize;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::{
|
||||
config::ServerConfig,
|
||||
server::web::{
|
||||
base::Base,
|
||||
paths::{PathAdminRefsTrack, PathAdminRefsUntrack, PathIndex},
|
||||
},
|
||||
somehow,
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FormAdminRefsTrack {
|
||||
r#ref: String,
|
||||
}
|
||||
|
||||
pub async fn post_admin_refs_track(
|
||||
_path: PathAdminRefsTrack,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminRefsTrack>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let result = sqlx::query!("UPDATE refs SET tracked = 1 WHERE name = ?", form.r#ref)
|
||||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
if result.rows_affected() > 0 {
|
||||
info!("Admin tracked {}", form.r#ref);
|
||||
}
|
||||
|
||||
let link = Base::link_with_config(config, PathIndex {});
|
||||
Ok(Redirect::to(&link.to_string()))
|
||||
}
|
||||
|
||||
pub async fn post_admin_refs_untrack(
|
||||
_path: PathAdminRefsUntrack,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminRefsTrack>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let result = sqlx::query!("UPDATE refs SET tracked = 0 WHERE name = ?", form.r#ref)
|
||||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
if result.rows_affected() > 0 {
|
||||
info!("Admin untracked {}", form.r#ref);
|
||||
}
|
||||
|
||||
let link = Base::link_with_config(config, PathIndex {});
|
||||
Ok(Redirect::to(&link.to_string()))
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
server::web::{
|
||||
base::{Base, Link, Tab},
|
||||
link::LinkCommit,
|
||||
paths::{PathAdminRepoUpdate, PathIndex},
|
||||
paths::{PathAdminRefsTrack, PathAdminRefsUntrack, PathAdminRepoUpdate, PathIndex},
|
||||
},
|
||||
somehow,
|
||||
};
|
||||
|
|
@ -22,6 +22,8 @@ struct Ref {
|
|||
#[derive(Template)]
|
||||
#[template(path = "pages/index.html")]
|
||||
struct IndexTemplate {
|
||||
link_admin_refs_track: Link,
|
||||
link_admin_refs_untrack: Link,
|
||||
link_admin_repo_update: Link,
|
||||
base: Base,
|
||||
|
||||
|
|
@ -64,6 +66,8 @@ pub async fn get_index(
|
|||
}
|
||||
|
||||
Ok(IndexTemplate {
|
||||
link_admin_refs_track: base.link(PathAdminRefsTrack {}),
|
||||
link_admin_refs_untrack: base.link(PathAdminRefsUntrack {}),
|
||||
link_admin_repo_update: base.link(PathAdminRepoUpdate {}),
|
||||
base: Base::new(config, Tab::Index),
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,14 @@ pub struct PathWorkerByName {
|
|||
// Admin actions //
|
||||
///////////////////
|
||||
|
||||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/admin/refs/track")]
|
||||
pub struct PathAdminRefsTrack {}
|
||||
|
||||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/admin/refs/untrack")]
|
||||
pub struct PathAdminRefsUntrack {}
|
||||
|
||||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/admin/repo/update")]
|
||||
pub struct PathAdminRepoUpdate {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue