Lines
84.62 %
Functions
16.67 %
Branches
100 %
use axum::{
Extension,
response::{IntoResponse, Response},
};
use crate::jwt_auth::JWTAuthMiddleware;
use crate::response::WebError;
use server::command::CmdResult;
pub async fn get_version() -> Result<impl IntoResponse, WebError> {
if let Some(CmdResult::String(version)) =
server::command::config::GetVersion::new().run().await?
&& let Some(CmdResult::String(build_date)) =
server::command::config::GetBuildDate::new().run().await?
{
Ok(Response::new(format!(
"<span class=\"version\">{version}</span><span class=\"build_date\" data-iso=\"{build_date}\"><script>
const el = document.currentScript.parentElement;
el.textContent = new Date(el.dataset.iso.trim()).toLocaleString();
</script></span>"
)))
} else {
Ok(Response::new("Unversioned".to_string()))
}
pub async fn get_logout_link(Extension(jwtauth): Extension<JWTAuthMiddleware>) -> Response {
// `/register` is admin-gated server-side; showing the link to everyone
// would only advertise a 401.
let admin_link = match jwtauth.user.role.as_str() {
"admin" => "<a href=\"/register\">Register user</a> ",
_ => "",
Response::new(
format!(
"<a href=\"/account/ssh-key\">Account</a> {admin_link}\
<a hx-get=\"/api/auth/logout\">Logout</a>"
)
.into(),
pub async fn get_home_link() -> Response {
Response::new("<a href='/'>Back to main</a>".into())