Compare commits
No commits in common. "886fddfc41431caf0cfb9dc88178eaebcd1cfa0d" and "26841d5293b955509852f826b62623148ecefa09" have entirely different histories.
886fddfc41
...
26841d5293
@ -3,6 +3,7 @@
|
|||||||
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,37 +1,14 @@
|
|||||||
use axum::{
|
use axum::response::{Html, IntoResponse};
|
||||||
extract::State,
|
|
||||||
http::StatusCode,
|
|
||||||
response::{Html, IntoResponse},
|
|
||||||
};
|
|
||||||
use sqlx::SqlitePool;
|
|
||||||
use std::fmt::Write;
|
|
||||||
use tracing::{error, instrument};
|
|
||||||
|
|
||||||
#[instrument(skip_all)]
|
pub async fn get_scripts() -> impl IntoResponse {
|
||||||
pub async fn get_scripts(State(database): State<SqlitePool>) -> impl IntoResponse {
|
Html(
|
||||||
let scripts = match crate::db::list_scripts(&database).await {
|
r##"
|
||||||
Ok(scripts) => scripts,
|
<section id="scripts">
|
||||||
Err(e) => {
|
<ul>
|
||||||
error!(err = e, "list_scripts");
|
<li>Script1</li>
|
||||||
return Err(StatusCode::INTERNAL_SERVER_ERROR);
|
<li>Script2</li>
|
||||||
}
|
</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