Add "Enqueue" button to commits

This commit is contained in:
Joscha 2023-08-11 16:50:32 +02:00
parent 5e0b8e3c8c
commit 48693d3f1c
4 changed files with 41 additions and 3 deletions

View file

@ -2,10 +2,11 @@ use askama::Template;
use axum::{
extract::{Path, State},
http::StatusCode,
response::{IntoResponse, Response},
response::{IntoResponse, Redirect, Response},
};
use futures::TryStreamExt;
use sqlx::SqlitePool;
use time::OffsetDateTime;
use crate::{config::Config, server::util, somehow};
@ -98,3 +99,20 @@ pub async fn get(
}
.into_response())
}
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)))
}