mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-29 04:07:04 +02:00
mvp file to ingress fn
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
use std::hash::Hash;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
use tracing::info;
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
use crate::redis::client::RedisClient;
|
||||
|
||||
use super::file_info::FileInfo;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
@@ -48,7 +53,8 @@ pub enum IngressContentError {
|
||||
impl IngressContent {
|
||||
/// Create a new `IngressContent` from `IngressInput`.
|
||||
pub async fn new(
|
||||
input: IngressInput
|
||||
input: IngressInput,
|
||||
redis_client: &RedisClient, // Add RedisClient as a parameter
|
||||
) -> Result<IngressContent, IngressContentError> {
|
||||
let content = if let Some(input_content) = input.content {
|
||||
// Check if the content is a URL
|
||||
@@ -63,15 +69,26 @@ impl IngressContent {
|
||||
None
|
||||
};
|
||||
|
||||
// Check if there is files
|
||||
// Use FileInfo.get(id) with all the ids in files vec
|
||||
// Return a vec<FileInfo> as file_info_list
|
||||
// Fetch file information if file UUIDs are provided
|
||||
let files = if let Some(file_uuids) = input.files {
|
||||
let mut file_info_list = Vec::new();
|
||||
for uuid_str in file_uuids {
|
||||
let uuid = Uuid::parse_str(&uuid_str).map_err(|_| IngressContentError::UnsupportedMime("Invalid UUID".into()))?;
|
||||
match FileInfo::get(uuid, redis_client).await {
|
||||
Ok(file_info) => file_info_list.push(file_info),
|
||||
Err(_) => info!("No file with that uuid"),
|
||||
}
|
||||
}
|
||||
Some(file_info_list)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(IngressContent {
|
||||
content,
|
||||
instructions: input.instructions,
|
||||
category: input.category,
|
||||
files: None,
|
||||
files,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user