Compare commits
2 Commits
26841d5293
...
886fddfc41
Author | SHA1 | Date | |
---|---|---|---|
886fddfc41 | |||
47b2f04a64 |
@ -3,7 +3,6 @@
|
|||||||
use db::import_scripts;
|
use db::import_scripts;
|
||||||
use router::new_router;
|
use router::new_router;
|
||||||
use script::Script;
|
use script::Script;
|
||||||
use sqlx::SqlitePool;
|
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
@ -1,14 +1,37 @@
|
|||||||
use axum::response::{Html, IntoResponse};
|
use axum::{
|
||||||
|
extract::State,
|
||||||
|
http::StatusCode,
|
||||||
|
response::{Html, IntoResponse},
|
||||||
|
};
|
||||||
|
use sqlx::SqlitePool;
|
||||||
|
use std::fmt::Write;
|
||||||
|
use tracing::{error, instrument};
|
||||||
|
|
||||||
pub async fn get_scripts() -> impl IntoResponse {
|
#[instrument(skip_all)]
|
||||||
Html(
|
pub async fn get_scripts(State(database): State<SqlitePool>) -> impl IntoResponse {
|
||||||
r##"
|
let scripts = match crate::db::list_scripts(&database).await {
|
||||||
<section id="scripts">
|
Ok(scripts) => scripts,
|
||||||
<ul>
|
Err(e) => {
|
||||||
<li>Script1</li>
|
error!(err = e, "list_scripts");
|
||||||
<li>Script2</li>
|
return Err(StatusCode::INTERNAL_SERVER_ERROR);
|
||||||
</ul>
|
}
|
||||||
<button hx-get="/scripts" hx-swap="outerHTML" hx-target="#scripts">Refresh</button>
|
};
|
||||||
</section>"##,
|
|
||||||
)
|
let content = scripts.iter().fold(String::new(), |mut acc, x| {
|
||||||
|
if let Err(e) = write!(acc, "<li>{} [", x.1.name()) {
|
||||||
|
error!(err = e.to_string(), script=?x ,"failed to write name");
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
if let Err(e) = write!(acc, "{}]</li>", x.0) {
|
||||||
|
error!(err = e.to_string(), script=?x ,"failed to write id");
|
||||||
|
return String::new();
|
||||||
|
}
|
||||||
|
acc
|
||||||
|
});
|
||||||
|
|
||||||
|
let output = format!(
|
||||||
|
r##"<section id="scripts"><ul>{content}</ul><button hx-get="/scripts" hx-swap="outerHTML" hx-target="#scripts">Refresh</button></section>"##
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(Html(output))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user