use axum::extract::{Multipart, State}; use sqlx::SqlitePool; use askama_axum::{IntoResponse, Response}; use anyhow::anyhow; use tracing::info; use crate::error::AppError; use crate::ingest::catalog::ingest_catalog_bytes; use crate::session::SessionUser; pub async fn catalog_import( State(db): State, user: SessionUser, mut multipart: Multipart, ) -> Result { let mut filename = "".to_owned(); while let Some(field) = multipart.next_field().await? { filename = field.file_name().ok_or(anyhow!("field missing filename"))?.to_string(); let name = field.name().ok_or(anyhow!("field missing name"))?.to_string(); let content_type = field.content_type().ok_or(anyhow!("field missing content type"))?.to_string(); let data = field.bytes().await?; info!("Name: {}, file: {}, content: {}, data: {} bytes", name, filename, content_type, data.len()); ingest_catalog_bytes(data, db.clone(), user.id).await?; } Ok(format!("File {} uploaded successfully", filename).into_response()) }