From 0b4785681e05b1b7d12a9f2ea4dfdcfc73bdc521 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sun, 7 Apr 2024 21:43:48 -0400 Subject: [PATCH] Added rust code --- Cargo.toml | 12 +++++ src/main.rs | 82 +++++++++++++++++++++++++++++ src/managers/action_managers.rs | 52 +++++++++++++++++++ src/managers/commit_manager.rs | 92 +++++++++++++++++++++++++++++++++ src/managers/mod.rs | 0 src/managers/user_manager.rs | 21 ++++++++ src/models/api.rs | 8 +++ src/models/flags.rs | 7 +++ src/models/icarus_action.rs | 18 +++++++ src/models/mod.rs | 0 src/models/song.rs | 48 +++++++++++++++++ src/models/token.rs | 8 +++ src/models/upload_form.rs | 7 +++ src/models/user.rs | 7 +++ src/parsers/api_parser.rs | 0 src/parsers/mod.rs | 0 src/syncers/delete.rs | 0 src/syncers/download.rs | 0 src/syncers/mod.rs | 0 src/syncers/retrieve_records.rs | 0 src/syncers/syncer_base.rs | 0 src/syncers/upload.rs | 0 src/utilities/checks.rs | 24 +++++++++ src/utilities/conversions.rs | 19 +++++++ src/utilities/mod.rs | 0 25 files changed, 405 insertions(+) create mode 100644 Cargo.toml create mode 100644 src/main.rs create mode 100644 src/managers/action_managers.rs create mode 100644 src/managers/commit_manager.rs create mode 100644 src/managers/mod.rs create mode 100644 src/managers/user_manager.rs create mode 100644 src/models/api.rs create mode 100644 src/models/flags.rs create mode 100644 src/models/icarus_action.rs create mode 100644 src/models/mod.rs create mode 100644 src/models/song.rs create mode 100644 src/models/token.rs create mode 100644 src/models/upload_form.rs create mode 100644 src/models/user.rs create mode 100644 src/parsers/api_parser.rs create mode 100644 src/parsers/mod.rs create mode 100644 src/syncers/delete.rs create mode 100644 src/syncers/download.rs create mode 100644 src/syncers/mod.rs create mode 100644 src/syncers/retrieve_records.rs create mode 100644 src/syncers/syncer_base.rs create mode 100644 src/syncers/upload.rs create mode 100644 src/utilities/checks.rs create mode 100644 src/utilities/conversions.rs create mode 100644 src/utilities/mod.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..13088dc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "IcarusDownloadManager" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0.197", features = ["derive"] } +serde_json = "1.0.115" +# rodio = "0.17.3" +# metadata = "0.1.8" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..d23bb23 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,82 @@ +mod managers; +mod models; + +use std::env; +use std::process; + +// use managers::ActionManager; +// use models::{user, upload_form}; + +// use models:: + + +fn exit_program(code: i32) { + process::exit(code); +} + +fn print_help() { + let msg: String = String::from(r#"icd [Action] [flag] + + Actions + download + upload + upload-meta + retrieve + delete + + Flags + Required for all actions + -u username + -p password + -h host + + Required for upload + -s path of song + -sd directory where to search for songs to upload (Optional) + -sr directory where to recursively search for songs to upload (Optional) + -nc will not prompt the user when uploading from a directory + + Required for upload with metadata + -s path of song + -t track number + -m metadata filepath + -ca coverart filepath + -scma directory where songs, metadata, and cover art exists and will be uploaded (Optional) + + Required for download + -b song id + -d path to download song (Optional) + + Required for retrieving records + -rt retrieve type (songs is only accepted) + + Required for deleting a song + -D song id"#); + + println!("{}", msg); +} + +fn main() { + let args: Vec = env::args().collect(); + + if args.len() == 0 { + print_help(); + exit_program(-1); + } + + let act_mgr = managers::ActionManager { + action: String::from(""), + flags: Vec::new(), + params: args, + param_count: args.len(), + }; + + let chosen_act = act_mgr.retrieve_icarus_action(); + + chosen_act.print_action_and_flags(); + + let cmt_mgr = managers::CommitManager { + }; + + cmt_mgr.commit_action(); +} diff --git a/src/managers/action_managers.rs b/src/managers/action_managers.rs new file mode 100644 index 0000000..34db17e --- /dev/null +++ b/src/managers/action_managers.rs @@ -0,0 +1,52 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct ActionManager { + action: String, + flags: Vec, + params: Vec, + param_count: i32, +} + +impl ActionManager { + // TODO: Implement + pub fn retrieve_icarus_action(&self) -> models::IcarusAction { + return models::IcarusAction { + action: String::from(""), + flags: Vec::new(), + }; + } + + // TODO: Implement + fn supported_flags(&self) -> Vec { + return Vec::new(); + } + + // TODO: Implement + fn supported_actions(&self) { + } + // TODO: Implement + fn initialize(&self) { + } + // TODO: Implement + fn validate_flags(&self) { + } + // TODO: Implement + fn is_valid_flag(&self, flag: &String) -> bool{ + return false; + } + // TODO: Implement + fn does_flag_have_value(&self, flag: &String) -> bool { + return false; + } + // TODO: Implement + fn print_action(&self) { + } + // TODO: Implement + fn print_flags(&self) { + } + // TODO: Implement + fn parsed_flags(&self) -> Vec { + return Vec::new(); + } +} diff --git a/src/managers/commit_manager.rs b/src/managers/commit_manager.rs new file mode 100644 index 0000000..68c9490 --- /dev/null +++ b/src/managers/commit_manager.rs @@ -0,0 +1,92 @@ +use std::collections::HashMap; + +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct CommitManager { + action: String, + flags: Vec, + params: Vec, + param_count: i32, + ica_action: models::IcarusAction, +} + +struct Album { + pub title: String, + pub album_artist: String, + pub genre: String, + pub year: i32, + pub track_count: i32, + pub disc_count: i32, + pub songs: Vec, + +} + +enum ActionValues { + DeleteAct, + DownloadAct, + RetrieveAct, + UploadAct, + UploadSongWithMetadata, +} + +enum RetrieveTypes { + Songs +} + +impl Album { + // TODO: Implement + pub fn print_info(&self) { + } +} + +impl CommitManager { + // TODO: Implement + pub fn commit_action(&self) { + } + + // TODO: Implement + fn map_actions(&self) -> HashMap { + return HashMap::new(); + } + + // TODO: Implement + fn parse_token(&self, api: &models::API) { + } + // TODO: Implement + fn upload_song_with_metadata(&self) { + } + // TODO: Implement + fn sing_target_upload(&self, songpath: &String, track_id: &String, + meta_path: &String, cover_path: &String) { + } + // TODO: Implement + fn multi_target_upload(&self, sourcepath: &String) { + } + // TODO: Implement + fn initialize_disc_and_track(&self, song: &Song) { + } + // TODO: Implement + fn parse_disc_and_track(&self, song: &Song, track_id: &String) { + } + // TODO: Implement + fn check_for_no_confirm(&self) -> bool { + return false; + } + // TODO: Implement + fn retrieve_metadata(&self, path: &String) -> models::Album { + return Album { + title: String::from(""), + album_artist: String::from(""), + genre: String::from(""), + year: 0, + track_count: 0, + disc_count: 0, + songs: Vec::new(), + }; + } + // TODO: Implement + fn retrieve_file_content(&self, path: &String) -> String { + return String::from(""); + } +} diff --git a/src/managers/mod.rs b/src/managers/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/managers/user_manager.rs b/src/managers/user_manager.rs new file mode 100644 index 0000000..217c374 --- /dev/null +++ b/src/managers/user_manager.rs @@ -0,0 +1,21 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct UserManager { + user: models::User, + ica_action: models::IcarusAction, +} + +impl UserManager { + // TODO: Implement + pub fn retrieve_user(&self) -> models::User { + return models::User { + username: String::from(""), + password: String::from(""), + }; + } + + // TODO: Implement + fn parse_user_from_actions(&self) { + } +} diff --git a/src/models/api.rs b/src/models/api.rs new file mode 100644 index 0000000..4df4aa5 --- /dev/null +++ b/src/models/api.rs @@ -0,0 +1,8 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct API { + pub url: String, + pub endpoint: String, + pub version: String, +} diff --git a/src/models/flags.rs b/src/models/flags.rs new file mode 100644 index 0000000..8748262 --- /dev/null +++ b/src/models/flags.rs @@ -0,0 +1,7 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct Flags { + pub flag: String, + pub value: String, +} diff --git a/src/models/icarus_action.rs b/src/models/icarus_action.rs new file mode 100644 index 0000000..4ea0847 --- /dev/null +++ b/src/models/icarus_action.rs @@ -0,0 +1,18 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct IcarusAction { + pub action: String, + pub flags: Vec, +} + +impl IcarusAction { + // TODO: Implement + pub fn retrieve_flag_value(&self, flag: &String) -> String { + return String::from(""); + } + + // TODO: Implement + pub fn print_action_and_flags(&self) { + } +} diff --git a/src/models/mod.rs b/src/models/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/models/song.rs b/src/models/song.rs new file mode 100644 index 0000000..a0fd312 --- /dev/null +++ b/src/models/song.rs @@ -0,0 +1,48 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct Song { + pub id: i32, + pub title: String, + pub artist: String, + pub album: String, + pub genre: String, + pub year: int, + pub duration: f64, + pub track: i32, + pub disc: i32, + pub data: String, + // use filepath instead + // pub song_path: String, + pub filepath: String, + pub directory: String, +} + +impl Song { + // TODO: Implement + pub fn print_info(&self) { + } + + // TODO: Implement + pub fn song_path(&self) -> String { + return String::from(""); + } + + // TODO: Implement + pub fn generate_filename_from_track() -> i32 { + return 0; + } + + // TODO: Implement + pub fn to_metadata_json() -> String { + return String::from(""); + } +} + + +#[derive(Debug, Deserialize, Serialize)] +struct CoverArt { + pub id: i32, + pub title: String, + pub path: String, +} \ No newline at end of file diff --git a/src/models/token.rs b/src/models/token.rs new file mode 100644 index 0000000..9710ecd --- /dev/null +++ b/src/models/token.rs @@ -0,0 +1,8 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct Token { + pub access_token: String, + pub token_type: String, + pub expiration: i32, +} diff --git a/src/models/upload_form.rs b/src/models/upload_form.rs new file mode 100644 index 0000000..1f78b56 --- /dev/null +++ b/src/models/upload_form.rs @@ -0,0 +1,7 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct UploadForm { + pub url: String, + pub filepath: String, +} \ No newline at end of file diff --git a/src/models/user.rs b/src/models/user.rs new file mode 100644 index 0000000..c352bad --- /dev/null +++ b/src/models/user.rs @@ -0,0 +1,7 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct User { + pub username: String, + pub password: String, +} \ No newline at end of file diff --git a/src/parsers/api_parser.rs b/src/parsers/api_parser.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/parsers/mod.rs b/src/parsers/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/syncers/delete.rs b/src/syncers/delete.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/syncers/download.rs b/src/syncers/download.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/syncers/mod.rs b/src/syncers/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/syncers/retrieve_records.rs b/src/syncers/retrieve_records.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/syncers/syncer_base.rs b/src/syncers/syncer_base.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/syncers/upload.rs b/src/syncers/upload.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/utilities/checks.rs b/src/utilities/checks.rs new file mode 100644 index 0000000..e7bca40 --- /dev/null +++ b/src/utilities/checks.rs @@ -0,0 +1,24 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct Checks { +} + +impl Checks { + // TODO: Implement + pub fn is_number(val: &String) -> bool { + return false; + } + + // TODO: Implement + pub fn item_in_container(container: &Vec, item: &String, + func: fn(a: &String, b: &String) -> String) -> String { + return String::from(""); + } + + // TODO: Implement + pub fn item_iter_in_container(container: &Vec, item: &String, + func: fn(a: &String, b: &String) -> String) -> String { + return String::from(""); + } +} diff --git a/src/utilities/conversions.rs b/src/utilities/conversions.rs new file mode 100644 index 0000000..d55ccae --- /dev/null +++ b/src/utilities/conversions.rs @@ -0,0 +1,19 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct Conversions { +} + +impl Conversions { + // TODO: Implement + pub fn to_lower_char(val: &mut String) { + } + + // TODO: Implement + pub fn initialize_values(&self) { + } + + // TODO: Implement + pub fn print_value(&self, val: i32) { + } +} diff --git a/src/utilities/mod.rs b/src/utilities/mod.rs new file mode 100644 index 0000000..e69de29