actually return file paths in FileSystem::save

This commit is contained in:
2025-07-29 15:22:32 +02:00
parent 77be84da65
commit 45368dcc9a
2 changed files with 21 additions and 7 deletions

View File

@@ -151,9 +151,21 @@ impl AsRef<Path> for FilePath {
}
impl RelativeFilePath {
/* pub fn new(path: FilePath) -> Self {
Self(path.0.trim_start_matches('/').to_owned())
} */
pub fn new(path: FilePath) -> Result<Self, RelativeFilePathError> {
Self::from_str(&path.0)
}
pub fn from_str(raw: &str) -> Result<Self, RelativeFilePathError> {
if raw.starts_with("/") {
return Err(RelativeFilePathError::Absolute);
}
if raw.is_empty() {
return Err(RelativeFilePathError::Empty);
}
Ok(Self(raw.to_owned()))
}
pub fn join(mut self, other: &RelativeFilePath) -> Self {
self.0.push('/');
@@ -197,6 +209,8 @@ pub enum FilePathError {
#[derive(Clone, Debug, Error)]
pub enum RelativeFilePathError {
#[error("The path is empty")]
Empty,
#[error("A relative file path must not with a slash")]
Absolute,
}

View File

@@ -167,12 +167,10 @@ impl FileSystem {
) -> anyhow::Result<Vec<AbsoluteFilePath>> {
let base_path = self.get_target_path(path);
let paths = Vec::new();
let mut paths = Vec::new();
while let Ok(Some(mut upload_file)) = stream.try_next().await {
// TODO: Refactor this result question mark chain thing
let file_name_as_path: RelativeFilePath =
FilePath::new(upload_file.file_name().as_str())?.try_into()?;
let file_name_as_path = RelativeFilePath::from_str(upload_file.file_name().as_str())?;
let file_path = base_path.join(&file_name_as_path);
let mut file = fs::OpenOptions::new()
@@ -184,6 +182,8 @@ impl FileSystem {
while let Ok(Some(chunk)) = upload_file.try_next().await {
file.write(&chunk).await?;
}
paths.push(path.clone().join(&file_name_as_path));
}
Ok(paths)