Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2188c2b746 | |||
| 9328f3d3da | |||
| ca13f101d7 | |||
| 1e4ffc798e | |||
| ecd025346c | |||
| 74184fa022 | |||
| c2a2ca049d |
@@ -2,9 +2,9 @@ name: Rust
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "master", "icarus_v2_support" ]
|
||||
branches: [ "main" ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@@ -15,9 +15,9 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- name: Install Rust version
|
||||
run: rustup install 1.88.0 && rustup default 1.88.0
|
||||
run: rustup install 1.90.0 && rustup default 1.90.0
|
||||
|
||||
- name: Debug secret
|
||||
run: echo "${{ secrets.MYREPO_TOKEN }}" | head -c 10 ; echo "..."
|
||||
|
||||
Generated
+376
-347
File diff suppressed because it is too large
Load Diff
+9
-9
@@ -1,17 +1,17 @@
|
||||
[package]
|
||||
name = "icarus-dm"
|
||||
version = "0.7.0"
|
||||
rust-version = "1.88"
|
||||
version = "0.8.4"
|
||||
rust-version = "1.90"
|
||||
edition = "2024"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[dependencies]
|
||||
futures = { version = "0.3.31" }
|
||||
http = { version = "1.3.1" }
|
||||
reqwest = { version = "0.12.20", features = ["json", "blocking", "multipart", "stream"] }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_json = "1.0.140"
|
||||
tokio = { version = "1.45.1", features = ["full"] }
|
||||
tokio-util = { version = "0.7.15", features = ["codec"] }
|
||||
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.6" }
|
||||
reqwest = { version = "0.12.23", features = ["json", "blocking", "multipart", "stream"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.145"
|
||||
tokio = { version = "1.47.1", features = ["full"] }
|
||||
tokio-util = { version = "0.7.16", features = ["codec"] }
|
||||
uuid = { version = "1.18.1", features = ["v4", "serde"] }
|
||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.8.0" }
|
||||
|
||||
+4
-1
@@ -30,7 +30,10 @@ pub fn print_help() {
|
||||
-rt retrieve type (songs is only accepted)
|
||||
|
||||
Required for deleting a song
|
||||
-D song id"#,
|
||||
-D song id
|
||||
|
||||
Print version
|
||||
-v"#,
|
||||
);
|
||||
|
||||
println!("{msg}");
|
||||
|
||||
+8
-3
@@ -4,6 +4,7 @@ mod models;
|
||||
mod parsers;
|
||||
mod syncers;
|
||||
mod utilities;
|
||||
mod version;
|
||||
|
||||
use std::env;
|
||||
|
||||
@@ -17,13 +18,17 @@ async fn main() {
|
||||
utilities::checks::exit_program(-1);
|
||||
}
|
||||
|
||||
println!("Argument count: {args_len}");
|
||||
|
||||
let mut act_mgr = managers::action_managers::ActionManager::default();
|
||||
act_mgr.set_params(&args);
|
||||
act_mgr.initialize();
|
||||
|
||||
let chosen_act = act_mgr.retrieve_icarus_action();
|
||||
for act in &chosen_act.flags {
|
||||
if act.flag == "-v" {
|
||||
version::print_version();
|
||||
utilities::checks::exit_program(-1);
|
||||
}
|
||||
}
|
||||
chosen_act.print_action_and_flags();
|
||||
|
||||
let mut cmt_mgr = managers::commit_manager::CommitManager {
|
||||
@@ -63,7 +68,7 @@ mod tests {
|
||||
match managers::commit_manager::retrieve_song(
|
||||
&album, track, disc, &directory, &filename,
|
||||
) {
|
||||
Ok(song) => match song.to_data() {
|
||||
Ok(song) => match icarus_models::song::io::to_data(&song) {
|
||||
Ok(_) => {
|
||||
print!("Success");
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ impl ActionManager {
|
||||
String::from("-ca"),
|
||||
String::from("-smca"),
|
||||
String::from("-t"),
|
||||
String::from("-v"),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -63,31 +64,24 @@ impl ActionManager {
|
||||
}
|
||||
|
||||
fn validate_flags(&mut self) {
|
||||
println!("Validating flags");
|
||||
|
||||
let flag_vals = self.parsed_flags();
|
||||
|
||||
let mut i = 0;
|
||||
println!("Flag count: {}", flag_vals.len());
|
||||
|
||||
while i < flag_vals.len() {
|
||||
let flag = &flag_vals[i];
|
||||
println!("Index: {i} | Value: {flag}");
|
||||
|
||||
let mut flg = models::flags::Flags::default();
|
||||
|
||||
// TODO: Refactor this
|
||||
if self.is_valid_flag(flag) && self.does_flag_have_value(flag) {
|
||||
println!("Flag has value");
|
||||
flg.flag = String::from(flag);
|
||||
flg.value = String::from(&flag_vals[i + 1]);
|
||||
|
||||
i += 1;
|
||||
} else if self.is_valid_flag(flag) {
|
||||
println!("Flag does not have a value");
|
||||
flg.flag = String::from(flag);
|
||||
} else {
|
||||
println!("Flag {flag} is not valid");
|
||||
utilities::checks::exit_program(-1);
|
||||
}
|
||||
|
||||
@@ -155,10 +149,17 @@ impl ActionManager {
|
||||
fn parsed_flags(&self) -> Vec<String> {
|
||||
let mut parsed: Vec<String> = Vec::new();
|
||||
|
||||
if self.param_count <= 2 {
|
||||
let flag = String::from(&self.params[1]);
|
||||
if flag == "-v" {
|
||||
parsed.push(flag);
|
||||
}
|
||||
} else {
|
||||
for i in 2..self.params.len() {
|
||||
let flag = String::from(&self.params[i]);
|
||||
parsed.push(flag);
|
||||
}
|
||||
}
|
||||
|
||||
parsed
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
@@ -373,15 +373,16 @@ impl CommitManager {
|
||||
println!("Directory: {:?}", s.directory);
|
||||
println!("Filename: {:?}", s.filename);
|
||||
println!("Path: {:?}", s.song_path());
|
||||
s.data = s.to_data().unwrap();
|
||||
s.data = icarus_models::song::io::to_data(&s).unwrap();
|
||||
|
||||
cover_art.data = cover_art.to_data().unwrap();
|
||||
cover_art.data =
|
||||
icarus_models::coverart::io::to_data(&cover_art).unwrap();
|
||||
|
||||
let members = UploadSongMembers {
|
||||
song: s,
|
||||
coverart: cover_art,
|
||||
token: token,
|
||||
album: album,
|
||||
token,
|
||||
album,
|
||||
};
|
||||
|
||||
match self.upload_song_process(&members).await {
|
||||
@@ -496,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,
|
||||
@@ -511,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)
|
||||
@@ -538,23 +536,26 @@ impl CommitManager {
|
||||
panic!("Directory does not exist");
|
||||
}
|
||||
|
||||
let coverart_path = self.get_cover_art_path(sourcepath).unwrap_or_default();
|
||||
let mut cover_art =
|
||||
icarus_models::coverart::init::init_coverart_only_path(coverart_path.clone());
|
||||
let (coverart_directory, coverart_filename) =
|
||||
self.get_coverart_dir_and_filename(sourcepath).unwrap();
|
||||
let mut cover_art = 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();
|
||||
let host = self.ica_action.retrieve_flag_value(&String::from("-h"));
|
||||
up.set_api(&host);
|
||||
|
||||
cover_art.data = cover_art.to_data().unwrap();
|
||||
cover_art.data = icarus_models::coverart::io::to_data(&cover_art).unwrap();
|
||||
|
||||
match self.get_songs(&metadatapath, sourcepath) {
|
||||
Ok(sngs) => match icarus_models::album::collection::parse_album(&metadatapath) {
|
||||
Ok(album) => {
|
||||
for song in sngs {
|
||||
let members = UploadSongMembers {
|
||||
song: song,
|
||||
song,
|
||||
coverart: cover_art.clone(),
|
||||
token: token.clone(),
|
||||
album: album.clone(),
|
||||
@@ -585,8 +586,8 @@ impl CommitManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_cover_art_path(&self, directory_path: &String) -> Result<String> {
|
||||
for entry in read_dir(std::path::Path::new(directory_path))? {
|
||||
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();
|
||||
@@ -596,14 +597,12 @@ impl CommitManager {
|
||||
println!("file name: {file_name:?}");
|
||||
|
||||
if let En::ImageFile = self.find_file_extension(&file_name) {
|
||||
let directory_part = directory_path.clone();
|
||||
let fname = utilities::string::o_to_string(&file_name);
|
||||
let fullpath = format!("{}/{}", directory_part, &fname.unwrap());
|
||||
return Ok(fullpath);
|
||||
return Ok((directory.to_string(), fname.unwrap()));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(String::new())
|
||||
Ok((String::new(), String::new()))
|
||||
}
|
||||
|
||||
fn find_file_extension(&self, file_name: &std::ffi::OsString) -> En {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod api;
|
||||
pub mod flags;
|
||||
pub mod icarus_action;
|
||||
pub mod upload_form;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
use std::default::Default;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
pub struct UploadForm {
|
||||
pub url: Option<String>,
|
||||
pub filepath: Option<String>,
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -1,32 +1,3 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Checks {}
|
||||
|
||||
impl Checks {
|
||||
pub fn _is_numeric(text: &str) -> bool {
|
||||
text.parse::<f64>().is_ok()
|
||||
}
|
||||
|
||||
pub fn _index_of_item_in_container<F>(container: &str, item: &char, func: F) -> i32
|
||||
where
|
||||
F: Fn(&char, &char) -> bool,
|
||||
{
|
||||
let mut index = -1;
|
||||
|
||||
for c in container.chars() {
|
||||
if func(&c, item) {
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
|
||||
index += 1;
|
||||
}
|
||||
|
||||
index
|
||||
}
|
||||
}
|
||||
|
||||
pub fn exit_program(code: i32) {
|
||||
std::process::exit(code);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
pub fn print_version() {
|
||||
let name = env!("CARGO_PKG_NAME");
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
|
||||
println!("{name:?} {version:?}");
|
||||
}
|
||||
Reference in New Issue
Block a user