Minor refatoring (#68)
* Removed old upload method * Removed upload commit action * Version bump
This commit was merged in pull request #68.
This commit is contained in:
Generated
+1
-1
@@ -479,7 +479,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus-dm"
|
name = "icarus-dm"
|
||||||
version = "0.6.8"
|
version = "0.6.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"http",
|
"http",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus-dm"
|
name = "icarus-dm"
|
||||||
version = "0.6.8"
|
version = "0.6.9"
|
||||||
rust-version = "1.88"
|
rust-version = "1.88"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ enum ActionValues {
|
|||||||
DeleteAct,
|
DeleteAct,
|
||||||
DownloadAct,
|
DownloadAct,
|
||||||
RetrieveAct,
|
RetrieveAct,
|
||||||
UploadAct,
|
|
||||||
UploadSongWithMetadata,
|
UploadSongWithMetadata,
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
@@ -101,7 +100,6 @@ impl CommitManager {
|
|||||||
ActionValues::DeleteAct => self.delete_song().await,
|
ActionValues::DeleteAct => self.delete_song().await,
|
||||||
ActionValues::DownloadAct => self.download_song().await,
|
ActionValues::DownloadAct => self.download_song().await,
|
||||||
ActionValues::RetrieveAct => self.retrieve_object().await,
|
ActionValues::RetrieveAct => self.retrieve_object().await,
|
||||||
ActionValues::UploadAct => self.upload_song(),
|
|
||||||
ActionValues::UploadSongWithMetadata => self.upload_song_with_metadata().await,
|
ActionValues::UploadSongWithMetadata => self.upload_song_with_metadata().await,
|
||||||
_ => {
|
_ => {
|
||||||
println!("Nothing good here");
|
println!("Nothing good here");
|
||||||
@@ -127,7 +125,6 @@ impl CommitManager {
|
|||||||
let actions: HashMap<String, ActionValues> = HashMap::from([
|
let actions: HashMap<String, ActionValues> = HashMap::from([
|
||||||
("download".to_string(), ActionValues::DownloadAct),
|
("download".to_string(), ActionValues::DownloadAct),
|
||||||
("download".to_string(), ActionValues::DownloadAct),
|
("download".to_string(), ActionValues::DownloadAct),
|
||||||
("upload".to_string(), ActionValues::UploadAct),
|
|
||||||
(
|
(
|
||||||
"upload-meta".to_string(),
|
"upload-meta".to_string(),
|
||||||
ActionValues::UploadSongWithMetadata,
|
ActionValues::UploadSongWithMetadata,
|
||||||
@@ -266,12 +263,6 @@ impl CommitManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove at some point
|
|
||||||
fn upload_song(&self) {
|
|
||||||
println!("Deleting song");
|
|
||||||
panic!("Not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn parse_token(&self, api: &models::api::Api) -> icarus_models::token::AccessToken {
|
async fn parse_token(&self, api: &models::api::Api) -> icarus_models::token::AccessToken {
|
||||||
println!("Fetching token");
|
println!("Fetching token");
|
||||||
|
|
||||||
|
|||||||
@@ -38,45 +38,6 @@ mod response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Upload {
|
impl Upload {
|
||||||
pub async fn upload_song_with_metadata(
|
|
||||||
&mut self,
|
|
||||||
token: &icarus_models::token::AccessToken,
|
|
||||||
song: &icarus_models::song::Song,
|
|
||||||
cover: &icarus_models::coverart::CoverArt,
|
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
|
||||||
self.api.endpoint = String::from("song/data/upload/with/data");
|
|
||||||
let url = syncers::common::retrieve_url(&self.api, false, &uuid::Uuid::nil());
|
|
||||||
let access_token = token.bearer_token();
|
|
||||||
|
|
||||||
if url.is_empty() {
|
|
||||||
println!("Url is empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Url: {url}");
|
|
||||||
println!("Token: {access_token}");
|
|
||||||
println!("Path: {:?}", song.song_path());
|
|
||||||
|
|
||||||
let mut headers = reqwest::header::HeaderMap::new();
|
|
||||||
headers.insert(
|
|
||||||
reqwest::header::AUTHORIZATION,
|
|
||||||
HeaderValue::from_str(&access_token.clone()).unwrap(),
|
|
||||||
);
|
|
||||||
headers.insert(reqwest::header::ACCEPT, HeaderValue::from_static("*/*"));
|
|
||||||
|
|
||||||
let form = self.init_form(song, cover);
|
|
||||||
let client = reqwest::Client::builder().build().unwrap();
|
|
||||||
match client
|
|
||||||
.post(url)
|
|
||||||
.headers(headers)
|
|
||||||
.multipart(form)
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(r) => Ok(r),
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn queue_song(
|
pub async fn queue_song(
|
||||||
&self,
|
&self,
|
||||||
token: &icarus_models::token::AccessToken,
|
token: &icarus_models::token::AccessToken,
|
||||||
@@ -332,37 +293,6 @@ impl Upload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_form(
|
|
||||||
&self,
|
|
||||||
song: &icarus_models::song::Song,
|
|
||||||
cover: &icarus_models::coverart::CoverArt,
|
|
||||||
) -> reqwest::multipart::Form {
|
|
||||||
let songpath = song.song_path().unwrap_or_default();
|
|
||||||
let coverpath = cover.path.clone();
|
|
||||||
println!("Cover path: {coverpath:?}");
|
|
||||||
let song_detail = song.to_metadata_json(true).unwrap_or_default();
|
|
||||||
|
|
||||||
println!("\n{song_detail}\n");
|
|
||||||
|
|
||||||
let mut song_filename = String::from("audio");
|
|
||||||
song_filename += icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION;
|
|
||||||
let mut cover_filename = String::from("cover");
|
|
||||||
cover_filename += icarus_models::constants::file_extensions::image::JPGEXTENSION;
|
|
||||||
|
|
||||||
reqwest::multipart::Form::new()
|
|
||||||
.part(
|
|
||||||
"file",
|
|
||||||
reqwest::multipart::Part::bytes(std::fs::read(songpath).unwrap())
|
|
||||||
.file_name(song_filename),
|
|
||||||
)
|
|
||||||
.part(
|
|
||||||
"cover",
|
|
||||||
reqwest::multipart::Part::bytes(std::fs::read(coverpath).unwrap())
|
|
||||||
.file_name(cover_filename),
|
|
||||||
)
|
|
||||||
.text("metadata", song_detail)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_api(&mut self, host: &str) {
|
pub fn set_api(&mut self, host: &str) {
|
||||||
let api = models::api::Api {
|
let api = models::api::Api {
|
||||||
url: host.to_owned(),
|
url: host.to_owned(),
|
||||||
|
|||||||
Reference in New Issue
Block a user