user restricted to own objects

This commit is contained in:
Per Stark
2024-12-15 22:52:34 +01:00
parent 646792291c
commit cf6078eceb
18 changed files with 109 additions and 28 deletions

View File

@@ -56,6 +56,7 @@ pub enum IngressContentError {
pub async fn create_ingress_objects(
input: IngressInput,
db_client: &SurrealDbClient,
user_id: &str,
) -> Result<Vec<IngressObject>, IngressContentError> {
// Initialize list
let mut object_list = Vec::new();
@@ -69,6 +70,7 @@ pub async fn create_ingress_objects(
url: url.to_string(),
instructions: input.instructions.clone(),
category: input.category.clone(),
user_id: user_id.into(),
});
}
Err(_) => {
@@ -77,6 +79,7 @@ pub async fn create_ingress_objects(
text: input_content.to_string(),
instructions: input.instructions.clone(),
category: input.category.clone(),
user_id: user_id.into(),
});
}
}
@@ -90,6 +93,7 @@ pub async fn create_ingress_objects(
file_info,
instructions: input.instructions.clone(),
category: input.category.clone(),
user_id: user_id.into(),
});
} else {
info!("No file with id: {}", id);

View File

@@ -10,16 +10,19 @@ pub enum IngressObject {
url: String,
instructions: String,
category: String,
user_id: String,
},
Text {
text: String,
instructions: String,
category: String,
user_id: String,
},
File {
file_info: FileInfo,
instructions: String,
category: String,
user_id: String,
},
}
@@ -37,6 +40,7 @@ impl IngressObject {
url,
instructions,
category,
user_id,
} => {
let text = Self::fetch_text_from_url(url).await?;
Ok(TextContent::new(
@@ -44,22 +48,26 @@ impl IngressObject {
instructions.into(),
category.into(),
None,
user_id.into(),
))
}
IngressObject::Text {
text,
instructions,
category,
user_id,
} => Ok(TextContent::new(
text.into(),
instructions.into(),
category.into(),
None,
user_id.into(),
)),
IngressObject::File {
file_info,
instructions,
category,
user_id,
} => {
let text = Self::extract_text_from_file(file_info).await?;
Ok(TextContent::new(
@@ -67,6 +75,7 @@ impl IngressObject {
instructions.into(),
category.into(),
Some(file_info.to_owned()),
user_id.into(),
))
}
}