Move extract_field to util

This commit is contained in:
2025-05-06 01:24:30 +00:00
parent 58b5ed6d3f
commit 68778615b9
3 changed files with 16 additions and 13 deletions

View File

@ -7,6 +7,7 @@ cfg_if! {
if #[cfg(feature = "ssr")] {
use multer::Field;
use crate::util::database::get_db_conn;
use crate::util::extract_field::extract_field;
use diesel::prelude::*;
use log::*;
use server_fn::error::NoCustomError;
@ -14,19 +15,6 @@ cfg_if! {
}
}
/// Extract the text from a multipart field
#[cfg(feature = "ssr")]
async fn extract_field(field: Field<'static>) -> Result<String, ServerFnError> {
let field = match field.text().await {
Ok(field) => field,
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!(
"Error reading field: {e}"
)))?,
};
Ok(field)
}
/// Validate the artist ids in a multipart field
/// Expects a field with a comma-separated list of artist ids, and ensures each is a valid artist id in the database
#[cfg(feature = "ssr")]

14
src/util/extract_field.rs Normal file
View File

@ -0,0 +1,14 @@
use multer::Field;
use server_fn::{error::NoCustomError, ServerFnError};
/// Extract the text from a multipart field
pub async fn extract_field(field: Field<'static>) -> Result<String, ServerFnError> {
let field = match field.text().await {
Ok(field) => field,
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!(
"Error reading field: {e}"
)))?,
};
Ok(field)
}

View File

@ -8,6 +8,7 @@ cfg_if! {
pub mod database;
pub mod auth_backend;
pub mod redis;
pub mod extract_field;
}
}