mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-25 10:18:38 +02:00
chore: clippy html-router
This commit is contained in:
@@ -205,26 +205,26 @@ pub enum HtmlError {
|
|||||||
|
|
||||||
impl From<AppError> for HtmlError {
|
impl From<AppError> for HtmlError {
|
||||||
fn from(err: AppError) -> Self {
|
fn from(err: AppError) -> Self {
|
||||||
HtmlError::AppError(err)
|
Self::AppError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<surrealdb::Error> for HtmlError {
|
impl From<surrealdb::Error> for HtmlError {
|
||||||
fn from(err: surrealdb::Error) -> Self {
|
fn from(err: surrealdb::Error) -> Self {
|
||||||
HtmlError::AppError(AppError::from(err))
|
Self::AppError(AppError::from(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<minijinja::Error> for HtmlError {
|
impl From<minijinja::Error> for HtmlError {
|
||||||
fn from(err: minijinja::Error) -> Self {
|
fn from(err: minijinja::Error) -> Self {
|
||||||
HtmlError::TemplateError(err.to_string())
|
Self::TemplateError(err.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoResponse for HtmlError {
|
impl IntoResponse for HtmlError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
match self {
|
match self {
|
||||||
HtmlError::AppError(err) => match err {
|
Self::AppError(err) => match err {
|
||||||
AppError::NotFound(_) => TemplateResponse::not_found().into_response(),
|
AppError::NotFound(_) => TemplateResponse::not_found().into_response(),
|
||||||
AppError::Auth(_) => TemplateResponse::unauthorized().into_response(),
|
AppError::Auth(_) => TemplateResponse::unauthorized().into_response(),
|
||||||
AppError::Validation(msg) => TemplateResponse::bad_request(&msg).into_response(),
|
AppError::Validation(msg) => TemplateResponse::bad_request(&msg).into_response(),
|
||||||
@@ -233,7 +233,7 @@ impl IntoResponse for HtmlError {
|
|||||||
TemplateResponse::server_error().into_response()
|
TemplateResponse::server_error().into_response()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
HtmlError::TemplateError(err) => {
|
Self::TemplateError(err) => {
|
||||||
error!("Template error: {}", err);
|
error!("Template error: {}", err);
|
||||||
TemplateResponse::server_error().into_response()
|
TemplateResponse::server_error().into_response()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Enables response compression when building the router.
|
/// 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.compression_enabled = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub async fn show_account_page(
|
|||||||
RequireUser(user): RequireUser,
|
RequireUser(user): RequireUser,
|
||||||
State(state): State<HtmlState>,
|
State(state): State<HtmlState>,
|
||||||
) -> Result<impl IntoResponse, HtmlError> {
|
) -> 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?;
|
let conversation_archive = User::get_user_conversations(&user.id, &state.db).await?;
|
||||||
|
|
||||||
Ok(TemplateResponse::new_template(
|
Ok(TemplateResponse::new_template(
|
||||||
@@ -102,7 +102,7 @@ pub async fn update_timezone(
|
|||||||
..user.clone()
|
..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
|
// Render the API key section block
|
||||||
Ok(TemplateResponse::new_partial(
|
Ok(TemplateResponse::new_partial(
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ pub async fn toggle_registration_status(
|
|||||||
// Early return if the user is not admin
|
// Early return if the user is not admin
|
||||||
if !user.admin {
|
if !user.admin {
|
||||||
return Ok(TemplateResponse::redirect("/"));
|
return Ok(TemplateResponse::redirect("/"));
|
||||||
};
|
}
|
||||||
|
|
||||||
let current_settings = SystemSettings::get_current(&state.db).await?;
|
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
|
// Early return if the user is not admin
|
||||||
if !user.admin {
|
if !user.admin {
|
||||||
return Ok(TemplateResponse::redirect("/"));
|
return Ok(TemplateResponse::redirect("/"));
|
||||||
};
|
}
|
||||||
|
|
||||||
let current_settings = SystemSettings::get_current(&state.db).await?;
|
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
|
// Early return if the user is not admin
|
||||||
if !user.admin {
|
if !user.admin {
|
||||||
return Ok(TemplateResponse::redirect("/"));
|
return Ok(TemplateResponse::redirect("/"));
|
||||||
};
|
}
|
||||||
|
|
||||||
let settings = SystemSettings::get_current(&state.db).await?;
|
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
|
// Early return if the user is not admin
|
||||||
if !user.admin {
|
if !user.admin {
|
||||||
return Ok(TemplateResponse::redirect("/"));
|
return Ok(TemplateResponse::redirect("/"));
|
||||||
};
|
}
|
||||||
|
|
||||||
let current_settings = SystemSettings::get_current(&state.db).await?;
|
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
|
// Early return if the user is not admin
|
||||||
if !user.admin {
|
if !user.admin {
|
||||||
return Ok(TemplateResponse::redirect("/"));
|
return Ok(TemplateResponse::redirect("/"));
|
||||||
};
|
}
|
||||||
|
|
||||||
let settings = SystemSettings::get_current(&state.db).await?;
|
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
|
// Early return if the user is not admin
|
||||||
if !user.admin {
|
if !user.admin {
|
||||||
return Ok(TemplateResponse::redirect("/"));
|
return Ok(TemplateResponse::redirect("/"));
|
||||||
};
|
}
|
||||||
|
|
||||||
let current_settings = SystemSettings::get_current(&state.db).await?;
|
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
|
// Early return if the user is not admin
|
||||||
if !user.admin {
|
if !user.admin {
|
||||||
return Ok(TemplateResponse::redirect("/"));
|
return Ok(TemplateResponse::redirect("/"));
|
||||||
};
|
}
|
||||||
|
|
||||||
let settings = SystemSettings::get_current(&state.db).await?;
|
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
|
// Early return if the user is not admin
|
||||||
if !user.admin {
|
if !user.admin {
|
||||||
return Ok(TemplateResponse::redirect("/"));
|
return Ok(TemplateResponse::redirect("/"));
|
||||||
};
|
}
|
||||||
|
|
||||||
let current_settings = SystemSettings::get_current(&state.db).await?;
|
let current_settings = SystemSettings::get_current(&state.db).await?;
|
||||||
|
|
||||||
|
|||||||
@@ -27,14 +27,11 @@ pub async fn show_signin_form(
|
|||||||
if auth.is_authenticated() {
|
if auth.is_authenticated() {
|
||||||
return Ok(TemplateResponse::redirect("/"));
|
return Ok(TemplateResponse::redirect("/"));
|
||||||
}
|
}
|
||||||
match boosted {
|
if boosted { Ok(TemplateResponse::new_partial(
|
||||||
true => Ok(TemplateResponse::new_partial(
|
"auth/signin_base.html",
|
||||||
"auth/signin_base.html",
|
"body",
|
||||||
"body",
|
(),
|
||||||
(),
|
)) } else { Ok(TemplateResponse::new_template("auth/signin_base.html", ())) }
|
||||||
)),
|
|
||||||
false => Ok(TemplateResponse::new_template("auth/signin_base.html", ())),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn authenticate_user(
|
pub async fn authenticate_user(
|
||||||
|
|||||||
@@ -29,14 +29,11 @@ pub async fn show_signup_form(
|
|||||||
return Ok(TemplateResponse::redirect("/"));
|
return Ok(TemplateResponse::redirect("/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
match boosted {
|
if boosted { Ok(TemplateResponse::new_partial(
|
||||||
true => Ok(TemplateResponse::new_partial(
|
"auth/signup_form.html",
|
||||||
"auth/signup_form.html",
|
"body",
|
||||||
"body",
|
(),
|
||||||
(),
|
)) } else { Ok(TemplateResponse::new_template("auth/signup_form.html", ())) }
|
||||||
)),
|
|
||||||
false => Ok(TemplateResponse::new_template("auth/signup_form.html", ())),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn process_signup_and_show_verification(
|
pub async fn process_signup_and_show_verification(
|
||||||
@@ -48,7 +45,7 @@ pub async fn process_signup_and_show_verification(
|
|||||||
Ok(user) => user,
|
Ok(user) => user,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("{:?}", e);
|
tracing::error!("{:?}", e);
|
||||||
return Ok(Html(format!("<p>{}</p>", e)).into_response());
|
return Ok(Html(format!("<p>{e}</p>")).into_response());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ pub async fn new_user_message(
|
|||||||
|
|
||||||
if conversation.user_id != user.id {
|
if conversation.user_id != user.id {
|
||||||
return Ok(TemplateResponse::unauthorized().into_response());
|
return Ok(TemplateResponse::unauthorized().into_response());
|
||||||
};
|
}
|
||||||
|
|
||||||
let user_message = Message::new(conversation_id, MessageRole::User, form.content, None);
|
let user_message = Message::new(conversation_id, MessageRole::User, form.content, None);
|
||||||
|
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ pub async fn get_response_stream(
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
yield Ok(Event::default()
|
yield Ok(Event::default()
|
||||||
.event("error")
|
.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 {
|
.chain(stream::once(async move {
|
||||||
if let Some(message) = rx_final.recv().await {
|
if let Some(message) = rx_final.recv().await {
|
||||||
// Don't send any event if references is empty
|
// 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
|
return Ok(Event::default().event("empty")); // This event won't be sent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ pub async fn delete_text_content(
|
|||||||
"dashboard/recent_content.html",
|
"dashboard/recent_content.html",
|
||||||
"latest_content_section",
|
"latest_content_section",
|
||||||
LatestTextContentData {
|
LatestTextContentData {
|
||||||
user: user.to_owned(),
|
user: user.clone(),
|
||||||
text_contents,
|
text_contents,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user