Constants and url changes

This commit is contained in:
KD
2025-03-30 15:31:33 -04:00
parent 2c77938dac
commit 88f7df61c0
5 changed files with 49 additions and 24 deletions
+32
View File
@@ -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
View File
@@ -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
View File
@@ -1,3 +1,4 @@
pub mod common;
pub mod delete;
pub mod download;
pub mod retrieve_records;
+2 -2
View File
@@ -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(