icarus_models related changes

This commit is contained in:
kdeng00
2025-10-19 23:33:21 -04:00
parent 71921a6579
commit 5dd4464643
2 changed files with 32 additions and 11 deletions
+31 -10
View File
@@ -349,11 +349,11 @@ impl CommitManager {
panic!("Error");
}
let pa = std::path::Path::new(&cover_path);
let mut cover_art = icarus_models::coverart::CoverArt {
id: uuid::Uuid::nil(),
title: String::new(),
path: cover_path.to_owned(),
data: Vec::new(),
directory: String::from(pa.parent().unwrap().to_str().unwrap()),
filename: String::from(pa.file_name().unwrap().to_str().unwrap()),
..Default::default()
};
let file_name = std::ffi::OsString::from(&song_file.file_name().unwrap());
@@ -497,7 +497,6 @@ impl CommitManager {
};
songs.push(icarus_models::song::Song {
id: uuid::Uuid::nil(),
title: track.title.clone(),
artist: track.artist.clone(),
disc: track.disc,
@@ -512,9 +511,7 @@ impl CommitManager {
audio_type: String::from("FLAC"),
directory: source_directory.to_owned(),
filename: song_filename,
user_id: uuid::Uuid::nil(),
data: Vec::new(),
date_created: String::new(),
..Default::default()
});
}
Ok(songs)
@@ -539,9 +536,11 @@ impl CommitManager {
panic!("Directory does not exist");
}
let coverart_path = self.get_cover_art_path(sourcepath).unwrap_or_default();
// let coverart_path = self.get_cover_art_path(sourcepath).unwrap_or_default();
let (coverart_directory, coverart_filename) = self.get_coverart_dir_and_filename(&sourcepath).unwrap();
// let mut cover_art =
let mut cover_art =
icarus_models::coverart::init::init_coverart_only_path(coverart_path.clone());
icarus_models::coverart::init::init_coverart_dir_and_filename(&coverart_directory, &coverart_filename);
let metadatapath = self.get_metadata_path(sourcepath).unwrap_or_default();
let mut up = syncers::upload::Upload::default();
@@ -607,6 +606,28 @@ impl CommitManager {
Ok(String::new())
}
fn get_coverart_dir_and_filename(&self, directory: &str) -> Result<(String, String)> {
for entry in read_dir(std::path::Path::new(directory))? {
let entry = entry?;
let file_type = entry.file_type();
let file_name = entry.file_name();
println!("file type: {file_type:?}");
println!("file name: {file_name:?}");
if let En::ImageFile = self.find_file_extension(&file_name) {
// let directory_part = directory.clone();
let fname = utilities::string::o_to_string(&file_name);
return Ok((directory.to_string(), fname.unwrap()));
// let fullpath = format!("{}/{}", directory_part, &fname.unwrap());
// return Ok(fullpath);
}
}
Ok((String::new(), String::new()))
}
fn find_file_extension(&self, file_name: &std::ffi::OsString) -> En {
let file_name_str = Some(file_name.clone().into_string());
+1 -1
View File
@@ -176,7 +176,7 @@ impl Upload {
token: &icarus_models::token::AccessToken,
coverart: &icarus_models::coverart::CoverArt,
) -> Result<uuid::Uuid, reqwest::Error> {
let coverartpath = coverart.path.clone();
let coverartpath = coverart.get_path().unwrap();
let file = tokio::fs::File::open(&coverartpath).await.unwrap();
let stream = tokio_util::codec::FramedRead::new(file, tokio_util::codec::BytesCodec::new());
let file_body = reqwest::Body::wrap_stream(stream);