Constants and url changes
This commit is contained in:
@@ -52,7 +52,9 @@ pub fn retrieve_song(
|
||||
song.album = album.title.clone();
|
||||
song.album_artist = album.artist.clone();
|
||||
song.artist = track.artist.clone();
|
||||
song.audio_type = String::from(icarus_models::constants::DEFAULTMUSICEXTENSION);
|
||||
song.audio_type = String::from(
|
||||
icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION,
|
||||
);
|
||||
song.disc = track.disc.clone();
|
||||
song.disc_count = album.disc_count.clone();
|
||||
song.duration = track.duration as i32;
|
||||
@@ -192,8 +194,8 @@ impl CommitManager {
|
||||
match Runtime::new().unwrap().block_on(result_fut) {
|
||||
Ok(o) => {
|
||||
println!("Success");
|
||||
let filename =
|
||||
String::from("audio") + icarus_models::constants::DEFAULTMUSICEXTENSION;
|
||||
let filename = String::from("audio")
|
||||
+ icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION;
|
||||
let data = o.as_bytes();
|
||||
let mut file = std::fs::File::create(filename).expect("Failed to save");
|
||||
file.write_all(&data)
|
||||
@@ -420,11 +422,11 @@ impl CommitManager {
|
||||
let filename = if track.track < 10 {
|
||||
"track0".to_owned()
|
||||
+ &track.track.to_string()
|
||||
+ icarus_models::constants::DEFAULTMUSICEXTENSION
|
||||
+ icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION
|
||||
} else {
|
||||
"track".to_owned()
|
||||
+ &track.track.to_string()
|
||||
+ icarus_models::constants::DEFAULTMUSICEXTENSION
|
||||
+ icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION
|
||||
};
|
||||
|
||||
songs.push(icarus_models::song::Song {
|
||||
@@ -540,13 +542,15 @@ impl CommitManager {
|
||||
index += 1;
|
||||
}
|
||||
|
||||
if extension == icarus_models::constants::WAVEXTENSION[1..]
|
||||
|| extension == icarus_models::constants::FLACEXTENSION[1..]
|
||||
if extension == icarus_models::constants::file_extensions::audio::WAVEXTENSION[1..]
|
||||
|| extension
|
||||
== icarus_models::constants::file_extensions::audio::FLACEXTENSION[1..]
|
||||
{
|
||||
return En::SongFile;
|
||||
} else if extension == "json" {
|
||||
return En::MetadataFile;
|
||||
} else if extension == icarus_models::constants::JPGEXTENSION[1..]
|
||||
} else if extension
|
||||
== icarus_models::constants::file_extensions::image::JPGEXTENSION[1..]
|
||||
|| extension == "jpeg"
|
||||
|| extension == "png"
|
||||
{
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
use crate::models;
|
||||
|
||||
pub fn retrieve_url(api: &models::api::API, with_id: bool, id: i32) -> String {
|
||||
if with_id {
|
||||
retrieve_url_with_id(&api, id)
|
||||
} else {
|
||||
retrieve_url_reg(&api)
|
||||
}
|
||||
}
|
||||
|
||||
fn retrieve_url_reg(api: &models::api::API) -> String {
|
||||
let mut url: String = String::from(&api.url);
|
||||
url += &String::from("api/");
|
||||
url += &String::from(&api.version);
|
||||
url += &String::from("/");
|
||||
url += &String::from(&api.endpoint);
|
||||
url += &String::from("/");
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
fn retrieve_url_with_id(api: &models::api::API, id: i32) -> String {
|
||||
let mut url: String = String::from(&api.url);
|
||||
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;
|
||||
}
|
||||
+2
-14
@@ -3,6 +3,7 @@ use std::default::Default;
|
||||
use reqwest;
|
||||
|
||||
use crate::models;
|
||||
use crate::syncers;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Delete {
|
||||
@@ -24,7 +25,7 @@ impl Delete {
|
||||
song: &icarus_models::song::Song,
|
||||
) -> Result<icarus_models::song::Song, std::io::Error> {
|
||||
self.api.endpoint = "song/data/delete".to_owned();
|
||||
let url = self.retrieve_url(&song);
|
||||
let url = syncers::common::retrieve_url(&self.api, true, song.id);
|
||||
let client = reqwest::Client::builder().build().unwrap();
|
||||
let access_token = token.bearer_token();
|
||||
let response = client
|
||||
@@ -55,17 +56,4 @@ impl Delete {
|
||||
|
||||
return Ok(sng);
|
||||
}
|
||||
|
||||
fn retrieve_url(&self, song: &icarus_models::song::Song) -> String {
|
||||
let api = &self.api;
|
||||
let mut url: String = String::from(&api.url);
|
||||
url += &String::from("api/");
|
||||
url += &String::from(&api.version);
|
||||
url += &String::from("/");
|
||||
url += &String::from(&api.endpoint);
|
||||
url += &String::from("/");
|
||||
url += &song.id.to_string();
|
||||
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod common;
|
||||
pub mod delete;
|
||||
pub mod download;
|
||||
pub mod retrieve_records;
|
||||
|
||||
@@ -80,9 +80,9 @@ impl Upload {
|
||||
println!("\n{}\n", song_detail);
|
||||
|
||||
let mut song_filename = String::from("audio");
|
||||
song_filename += icarus_models::constants::DEFAULTMUSICEXTENSION;
|
||||
song_filename += icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION;
|
||||
let mut cover_filename = String::from("cover");
|
||||
cover_filename += icarus_models::constants::JPGEXTENSION;
|
||||
cover_filename += icarus_models::constants::file_extensions::image::JPGEXTENSION;
|
||||
|
||||
let form = reqwest::multipart::Form::new()
|
||||
.part(
|
||||
|
||||
Reference in New Issue
Block a user