chore: clippy html-router

This commit is contained in:
Per Stark
2025-10-16 20:30:17 +02:00
parent 44e5d8a2fc
commit 99b88c3063
9 changed files with 31 additions and 37 deletions

View File

@@ -205,26 +205,26 @@ pub enum HtmlError {
impl From<AppError> for HtmlError {
fn from(err: AppError) -> Self {
HtmlError::AppError(err)
Self::AppError(err)
}
}
impl From<surrealdb::Error> for HtmlError {
fn from(err: surrealdb::Error) -> Self {
HtmlError::AppError(AppError::from(err))
Self::AppError(AppError::from(err))
}
}
impl From<minijinja::Error> for HtmlError {
fn from(err: minijinja::Error) -> Self {
HtmlError::TemplateError(err.to_string())
Self::TemplateError(err.to_string())
}
}
impl IntoResponse for HtmlError {
fn into_response(self) -> Response {
match self {
HtmlError::AppError(err) => match err {
Self::AppError(err) => match err {
AppError::NotFound(_) => TemplateResponse::not_found().into_response(),
AppError::Auth(_) => TemplateResponse::unauthorized().into_response(),
AppError::Validation(msg) => TemplateResponse::bad_request(&msg).into_response(),
@@ -233,7 +233,7 @@ impl IntoResponse for HtmlError {
TemplateResponse::server_error().into_response()
}
},
HtmlError::TemplateError(err) => {
Self::TemplateError(err) => {
error!("Template error: {}", err);
TemplateResponse::server_error().into_response()
}

View File

@@ -118,7 +118,7 @@ where
}
/// Enables response compression when building the router.
pub fn with_compression(mut self) -> Self {
pub const fn with_compression(mut self) -> Self {
self.compression_enabled = true;
self
}

View File

@@ -24,7 +24,7 @@ pub async fn show_account_page(
RequireUser(user): RequireUser,
State(state): State<HtmlState>,
) -> Result<impl IntoResponse, HtmlError> {
let timezones = TZ_VARIANTS.iter().map(|tz| tz.to_string()).collect();
let timezones = TZ_VARIANTS.iter().map(std::string::ToString::to_string).collect();
let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?;
Ok(TemplateResponse::new_template(
@@ -102,7 +102,7 @@ pub async fn update_timezone(
..user.clone()
};
let timezones = TZ_VARIANTS.iter().map(|tz| tz.to_string()).collect();
let timezones = TZ_VARIANTS.iter().map(std::string::ToString::to_string).collect();
// Render the API key section block
Ok(TemplateResponse::new_partial(

View File

@@ -103,7 +103,7 @@ pub async fn toggle_registration_status(
// Early return if the user is not admin
if !user.admin {
return Ok(TemplateResponse::redirect("/"));
};
}
let current_settings = SystemSettings::get_current(&state.db).await?;
@@ -147,7 +147,7 @@ pub async fn update_model_settings(
// Early return if the user is not admin
if !user.admin {
return Ok(TemplateResponse::redirect("/"));
};
}
let current_settings = SystemSettings::get_current(&state.db).await?;
@@ -239,7 +239,7 @@ pub async fn show_edit_system_prompt(
// Early return if the user is not admin
if !user.admin {
return Ok(TemplateResponse::redirect("/"));
};
}
let settings = SystemSettings::get_current(&state.db).await?;
@@ -270,7 +270,7 @@ pub async fn patch_query_prompt(
// Early return if the user is not admin
if !user.admin {
return Ok(TemplateResponse::redirect("/"));
};
}
let current_settings = SystemSettings::get_current(&state.db).await?;
@@ -303,7 +303,7 @@ pub async fn show_edit_ingestion_prompt(
// Early return if the user is not admin
if !user.admin {
return Ok(TemplateResponse::redirect("/"));
};
}
let settings = SystemSettings::get_current(&state.db).await?;
@@ -329,7 +329,7 @@ pub async fn patch_ingestion_prompt(
// Early return if the user is not admin
if !user.admin {
return Ok(TemplateResponse::redirect("/"));
};
}
let current_settings = SystemSettings::get_current(&state.db).await?;
@@ -362,7 +362,7 @@ pub async fn show_edit_image_prompt(
// Early return if the user is not admin
if !user.admin {
return Ok(TemplateResponse::redirect("/"));
};
}
let settings = SystemSettings::get_current(&state.db).await?;
@@ -388,7 +388,7 @@ pub async fn patch_image_prompt(
// Early return if the user is not admin
if !user.admin {
return Ok(TemplateResponse::redirect("/"));
};
}
let current_settings = SystemSettings::get_current(&state.db).await?;

View File

@@ -27,14 +27,11 @@ pub async fn show_signin_form(
if auth.is_authenticated() {
return Ok(TemplateResponse::redirect("/"));
}
match boosted {
true => Ok(TemplateResponse::new_partial(
"auth/signin_base.html",
"body",
(),
)),
false => Ok(TemplateResponse::new_template("auth/signin_base.html", ())),
}
if boosted { Ok(TemplateResponse::new_partial(
"auth/signin_base.html",
"body",
(),
)) } else { Ok(TemplateResponse::new_template("auth/signin_base.html", ())) }
}
pub async fn authenticate_user(

View File

@@ -29,14 +29,11 @@ pub async fn show_signup_form(
return Ok(TemplateResponse::redirect("/"));
}
match boosted {
true => Ok(TemplateResponse::new_partial(
"auth/signup_form.html",
"body",
(),
)),
false => Ok(TemplateResponse::new_template("auth/signup_form.html", ())),
}
if boosted { Ok(TemplateResponse::new_partial(
"auth/signup_form.html",
"body",
(),
)) } else { Ok(TemplateResponse::new_template("auth/signup_form.html", ())) }
}
pub async fn process_signup_and_show_verification(
@@ -48,7 +45,7 @@ pub async fn process_signup_and_show_verification(
Ok(user) => user,
Err(e) => {
tracing::error!("{:?}", e);
return Ok(Html(format!("<p>{}</p>", e)).into_response());
return Ok(Html(format!("<p>{e}</p>")).into_response());
}
};

View File

@@ -157,7 +157,7 @@ pub async fn new_user_message(
if conversation.user_id != user.id {
return Ok(TemplateResponse::unauthorized().into_response());
};
}
let user_message = Message::new(conversation_id, MessageRole::User, form.content, None);

View File

@@ -251,7 +251,7 @@ pub async fn get_response_stream(
Err(e) => {
yield Ok(Event::default()
.event("error")
.data(format!("Stream error: {}", e)));
.data(format!("Stream error: {e}")));
}
}
}
@@ -260,7 +260,7 @@ pub async fn get_response_stream(
.chain(stream::once(async move {
if let Some(message) = rx_final.recv().await {
// Don't send any event if references is empty
if message.references.as_ref().is_some_and(|x| x.is_empty()) {
if message.references.as_ref().is_some_and(std::vec::Vec::is_empty) {
return Ok(Event::default().event("empty")); // This event won't be sent
}

View File

@@ -107,7 +107,7 @@ pub async fn delete_text_content(
"dashboard/recent_content.html",
"latest_content_section",
LatestTextContentData {
user: user.to_owned(),
user: user.clone(),
text_contents,
},
))