Support for icarus v2 API #52
@@ -1,22 +0,0 @@
|
|||||||
name: Rust
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "master" ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ "master" ]
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: macos-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Build
|
|
||||||
run: cargo build --verbose
|
|
||||||
- name: Run tests
|
|
||||||
run: cargo test --verbose
|
|
||||||
@@ -4,7 +4,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches: [ "master" ]
|
branches: [ "master" ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "master" ]
|
branches: [ "master", "icarus_v2_support" ]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|||||||
@@ -7,4 +7,3 @@
|
|||||||
|
|
||||||
/target
|
/target
|
||||||
.vscode/
|
.vscode/
|
||||||
Cargo.lock
|
|
||||||
|
|||||||
Generated
+1834
File diff suppressed because it is too large
Load Diff
+5
-9
@@ -4,18 +4,14 @@ version = "0.6.0"
|
|||||||
rust-version = "1.88"
|
rust-version = "1.88"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = { version = "0.3.31" }
|
futures = { version = "0.3.31" }
|
||||||
http = { version = "1.3.1" }
|
http = { version = "1.3.1" }
|
||||||
reqwest = { version = "0.12.15", features = ["json", "blocking", "multipart", "stream"] }
|
reqwest = { version = "0.12.20", features = ["json", "blocking", "multipart", "stream"] }
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
tokio = { version = "1.44.1", features = ["full"] }
|
tokio = { version = "1.45.1", features = ["full"] }
|
||||||
tokio-util = { version = "0.7.14", features = ["codec"] }
|
tokio-util = { version = "0.7.15", features = ["codec"] }
|
||||||
uuid = { version = "1.16.0", features = ["v4", "serde"] }
|
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
||||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.3" }
|
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.0-devel-7958b89abc-111" }
|
||||||
|
|||||||
+1
-1
@@ -32,5 +32,5 @@ pub fn print_help() {
|
|||||||
-D song id"#,
|
-D song id"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("{}", msg);
|
println!("{msg}");
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -16,7 +16,7 @@ fn main() {
|
|||||||
utilities::checks::exit_program(-1);
|
utilities::checks::exit_program(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Argument count: {}", args_len);
|
println!("Argument count: {args_len}");
|
||||||
|
|
||||||
let mut act_mgr = managers::action_managers::ActionManager::default();
|
let mut act_mgr = managers::action_managers::ActionManager::default();
|
||||||
act_mgr.set_params(&args);
|
act_mgr.set_params(&args);
|
||||||
@@ -41,7 +41,7 @@ mod tests {
|
|||||||
let meta_path = String::from("tests/sample2_tracks/album.json");
|
let meta_path = String::from("tests/sample2_tracks/album.json");
|
||||||
|
|
||||||
if !std::path::Path::new(&meta_path).exists() {
|
if !std::path::Path::new(&meta_path).exists() {
|
||||||
assert!(false, "File does not exists: {:?}", meta_path);
|
assert!(false, "File does not exists: {meta_path:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
match icarus_models::album::collection::parse_album(&meta_path) {
|
match icarus_models::album::collection::parse_album(&meta_path) {
|
||||||
|
|||||||
+6
-18
@@ -2,32 +2,20 @@ use crate::models;
|
|||||||
|
|
||||||
pub fn retrieve_url(api: &models::api::API, with_id: bool, id: &uuid::Uuid) -> String {
|
pub fn retrieve_url(api: &models::api::API, with_id: bool, id: &uuid::Uuid) -> String {
|
||||||
if with_id {
|
if with_id {
|
||||||
retrieve_url_with_id(&api, id)
|
retrieve_url_with_id(api, id)
|
||||||
} else {
|
} else {
|
||||||
retrieve_url_reg(&api)
|
retrieve_url_reg(api)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_url_reg(api: &models::api::API) -> String {
|
fn retrieve_url_reg(api: &models::api::API) -> String {
|
||||||
let mut url: String = String::from(&api.url);
|
let url = format!("{}/api/{}/{}/", api.url, api.version, api.endpoint);
|
||||||
url += &String::from("/");
|
|
||||||
url += &String::from("api/");
|
|
||||||
url += &String::from(&api.version);
|
|
||||||
url += &String::from("/");
|
|
||||||
url += &String::from(&api.endpoint);
|
|
||||||
url += &String::from("/");
|
|
||||||
|
|
||||||
return url;
|
url
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_url_with_id(api: &models::api::API, id: &uuid::Uuid) -> String {
|
fn retrieve_url_with_id(api: &models::api::API, id: &uuid::Uuid) -> String {
|
||||||
let mut url: String = String::from(&api.url);
|
let url = format!("{}/api/{}/{}/{}", api.url, api.version, api.endpoint, id);
|
||||||
url += &String::from("api/");
|
|
||||||
url += &String::from(&api.version);
|
|
||||||
url += &String::from("/");
|
|
||||||
url += &String::from(&api.endpoint);
|
|
||||||
url += &String::from("/");
|
|
||||||
url += &id.to_string();
|
|
||||||
|
|
||||||
return url;
|
url
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-17
@@ -5,19 +5,11 @@ use reqwest;
|
|||||||
use crate::models;
|
use crate::models;
|
||||||
use crate::syncers;
|
use crate::syncers;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct Delete {
|
pub struct Delete {
|
||||||
pub api: models::api::API,
|
pub api: models::api::API,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Delete {
|
|
||||||
fn default() -> Self {
|
|
||||||
Delete {
|
|
||||||
api: models::api::API::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Delete {
|
impl Delete {
|
||||||
pub async fn delete_song(
|
pub async fn delete_song(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -41,16 +33,10 @@ impl Delete {
|
|||||||
|
|
||||||
match response.json::<icarus_models::song::Song>().await {
|
match response.json::<icarus_models::song::Song>().await {
|
||||||
Ok(sng) => Ok(sng),
|
Ok(sng) => Ok(sng),
|
||||||
Err(er) => Err(std::io::Error::new(
|
Err(er) => Err(std::io::Error::other(er.to_string())),
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
er.to_string(),
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
other => Err(std::io::Error::new(
|
other => Err(std::io::Error::other(other.to_string())),
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
other.to_string(),
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-22
@@ -3,18 +3,11 @@ use std::default::Default;
|
|||||||
use crate::models;
|
use crate::models;
|
||||||
use crate::syncers;
|
use crate::syncers;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Download {
|
pub struct Download {
|
||||||
pub api: models::api::API,
|
pub api: models::api::API,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Download {
|
|
||||||
fn default() -> Self {
|
|
||||||
Download {
|
|
||||||
api: models::api::API::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum MyError {
|
pub enum MyError {
|
||||||
Request(reqwest::Error),
|
Request(reqwest::Error),
|
||||||
@@ -31,7 +24,7 @@ impl Download {
|
|||||||
let url = syncers::common::retrieve_url(&self.api, true, &song.id);
|
let url = syncers::common::retrieve_url(&self.api, true, &song.id);
|
||||||
let access_token = token.bearer_token();
|
let access_token = token.bearer_token();
|
||||||
|
|
||||||
println!("Url: {:?}", url);
|
println!("Url: {url:?}");
|
||||||
|
|
||||||
let client = reqwest::Client::builder().build().unwrap();
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
|
|
||||||
@@ -45,24 +38,16 @@ impl Download {
|
|||||||
reqwest::StatusCode::OK => {
|
reqwest::StatusCode::OK => {
|
||||||
let data = rep.text();
|
let data = rep.text();
|
||||||
match data.await {
|
match data.await {
|
||||||
Ok(e) => {
|
Ok(e) => Ok(e),
|
||||||
return Ok(e);
|
Err(er) => Err(MyError::Other(er.to_string())),
|
||||||
}
|
|
||||||
Err(er) => {
|
|
||||||
return Err(MyError::Other(er.to_string()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reqwest::StatusCode::UNAUTHORIZED => {
|
reqwest::StatusCode::UNAUTHORIZED => {
|
||||||
return Err(MyError::Other(String::from("Need to grab a new token")));
|
Err(MyError::Other(String::from("Need to grab a new token")))
|
||||||
}
|
|
||||||
other => {
|
|
||||||
return Err(MyError::Other(other.to_string()));
|
|
||||||
}
|
}
|
||||||
|
other => Err(MyError::Other(other.to_string())),
|
||||||
},
|
},
|
||||||
Err(er) => {
|
Err(er) => Err(MyError::Request(er)),
|
||||||
return Err(MyError::Request(er));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,11 @@ use std::io::Error;
|
|||||||
use crate::models;
|
use crate::models;
|
||||||
use crate::syncers;
|
use crate::syncers;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct RetrieveRecords {
|
pub struct RetrieveRecords {
|
||||||
pub api: models::api::API,
|
pub api: models::api::API,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RetrieveRecords {
|
|
||||||
fn default() -> Self {
|
|
||||||
RetrieveRecords {
|
|
||||||
api: models::api::API::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RetrieveRecords {
|
impl RetrieveRecords {
|
||||||
pub async fn get_all_songs(
|
pub async fn get_all_songs(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -38,26 +31,13 @@ impl RetrieveRecords {
|
|||||||
// on success, parse our JSON to an APIResponse
|
// on success, parse our JSON to an APIResponse
|
||||||
match response.json::<Vec<icarus_models::song::Song>>().await {
|
match response.json::<Vec<icarus_models::song::Song>>().await {
|
||||||
Ok(parsed) => Ok(parsed),
|
Ok(parsed) => Ok(parsed),
|
||||||
Err(err) => {
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
return Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
err.to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reqwest::StatusCode::UNAUTHORIZED => {
|
reqwest::StatusCode::UNAUTHORIZED => {
|
||||||
return Err(std::io::Error::new(
|
Err(std::io::Error::other("Need to grab a new token"))
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
"Need to grab a new token",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
other => {
|
|
||||||
return Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
other.to_string(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
other => Err(std::io::Error::other(other.to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-35
@@ -6,18 +6,11 @@ use reqwest;
|
|||||||
use crate::models;
|
use crate::models;
|
||||||
use crate::syncers;
|
use crate::syncers;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Upload {
|
pub struct Upload {
|
||||||
pub api: models::api::API,
|
pub api: models::api::API,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Upload {
|
|
||||||
fn default() -> Self {
|
|
||||||
Upload {
|
|
||||||
api: models::api::API::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Upload {
|
impl Upload {
|
||||||
pub async fn upload_song_with_metadata(
|
pub async fn upload_song_with_metadata(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -33,8 +26,8 @@ impl Upload {
|
|||||||
println!("Url is empty");
|
println!("Url is empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Url: {}", url);
|
println!("Url: {url}");
|
||||||
println!("Token: {}", access_token);
|
println!("Token: {access_token}");
|
||||||
println!("Path: {:?}", song.song_path());
|
println!("Path: {:?}", song.song_path());
|
||||||
|
|
||||||
let mut headers = reqwest::header::HeaderMap::new();
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
@@ -44,7 +37,7 @@ impl Upload {
|
|||||||
);
|
);
|
||||||
headers.insert(reqwest::header::ACCEPT, HeaderValue::from_static("*/*"));
|
headers.insert(reqwest::header::ACCEPT, HeaderValue::from_static("*/*"));
|
||||||
|
|
||||||
let form = self.init_form(&song, &cover);
|
let form = self.init_form(song, cover);
|
||||||
let client = reqwest::Client::builder().build().unwrap();
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
match client
|
match client
|
||||||
.post(url)
|
.post(url)
|
||||||
@@ -53,12 +46,8 @@ impl Upload {
|
|||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(r) => {
|
Ok(r) => Ok(r),
|
||||||
return Ok(r);
|
Err(err) => Err(err),
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
return Err(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,25 +56,19 @@ impl Upload {
|
|||||||
song: &icarus_models::song::Song,
|
song: &icarus_models::song::Song,
|
||||||
cover: &icarus_models::coverart::CoverArt,
|
cover: &icarus_models::coverart::CoverArt,
|
||||||
) -> reqwest::multipart::Form {
|
) -> reqwest::multipart::Form {
|
||||||
let songpath = match song.song_path() {
|
let songpath = song.song_path().unwrap_or_default();
|
||||||
Ok(s) => s,
|
|
||||||
Err(_) => String::new(),
|
|
||||||
};
|
|
||||||
let coverpath = cover.path.clone();
|
let coverpath = cover.path.clone();
|
||||||
println!("Cover path: {:?}", coverpath);
|
println!("Cover path: {coverpath:?}");
|
||||||
let song_detail = match song.to_metadata_json(true) {
|
let song_detail = song.to_metadata_json(true).unwrap_or_default();
|
||||||
Ok(s) => s,
|
|
||||||
Err(_) => String::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
println!("\n{}\n", song_detail);
|
println!("\n{song_detail}\n");
|
||||||
|
|
||||||
let mut song_filename = String::from("audio");
|
let mut song_filename = String::from("audio");
|
||||||
song_filename += icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION;
|
song_filename += icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION;
|
||||||
let mut cover_filename = String::from("cover");
|
let mut cover_filename = String::from("cover");
|
||||||
cover_filename += icarus_models::constants::file_extensions::image::JPGEXTENSION;
|
cover_filename += icarus_models::constants::file_extensions::image::JPGEXTENSION;
|
||||||
|
|
||||||
let form = reqwest::multipart::Form::new()
|
reqwest::multipart::Form::new()
|
||||||
.part(
|
.part(
|
||||||
"file",
|
"file",
|
||||||
reqwest::multipart::Part::bytes(std::fs::read(songpath).unwrap())
|
reqwest::multipart::Part::bytes(std::fs::read(songpath).unwrap())
|
||||||
@@ -96,15 +79,15 @@ impl Upload {
|
|||||||
reqwest::multipart::Part::bytes(std::fs::read(coverpath).unwrap())
|
reqwest::multipart::Part::bytes(std::fs::read(coverpath).unwrap())
|
||||||
.file_name(cover_filename),
|
.file_name(cover_filename),
|
||||||
)
|
)
|
||||||
.text("metadata", song_detail);
|
.text("metadata", song_detail)
|
||||||
|
|
||||||
return form;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_api(&mut self, host: &String) {
|
pub fn set_api(&mut self, host: &str) {
|
||||||
let mut api = models::api::API::default();
|
let api = models::api::API {
|
||||||
api.url = host.clone();
|
url: host.to_owned(),
|
||||||
api.version = String::from("v1");
|
version: String::from("v1"),
|
||||||
|
endpoint: String::new(),
|
||||||
|
};
|
||||||
self.api = api;
|
self.api = api;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize};
|
|||||||
pub struct Checks {}
|
pub struct Checks {}
|
||||||
|
|
||||||
impl Checks {
|
impl Checks {
|
||||||
pub fn _is_numeric(text: &String) -> bool {
|
pub fn _is_numeric(text: &str) -> bool {
|
||||||
text.parse::<f64>().is_ok()
|
text.parse::<f64>().is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _index_of_item_in_container<F>(container: &String, item: &char, func: F) -> i32
|
pub fn _index_of_item_in_container<F>(container: &str, item: &char, func: F) -> i32
|
||||||
where
|
where
|
||||||
F: Fn(&char, &char) -> bool,
|
F: Fn(&char, &char) -> bool,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
pub fn o_to_string(val: &std::ffi::OsString) -> Result<std::string::String, std::io::Error> {
|
pub fn o_to_string(val: &std::ffi::OsString) -> Result<std::string::String, std::io::Error> {
|
||||||
match val.clone().into_string() {
|
match val.clone().into_string() {
|
||||||
Ok(value) => Ok(value),
|
Ok(value) => Ok(value),
|
||||||
Err(_) => Err(std::io::Error::new(
|
Err(_) => Err(std::io::Error::other(String::from("Error"))),
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
String::from("Error"),
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user