Single target upload is functional but need to revisit multi-target upload
Multi-target upload is broken now. Needs to be revisited
This commit is contained in:
+1
-4
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus-dm"
|
name = "icarus-dm"
|
||||||
version = "0.1.0"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
||||||
@@ -12,10 +12,7 @@ edition = "2021"
|
|||||||
futures = { version = "0.3.30" }
|
futures = { version = "0.3.30" }
|
||||||
reqwest = { version = "0.12.4", features = ["json", "blocking", "multipart", "stream"] }
|
reqwest = { version = "0.12.4", features = ["json", "blocking", "multipart", "stream"] }
|
||||||
http = { version = "1.1.0" }
|
http = { version = "1.1.0" }
|
||||||
# reqwest = { version = "0.12.4", features = ["full"] }
|
|
||||||
serde = { version = "1.0.197", features = ["derive"] }
|
serde = { version = "1.0.197", features = ["derive"] }
|
||||||
serde_json = "1.0.115"
|
serde_json = "1.0.115"
|
||||||
tokio = { version = "1.37", features = ["full"] }
|
tokio = { version = "1.37", features = ["full"] }
|
||||||
tokio-util = { version = "0.7.11", features = ["codec"] }
|
tokio-util = { version = "0.7.11", features = ["codec"] }
|
||||||
# rodio = "0.17.3"
|
|
||||||
# metadata = "0.1.8"
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
pub const WAV_FILE_EXTENSION: &str = ".wav";
|
||||||
|
pub const MP3_FILE_EXTENSION: &str = ".mp3";
|
||||||
|
pub const JPG_FILE_EXTENSION: &str = ".jpg";
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
pub mod file_extensions;
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
mod constants;
|
||||||
mod managers;
|
mod managers;
|
||||||
mod models;
|
mod models;
|
||||||
mod parsers;
|
mod parsers;
|
||||||
|
|||||||
+8
-3
@@ -3,6 +3,10 @@ use std::io::Read;
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::constants;
|
||||||
|
|
||||||
|
// use crate::constants;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
pub id: Option<i32>,
|
pub id: Option<i32>,
|
||||||
@@ -95,7 +99,7 @@ impl Song {
|
|||||||
let path = self.song_path();
|
let path = self.song_path();
|
||||||
println!("Converting song to data");
|
println!("Converting song to data");
|
||||||
println!("Path: {:?}", path);
|
println!("Path: {:?}", path);
|
||||||
// let content = std::fs::read_to_string(path);
|
|
||||||
let mut file = std::fs::File::open(path)?;
|
let mut file = std::fs::File::open(path)?;
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
file.read_to_end(&mut buffer)?;
|
file.read_to_end(&mut buffer)?;
|
||||||
@@ -105,6 +109,7 @@ impl Song {
|
|||||||
|
|
||||||
Ok(buffer)
|
Ok(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if 1 - wav, if 0 - mp3, anything else defaults to wav
|
// if 1 - wav, if 0 - mp3, anything else defaults to wav
|
||||||
pub fn generate_filename_from_track(&mut self, i_type: i32) -> i32 {
|
pub fn generate_filename_from_track(&mut self, i_type: i32) -> i32 {
|
||||||
let mut filename: String = String::new();
|
let mut filename: String = String::new();
|
||||||
@@ -115,9 +120,9 @@ impl Song {
|
|||||||
filename += &self.track.unwrap().to_string();
|
filename += &self.track.unwrap().to_string();
|
||||||
|
|
||||||
if i_type == 0 {
|
if i_type == 0 {
|
||||||
filename += ".mp3";
|
filename += constants::file_extensions::MP3_FILE_EXTENSION;
|
||||||
} else {
|
} else {
|
||||||
filename += ".wav";
|
filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.filepath = Some(filename);
|
self.filepath = Some(filename);
|
||||||
|
|||||||
+46
-36
@@ -1,17 +1,13 @@
|
|||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|
||||||
use http::header;
|
|
||||||
use http::HeaderMap;
|
use http::HeaderMap;
|
||||||
use http::HeaderValue;
|
use http::HeaderValue;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use reqwest::blocking::multipart;
|
use reqwest::multipart::Form;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
// use reqwest::blocking::
|
|
||||||
use reqwest::multipart::{Form, Part};
|
|
||||||
use reqwest::Response;
|
|
||||||
use reqwest::{Body, Client};
|
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
|
|
||||||
|
use crate::constants;
|
||||||
use crate::models;
|
use crate::models;
|
||||||
|
|
||||||
pub struct Upload {
|
pub struct Upload {
|
||||||
@@ -48,6 +44,7 @@ impl Default for Upload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Upload {
|
impl Upload {
|
||||||
|
/*
|
||||||
pub async fn upload_song(&self, token: &models::token::Token, song: &models::song::Song) {
|
pub async fn upload_song(&self, token: &models::token::Token, song: &models::song::Song) {
|
||||||
let url = self.retrieve_url();
|
let url = self.retrieve_url();
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
@@ -68,6 +65,7 @@ impl Upload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
pub async fn upload_song_with_metadata(
|
pub async fn upload_song_with_metadata(
|
||||||
@@ -91,29 +89,6 @@ impl Upload {
|
|||||||
let song_raw_data = song_raw_data_as.await;
|
let song_raw_data = song_raw_data_as.await;
|
||||||
let cover_raw_data: Vec<u8> = cover_raw_data_as.await;
|
let cover_raw_data: Vec<u8> = cover_raw_data_as.await;
|
||||||
|
|
||||||
/*
|
|
||||||
match song_data {
|
|
||||||
Ok(sd) => {
|
|
||||||
println!("song converted to data. Length {:?}", sd.len());
|
|
||||||
song_raw_data = sd;
|
|
||||||
}
|
|
||||||
Err(er) => {
|
|
||||||
println!("Error: {:?}", er);
|
|
||||||
std::process::exit(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match cover_data {
|
|
||||||
Ok(cv) => {
|
|
||||||
cover_raw_data = cv;
|
|
||||||
}
|
|
||||||
Err(er) => {
|
|
||||||
println!("Error: {:?}", er);
|
|
||||||
std::process::exit(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if url.is_empty() {
|
if url.is_empty() {
|
||||||
println!("Url is empty");
|
println!("Url is empty");
|
||||||
}
|
}
|
||||||
@@ -122,6 +97,7 @@ impl Upload {
|
|||||||
println!("Length: {:?}", song_raw_data.len());
|
println!("Length: {:?}", song_raw_data.len());
|
||||||
println!("Token: {}", access_token);
|
println!("Token: {}", access_token);
|
||||||
|
|
||||||
|
/*
|
||||||
let form_as = async {
|
let form_as = async {
|
||||||
self.initialize_form(
|
self.initialize_form(
|
||||||
song_raw_data.clone(),
|
song_raw_data.clone(),
|
||||||
@@ -129,18 +105,47 @@ impl Upload {
|
|||||||
song_detail.clone(),
|
song_detail.clone(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
// let form = self.initialize_form(song_raw_data, cover_raw_data, song_detail.clone());
|
// let form = self.initialize_form(song_raw_data, cover_raw_data, song_detail.clone());
|
||||||
let form = form_as.await;
|
// let form = form_as.await;
|
||||||
|
|
||||||
|
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 songpath = song.song_path();
|
||||||
|
let coverpath = cover.path.clone().unwrap();
|
||||||
|
|
||||||
|
println!("\n{}\n", song_detail);
|
||||||
|
|
||||||
|
let mut song_filename = String::from("audio");
|
||||||
|
song_filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
||||||
|
let mut cover_filename = String::from("cover");
|
||||||
|
cover_filename += constants::file_extensions::JPG_FILE_EXTENSION;
|
||||||
|
|
||||||
|
let form = reqwest::multipart::Form::new()
|
||||||
|
.part(
|
||||||
|
"file",
|
||||||
|
reqwest::multipart::Part::bytes(std::fs::read(songpath)?).file_name(song_filename),
|
||||||
|
)
|
||||||
|
.part(
|
||||||
|
"cover",
|
||||||
|
reqwest::multipart::Part::bytes(std::fs::read(coverpath)?)
|
||||||
|
.file_name(cover_filename),
|
||||||
|
)
|
||||||
|
.text("metadata", song_detail);
|
||||||
|
|
||||||
println!("Form: {:?}", form);
|
println!("Form: {:?}", form);
|
||||||
|
|
||||||
// let mut client = reqwest::Client::new();
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
let response = reqwest::Client::new()
|
let response = client
|
||||||
.post(url)
|
.post(url)
|
||||||
|
.headers(headers)
|
||||||
.multipart(form)
|
.multipart(form)
|
||||||
.header(reqwest::header::AUTHORIZATION, access_token)
|
|
||||||
.header(reqwest::header::CONTENT_TYPE, "multipart/form-data")
|
|
||||||
.send()
|
.send()
|
||||||
.await;
|
.await;
|
||||||
let response_text = response.unwrap();
|
let response_text = response.unwrap();
|
||||||
@@ -172,10 +177,15 @@ impl Upload {
|
|||||||
|
|
||||||
let mut cover = reqwest::multipart::Part::bytes(cover_raw_data).headers(headers_i);
|
let mut cover = reqwest::multipart::Part::bytes(cover_raw_data).headers(headers_i);
|
||||||
|
|
||||||
|
let mut song_filename = String::from("audio");
|
||||||
|
song_filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
||||||
|
let mut cover_filename = String::from("cover");
|
||||||
|
cover_filename += constants::file_extensions::JPG_FILE_EXTENSION;
|
||||||
|
|
||||||
return reqwest::multipart::Form::new()
|
return reqwest::multipart::Form::new()
|
||||||
.part("cover", cover.file_name("cover.jpeg"))
|
.part("cover", cover.file_name(cover_filename))
|
||||||
.text("metadata", song_detail)
|
.text("metadata", song_detail)
|
||||||
.part("file", file.file_name("audio.wav"));
|
.part("file", file.file_name(song_filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_api(&mut self, host: &String) {
|
pub fn set_api(&mut self, host: &String) {
|
||||||
|
|||||||
Reference in New Issue
Block a user