mirror of
https://github.com/perstarkse/minne.git
synced 2026-05-15 04:10:32 +02:00
feat: existing user_categories are options
This commit is contained in:
@@ -176,88 +176,6 @@ async fn get_and_validate_text_content(
|
||||
|
||||
Ok(text_content)
|
||||
}
|
||||
// pub async fn delete_text_content(
|
||||
// State(state): State<AppState>,
|
||||
// auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
|
||||
// Path(id): Path<String>,
|
||||
// ) -> Result<impl IntoResponse, HtmlError> {
|
||||
// let user = match &auth.current_user {
|
||||
// Some(user) => user,
|
||||
// None => return Ok(Redirect::to("/").into_response()),
|
||||
// };
|
||||
|
||||
// // Get TextContent from db
|
||||
// let text_content = match get_item::<TextContent>(&state.surreal_db_client, &id)
|
||||
// .await
|
||||
// .map_err(|e| HtmlError::new(AppError::from(e), state.templates.clone()))?
|
||||
// {
|
||||
// Some(text_content) => text_content,
|
||||
// None => {
|
||||
// return Err(HtmlError::new(
|
||||
// AppError::NotFound("No item found".to_string()),
|
||||
// state.templates,
|
||||
// ))
|
||||
// }
|
||||
// };
|
||||
|
||||
// // Validate that the user is the owner
|
||||
// if text_content.user_id != user.id {
|
||||
// return Err(HtmlError::new(
|
||||
// AppError::Auth("You are not the owner of that content".to_string()),
|
||||
// state.templates,
|
||||
// ));
|
||||
// }
|
||||
|
||||
// // If TextContent has file_info, delete it from db and file from disk.
|
||||
// if text_content.file_info.is_some() {
|
||||
// FileInfo::delete_by_id(
|
||||
// &text_content.file_info.unwrap().id,
|
||||
// &state.surreal_db_client,
|
||||
// )
|
||||
// .await
|
||||
// .map_err(|e| HtmlError::new(AppError::from(e), state.templates.clone()))?;
|
||||
// }
|
||||
|
||||
// // Delete textcontent from db
|
||||
// delete_item::<TextContent>(&state.surreal_db_client, &text_content.id)
|
||||
// .await
|
||||
// .map_err(|e| HtmlError::new(AppError::from(e), state.templates.clone()))?;
|
||||
|
||||
// // Delete TextChunks
|
||||
// TextChunk::delete_by_source_id(&text_content.id, &state.surreal_db_client)
|
||||
// .await
|
||||
// .map_err(|e| HtmlError::new(e, state.templates.clone()))?;
|
||||
|
||||
// // Delete KnowledgeEntities
|
||||
// KnowledgeEntity::delete_by_source_id(&text_content.id, &state.surreal_db_client)
|
||||
// .await
|
||||
// .map_err(|e| HtmlError::new(e, state.templates.clone()))?;
|
||||
|
||||
// // Delete KnowledgeRelationships
|
||||
// KnowledgeRelationship::delete_relationships_by_source_id(
|
||||
// &text_content.id,
|
||||
// &state.surreal_db_client,
|
||||
// )
|
||||
// .await
|
||||
// .map_err(|e| HtmlError::new(e, state.templates.clone()))?;
|
||||
|
||||
// // Get latest text contents after updates
|
||||
// let latest_text_contents = User::get_latest_text_contents(&user.id, &state.surreal_db_client)
|
||||
// .await
|
||||
// .map_err(|e| HtmlError::new(e, state.templates.clone()))?;
|
||||
|
||||
// let output = render_block(
|
||||
// "index/signed_in/recent_content.html",
|
||||
// "latest_content_section",
|
||||
// LatestTextContentData {
|
||||
// user: user.clone(),
|
||||
// latest_text_contents,
|
||||
// },
|
||||
// state.templates.clone(),
|
||||
// )?;
|
||||
|
||||
// Ok(output.into_response())
|
||||
// }
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ActiveJobsData {
|
||||
|
||||
@@ -20,6 +20,11 @@ use crate::{
|
||||
|
||||
use super::render_template;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ShowIngressFormData {
|
||||
user_categories: Vec<String>,
|
||||
}
|
||||
|
||||
pub async fn show_ingress_form(
|
||||
State(state): State<AppState>,
|
||||
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
|
||||
@@ -28,7 +33,15 @@ pub async fn show_ingress_form(
|
||||
return Ok(Redirect::to("/").into_response());
|
||||
}
|
||||
|
||||
let output = render_template("ingress_form.html", {}, state.templates.clone())?;
|
||||
let user_categories = User::get_user_categories(&auth.id, &state.surreal_db_client)
|
||||
.await
|
||||
.map_err(|e| HtmlError::new(e, state.templates.clone()))?;
|
||||
|
||||
let output = render_template(
|
||||
"ingress_form.html",
|
||||
ShowIngressFormData { user_categories },
|
||||
state.templates.clone(),
|
||||
)?;
|
||||
|
||||
Ok(output.into_response())
|
||||
}
|
||||
|
||||
41
src/server/routes/html/knowledge/entities.rs
Normal file
41
src/server/routes/html/knowledge/entities.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
response::{IntoResponse, Redirect},
|
||||
};
|
||||
use axum_session::Session;
|
||||
use axum_session_auth::AuthSession;
|
||||
use axum_session_surreal::SessionSurrealPool;
|
||||
use surrealdb::{engine::any::Any, Surreal};
|
||||
use tokio::join;
|
||||
use tracing::info;
|
||||
|
||||
use crate::{
|
||||
error::{AppError, HtmlError},
|
||||
page_data,
|
||||
server::{
|
||||
routes::html::{render_block, render_template},
|
||||
AppState,
|
||||
},
|
||||
storage::{
|
||||
db::{delete_item, get_item},
|
||||
types::{
|
||||
file_info::FileInfo, job::Job, knowledge_entity::KnowledgeEntity,
|
||||
knowledge_relationship::KnowledgeRelationship, text_chunk::TextChunk,
|
||||
text_content::TextContent, user::User,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
page_data!(KnowledgeEntitiesData, "todo", {
|
||||
gdpr_accepted: bool,
|
||||
user: Option<User>,
|
||||
latest_text_contents: Vec<TextContent>,
|
||||
active_jobs: Vec<Job>
|
||||
});
|
||||
pub async fn index_handler(
|
||||
State(state): State<AppState>,
|
||||
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
|
||||
session: Session<SessionSurrealPool<Any>>,
|
||||
) -> Result<impl IntoResponse, HtmlError> {
|
||||
Ok("Hi".into_response())
|
||||
}
|
||||
Reference in New Issue
Block a user