Language Migration #21
+1
-1
@@ -10,8 +10,8 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = { version = "0.3.30" }
|
futures = { version = "0.3.30" }
|
||||||
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 = ["json", "blocking", "multipart", "stream"] }
|
||||||
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"] }
|
||||||
|
|||||||
@@ -1,86 +1,67 @@
|
|||||||
# IcarusDownloadManager
|
# IcarusDownloadManager
|
||||||
|
|
||||||
IcarusDownloadManager is a Linux CLI software client application that has the feature of uploading and downloading songs from the [Icarus](https://github.com/kdeng00/Icarus) Music Server.
|
IcarusDownloadManager is a CLI software client application that has the feature of uploading and downloading songs from the [Icarus](https://github.com/kdeng00/Icarus) Music Server.
|
||||||
|
|
||||||
|
|
||||||
## Built With
|
## Built With
|
||||||
|
|
||||||
* C++ with C++20 features
|
* Rust
|
||||||
* CMake
|
* Cargo
|
||||||
* GCC >= 10 or Visual Studio >= 17 [2022]
|
* futures
|
||||||
* [vcpkg](https://github.com/microsoft/vcpkg)
|
* http
|
||||||
* [json](https://github.com/nlohmann/json)
|
* reqwst
|
||||||
* [openssl](https://github.com/openssl/openssl)
|
* serde
|
||||||
* [curl](https://github.com/curl/curl)
|
* serde_json
|
||||||
* [cpr](https://github.com/libcpr/cpr)
|
* tokio
|
||||||
|
* tokio-util
|
||||||
|
|
||||||
|
|
||||||
### Getting Started
|
### Getting Started
|
||||||
|
|
||||||
Clone the repo
|
Clone the repo
|
||||||
|
|
||||||
```
|
```BASH
|
||||||
git clone --recursive https://github.com/kdeng00/IcarusDownloadManager
|
git clone --recursive https://github.com/kdeng00/IcarusDownloadManager
|
||||||
```
|
```
|
||||||
|
|
||||||
Install packages
|
|
||||||
|
|
||||||
```
|
|
||||||
vcpkg install nlohman-json
|
|
||||||
vcpkg install openssl
|
|
||||||
vcpkg install curl
|
|
||||||
vcpkg install cpr
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
Build the project:
|
Build the project:
|
||||||
|
|
||||||
```
|
```BASH
|
||||||
cd IcarusDownloadManager
|
cd IcarusDownloadManager
|
||||||
mkdir build
|
cargo build
|
||||||
cd build
|
|
||||||
|
|
||||||
cmake ..
|
|
||||||
cmake --build . --config release -j
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The program has been built and can be executed by the binary file *icd*. For information on how to use icd, merely execute the program without any command line arguments.
|
The program has been built and can be executed by the binary file *icarus-dm*. For information on how to use icarua-dm, merely execute the program without any command line arguments.
|
||||||
|
|
||||||
### Downloading Song
|
### Downloading Song
|
||||||
|
|
||||||
```BASH
|
```BASH
|
||||||
icd download -u spacecadet -p stellar40 -h https://icarus.com -b 15
|
icarus-dm download -u spacecadet -p stellar40 -h https://icarus.com -b 15
|
||||||
```
|
|
||||||
|
|
||||||
### Uploading Song
|
|
||||||
|
|
||||||
```BASH
|
|
||||||
icd upload -u spacecadet -p stellar40 -h https://icarus.com -s /path/of/song.mp3
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Uploading Song with metadata
|
### Uploading Song with metadata
|
||||||
|
|
||||||
```BASH
|
```BASH
|
||||||
icd upload-meta -u spacecadet -p stellar40 -h https://icarus.com -s /path/of/song.mp3 -t 1 -m /path/to/metadata/config/collection.json -ca /path/to/cover/art/image.png
|
icarus-dm upload-meta -u spacecadet -p stellar40 -h https://icarus.com -s /path/of/song.mp3 -t 1 -m /path/to/metadata/config/collection.json -ca /path/to/cover/art/image.png
|
||||||
```
|
```
|
||||||
|
|
||||||
### Uploading Song with metadata from directory
|
### Uploading Song with metadata from directory
|
||||||
|
|
||||||
```BASH
|
```BASH
|
||||||
icd upload-meta -u spacecadet -p stellar40 -h https://icarus.com -smca /path/where/songs/and/metadata/exists/
|
icarus-dm upload-meta -u spacecadet -p stellar40 -h https://icarus.com -smca /path/where/songs/and/metadata/exists/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Retrieving Song in json
|
### Retrieving Song in json
|
||||||
|
|
||||||
```Bash
|
```Bash
|
||||||
icd retrieve -u spacecadet -p stellar40 -h https://icarus.com -rt songs
|
icarus-dm retrieve -u spacecadet -p stellar40 -h https://icarus.com -rt songs
|
||||||
```
|
```
|
||||||
|
|
||||||
### Deleting Song
|
### Deleting Song
|
||||||
|
|
||||||
```BASH
|
```BASH
|
||||||
icd delete -u spacecadet -p stellar40 -h https://icarus.com -D 15
|
icarus-dm delete -u spacecadet -p stellar40 -h https://icarus.com -D 15
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -97,12 +78,6 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the code of conduc
|
|||||||
[v0.1.1](https://github.com/kdeng00/IcarusDownloadManager/releases/tag/v0.1.1)
|
[v0.1.1](https://github.com/kdeng00/IcarusDownloadManager/releases/tag/v0.1.1)
|
||||||
[v0.1.0](https://github.com/kdeng00/IcarusDownloadManager/releases/tag/0.1.0)
|
[v0.1.0](https://github.com/kdeng00/IcarusDownloadManager/releases/tag/0.1.0)
|
||||||
|
|
||||||
## Authors
|
|
||||||
|
|
||||||
* **Kun Deng** - [kdeng00](https://github.com/kdeng00)
|
|
||||||
|
|
||||||
See also the list of [contributors](https://github.com/kdeng00/Icarus/graphs/contributors) who participated in this project.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
|
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
pub const WAV_FILE_EXTENSION: &str = ".wav";
|
pub const WAV_FILE_EXTENSION: &str = ".wav";
|
||||||
pub const MP3_FILE_EXTENSION: &str = ".mp3";
|
pub const _MP3_FILE_EXTENSION: &str = ".mp3";
|
||||||
pub const JPG_FILE_EXTENSION: &str = ".jpg";
|
pub const JPG_FILE_EXTENSION: &str = ".jpg";
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ fn print_help() {
|
|||||||
|
|
||||||
Actions
|
Actions
|
||||||
download
|
download
|
||||||
upload (Search NOTE)
|
|
||||||
upload-meta
|
upload-meta
|
||||||
retrieve
|
retrieve
|
||||||
delete
|
delete
|
||||||
@@ -29,12 +28,6 @@ fn print_help() {
|
|||||||
-p password
|
-p password
|
||||||
-h host
|
-h host
|
||||||
|
|
||||||
Required for upload
|
|
||||||
-s path of song
|
|
||||||
-sd directory where to search for songs to upload (Optional)
|
|
||||||
-sr directory where to recursively search for songs to upload (Optional)
|
|
||||||
-nc will not prompt the user when uploading from a directory
|
|
||||||
|
|
||||||
Required for upload with metadata
|
Required for upload with metadata
|
||||||
-s path of song
|
-s path of song
|
||||||
-t track number
|
-t track number
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ impl ActionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_action(&self) {
|
fn _print_action(&self) {
|
||||||
if self.action.len() == 0 {
|
if self.action.len() == 0 {
|
||||||
println!("Action is empty");
|
println!("Action is empty");
|
||||||
} else {
|
} else {
|
||||||
@@ -132,7 +132,7 @@ impl ActionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_flags(&self) {
|
fn _print_flags(&self) {
|
||||||
println!("Printing flags...");
|
println!("Printing flags...");
|
||||||
for flag in &self.flags {
|
for flag in &self.flags {
|
||||||
println!("Flag {}", flag.flag);
|
println!("Flag {}", flag.flag);
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::fmt::Display;
|
use std::fs::read_dir;
|
||||||
use std::fs::{read_dir, DirEntry};
|
use std::io::{Result, Write};
|
||||||
use std::io::{Error, Read, Result, Write};
|
|
||||||
use std::path::Path;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use futures::{FutureExt, TryFutureExt};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
|
use crate::managers;
|
||||||
use crate::models::song::Album;
|
use crate::models::song::Album;
|
||||||
use crate::models::{self, song};
|
use crate::models::{self};
|
||||||
use crate::syncers;
|
use crate::syncers;
|
||||||
use crate::utilities;
|
use crate::utilities;
|
||||||
use crate::{constants, parsers};
|
use crate::{constants, parsers};
|
||||||
use crate::{exit_program, managers};
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct CommitManager {
|
pub struct CommitManager {
|
||||||
@@ -32,7 +29,7 @@ enum ActionValues {
|
|||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum RetrieveTypes {
|
enum _RetrieveTypes {
|
||||||
Songs,
|
Songs,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +42,7 @@ enum En {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Album {
|
impl Album {
|
||||||
pub fn print_info(&self) {
|
pub fn _print_info(&self) {
|
||||||
println!("Album: {}", self.title);
|
println!("Album: {}", self.title);
|
||||||
println!("Album Artist: {}", self.album_artist);
|
println!("Album Artist: {}", self.album_artist);
|
||||||
println!("Genre: {}", self.genre);
|
println!("Genre: {}", self.genre);
|
||||||
@@ -126,7 +123,6 @@ impl CommitManager {
|
|||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement
|
|
||||||
fn delete_song(&self) {
|
fn delete_song(&self) {
|
||||||
let mut prsr = parsers::api_parser::APIParser {
|
let mut prsr = parsers::api_parser::APIParser {
|
||||||
ica_act: self.ica_action.clone(),
|
ica_act: self.ica_action.clone(),
|
||||||
@@ -150,11 +146,20 @@ impl CommitManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let del = syncers::delete::Delete { api: api };
|
let mut del = syncers::delete::Delete { api: api.clone() };
|
||||||
|
|
||||||
println!("Deleting song..");
|
println!("Deleting song..");
|
||||||
|
|
||||||
del.delete_song(&token, &song);
|
let res_fut = del.delete_song(&token, &song);
|
||||||
|
let result = Runtime::new().unwrap().block_on(res_fut);
|
||||||
|
match result {
|
||||||
|
Ok(o) => {
|
||||||
|
println!("Song (Id {:?}) has been successfully deleted", o.id);
|
||||||
|
}
|
||||||
|
Err(er) => {
|
||||||
|
println!("Error {:?}", er);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn download_song(&self) {
|
fn download_song(&self) {
|
||||||
@@ -213,8 +218,8 @@ impl CommitManager {
|
|||||||
let result = Runtime::new().unwrap().block_on(result_fut);
|
let result = Runtime::new().unwrap().block_on(result_fut);
|
||||||
match result {
|
match result {
|
||||||
Ok(o) => {
|
Ok(o) => {
|
||||||
for song in o {
|
for son in o {
|
||||||
println!("{:?} - {:?}", song.artist, song.title);
|
son.print_info();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(er) => {
|
Err(er) => {
|
||||||
@@ -280,9 +285,9 @@ impl CommitManager {
|
|||||||
println!("metadata path: {}", metadata_path);
|
println!("metadata path: {}", metadata_path);
|
||||||
println!("cover art path: {}", coverpath);
|
println!("cover art path: {}", coverpath);
|
||||||
|
|
||||||
self.sing_target_upload(&songpath, &track_id, &metadata_path, &coverpath);
|
let _ = self.sing_target_upload(&songpath, &track_id, &metadata_path, &coverpath);
|
||||||
} else if multitarget {
|
} else if multitarget {
|
||||||
self.multi_target_upload(&uni);
|
let _ = self.multi_target_upload(&uni);
|
||||||
} else {
|
} else {
|
||||||
println!("Single or Multi target has not been chosen");
|
println!("Single or Multi target has not been chosen");
|
||||||
}
|
}
|
||||||
@@ -681,8 +686,8 @@ impl CommitManager {
|
|||||||
song.track = Some(track);
|
song.track = Some(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_disc_and_track(&self, song: &mut models::song::Song, track_id: &String) {
|
fn _parse_disc_and_track(&self, song: &mut models::song::Song, track_id: &String) {
|
||||||
let sep = |a: &char, b: &char| -> bool {
|
let sep = |_a: &char, _b: &char| -> bool {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -690,7 +695,7 @@ impl CommitManager {
|
|||||||
|
|
||||||
if index == -1 {
|
if index == -1 {
|
||||||
let mut d_str: String = String::new();
|
let mut d_str: String = String::new();
|
||||||
let mut t_str = String::new();
|
let t_str = String::new();
|
||||||
|
|
||||||
for c in track_id.chars().skip(0).take(index as usize) {
|
for c in track_id.chars().skip(0).take(index as usize) {
|
||||||
d_str.push(c);
|
d_str.push(c);
|
||||||
@@ -712,7 +717,7 @@ impl CommitManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_for_no_confirm(&self) -> bool {
|
fn _check_for_no_confirm(&self) -> bool {
|
||||||
for flag in self.ica_action.flags.iter() {
|
for flag in self.ica_action.flags.iter() {
|
||||||
if flag.flag == "-nc" {
|
if flag.flag == "-nc" {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -24,9 +24,7 @@ impl TokenManager {
|
|||||||
pub async fn request_token(&self) -> Result<models::token::Token, std::io::Error> {
|
pub async fn request_token(&self) -> Result<models::token::Token, std::io::Error> {
|
||||||
println!("Sending request for a token");
|
println!("Sending request for a token");
|
||||||
|
|
||||||
// let endpoint = self.construct_endpoint();
|
let url = self.retrieve_url();
|
||||||
let mut url = self.retrieve_url();
|
|
||||||
// url += &endpoint;
|
|
||||||
|
|
||||||
println!("URL: {}", url);
|
println!("URL: {}", url);
|
||||||
|
|
||||||
@@ -59,7 +57,7 @@ impl TokenManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&mut self) {
|
pub fn init(&mut self) {
|
||||||
let mut api = &mut self.api;
|
let api = &mut self.api;
|
||||||
api.version = String::from("v1");
|
api.version = String::from("v1");
|
||||||
api.endpoint = String::from(format!("api/{}/login", api.version));
|
api.endpoint = String::from(format!("api/{}/login", api.version));
|
||||||
}
|
}
|
||||||
@@ -67,9 +65,6 @@ impl TokenManager {
|
|||||||
pub fn retrieve_url(&self) -> String {
|
pub fn retrieve_url(&self) -> String {
|
||||||
let api = &self.api;
|
let api = &self.api;
|
||||||
let mut url = String::from(&api.url);
|
let mut url = String::from(&api.url);
|
||||||
// url += &String::from("api/");
|
|
||||||
// url += &String::from(&api.version);
|
|
||||||
// url += &String::from("/");
|
|
||||||
url += &String::from(&api.endpoint);
|
url += &String::from(&api.endpoint);
|
||||||
url += &String::from("/");
|
url += &String::from("/");
|
||||||
|
|
||||||
@@ -77,7 +72,7 @@ impl TokenManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: This can get deleted. Redundant
|
// NOTE: This can get deleted. Redundant
|
||||||
fn construct_endpoint(&self) -> String {
|
fn _construct_endpoint(&self) -> String {
|
||||||
let mut endpoint: String = String::from("api/");
|
let mut endpoint: String = String::from("api/");
|
||||||
endpoint += &self.api.version;
|
endpoint += &self.api.version;
|
||||||
endpoint += "/login";
|
endpoint += "/login";
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::default::Default;
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::models::{self, user::User};
|
use crate::models::{self};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct UserManager {
|
pub struct UserManager {
|
||||||
|
|||||||
+4
-3
@@ -9,6 +9,7 @@ use crate::constants;
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
|
#[serde(alias = "song_id")]
|
||||||
pub id: Option<i32>,
|
pub id: Option<i32>,
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
pub artist: Option<String>,
|
pub artist: Option<String>,
|
||||||
@@ -111,7 +112,7 @@ impl Song {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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();
|
||||||
if self.track.unwrap() < 10 {
|
if self.track.unwrap() < 10 {
|
||||||
filename += "0";
|
filename += "0";
|
||||||
@@ -120,7 +121,7 @@ impl Song {
|
|||||||
filename += &self.track.unwrap().to_string();
|
filename += &self.track.unwrap().to_string();
|
||||||
|
|
||||||
if i_type == 0 {
|
if i_type == 0 {
|
||||||
filename += constants::file_extensions::MP3_FILE_EXTENSION;
|
filename += constants::file_extensions::_MP3_FILE_EXTENSION;
|
||||||
} else {
|
} else {
|
||||||
filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
||||||
}
|
}
|
||||||
@@ -130,7 +131,7 @@ impl Song {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_metadata_json(&self) -> Result<String, serde_json::Error> {
|
pub fn _to_metadata_json(&self) -> Result<String, serde_json::Error> {
|
||||||
return serde_json::to_string_pretty(&self);
|
return serde_json::to_string_pretty(&self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ impl Default for User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
pub fn to_json(&self) -> Result<String, serde_json::Error> {
|
pub fn _to_json(&self) -> Result<String, serde_json::Error> {
|
||||||
return serde_json::to_string_pretty(&self);
|
return serde_json::to_string_pretty(&self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,22 +15,18 @@ impl APIParser {
|
|||||||
let flags = self.ica_act.flags.clone();
|
let flags = self.ica_act.flags.clone();
|
||||||
println!("Parsing api");
|
println!("Parsing api");
|
||||||
|
|
||||||
let mut i = 0;
|
|
||||||
// for (i, elem) in flags {
|
|
||||||
for elem in flags {
|
for elem in flags {
|
||||||
let arg = elem.flag;
|
let arg = elem.flag;
|
||||||
let value = elem.value;
|
let value = elem.value;
|
||||||
|
|
||||||
if arg == "-h" {
|
if arg == "-h" {
|
||||||
if value.chars().nth((value.len() - 1)) == Some('/') {
|
if value.chars().nth(value.len() - 1) == Some('/') {
|
||||||
self.api.url = value;
|
self.api.url = value;
|
||||||
} else {
|
} else {
|
||||||
self.api.url = value + "/";
|
self.api.url = value + "/";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.api.version = "v1".to_string();
|
self.api.version = "v1".to_string();
|
||||||
|
|||||||
+20
-9
@@ -1,16 +1,9 @@
|
|||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::io::Error;
|
|
||||||
|
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use reqwest::Response;
|
|
||||||
use serde;
|
|
||||||
// use serde::Deserialize;
|
|
||||||
// use serde::Serialize;
|
|
||||||
|
|
||||||
use crate::models;
|
use crate::models;
|
||||||
|
|
||||||
use super::syncer_base;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Delete {
|
pub struct Delete {
|
||||||
pub api: models::api::API,
|
pub api: models::api::API,
|
||||||
@@ -25,9 +18,14 @@ impl Default for Delete {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Delete {
|
impl Delete {
|
||||||
pub async fn delete_song(&self, token: &models::token::Token, song: &models::song::Song) {
|
pub async fn delete_song(
|
||||||
|
&mut self,
|
||||||
|
token: &models::token::Token,
|
||||||
|
song: &models::song::Song,
|
||||||
|
) -> Result<models::song::Song, std::io::Error> {
|
||||||
|
self.api.endpoint = "song/data/delete".to_owned();
|
||||||
let url = self.retrieve_url(&song);
|
let url = self.retrieve_url(&song);
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::builder().build().unwrap();
|
||||||
let access_token = token.bearer_token();
|
let access_token = token.bearer_token();
|
||||||
let response = client
|
let response = client
|
||||||
.delete(&url)
|
.delete(&url)
|
||||||
@@ -35,15 +33,28 @@ impl Delete {
|
|||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let mut sng = models::song::Song::default();
|
||||||
|
|
||||||
match response.status() {
|
match response.status() {
|
||||||
reqwest::StatusCode::OK => {
|
reqwest::StatusCode::OK => {
|
||||||
println!("Success!");
|
println!("Success!");
|
||||||
|
let s = response.json::<models::song::Song>().await;
|
||||||
|
match s {
|
||||||
|
//
|
||||||
|
Ok(parsed) => {
|
||||||
|
sng = parsed;
|
||||||
|
}
|
||||||
|
Err(er) => {
|
||||||
|
println!("Error {:?}", er);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
panic!("Issue occurred: {:?}", other);
|
panic!("Issue occurred: {:?}", other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Ok(sng);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retrieve_url(&self, song: &models::song::Song) -> String {
|
fn retrieve_url(&self, song: &models::song::Song) -> String {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ impl Default for Download {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum MyError {
|
pub enum MyError {
|
||||||
Request(reqwest::Error),
|
_Request(reqwest::Error),
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
pub mod delete;
|
pub mod delete;
|
||||||
pub mod download;
|
pub mod download;
|
||||||
pub mod retrieve_records;
|
pub mod retrieve_records;
|
||||||
pub mod syncer_base;
|
|
||||||
pub mod upload;
|
pub mod upload;
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ use std::io::Error;
|
|||||||
|
|
||||||
use crate::models;
|
use crate::models;
|
||||||
|
|
||||||
// use super::syncer_base::Result;
|
|
||||||
|
|
||||||
pub struct RetrieveRecords {
|
pub struct RetrieveRecords {
|
||||||
pub api: models::api::API,
|
pub api: models::api::API,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
// use crate::models;
|
|
||||||
|
|
||||||
pub struct Syncer {
|
|
||||||
// pub api: models::api::API,
|
|
||||||
ok: i32,
|
|
||||||
unauthorized: i32,
|
|
||||||
not_found: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Syncer {
|
|
||||||
pub fn ok() -> i32 {
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unauthorized() -> i32 {
|
|
||||||
return 401;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn not_found() -> i32 {
|
|
||||||
return 404;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Result {
|
|
||||||
OK,
|
|
||||||
UNAUTHORIZED,
|
|
||||||
NOTFOUND,
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ use http::HeaderValue;
|
|||||||
use reqwest;
|
use reqwest;
|
||||||
use reqwest::multipart::Form;
|
use reqwest::multipart::Form;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::fs::File;
|
|
||||||
|
|
||||||
use crate::constants;
|
use crate::constants;
|
||||||
use crate::models;
|
use crate::models;
|
||||||
@@ -112,7 +111,7 @@ impl Upload {
|
|||||||
return Ok(response_text);
|
return Ok(response_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initialize_form(
|
fn _initialize_form(
|
||||||
&self,
|
&self,
|
||||||
song_raw_data: Vec<u8>,
|
song_raw_data: Vec<u8>,
|
||||||
cover_raw_data: Vec<u8>,
|
cover_raw_data: Vec<u8>,
|
||||||
@@ -124,14 +123,14 @@ impl Upload {
|
|||||||
http::HeaderValue::from_static("application/octet-stream"),
|
http::HeaderValue::from_static("application/octet-stream"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut file = reqwest::multipart::Part::bytes(song_raw_data).headers(headers);
|
let file = reqwest::multipart::Part::bytes(song_raw_data).headers(headers);
|
||||||
let mut headers_i = HeaderMap::new();
|
let mut headers_i = HeaderMap::new();
|
||||||
headers_i.insert(
|
headers_i.insert(
|
||||||
http::header::CONTENT_TYPE,
|
http::header::CONTENT_TYPE,
|
||||||
http::HeaderValue::from_static("image/jpeg"),
|
http::HeaderValue::from_static("image/jpeg"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut cover = reqwest::multipart::Part::bytes(cover_raw_data).headers(headers_i);
|
let cover = reqwest::multipart::Part::bytes(cover_raw_data).headers(headers_i);
|
||||||
|
|
||||||
let mut song_filename = String::from("audio");
|
let mut song_filename = String::from("audio");
|
||||||
song_filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
song_filename += constants::file_extensions::WAV_FILE_EXTENSION;
|
||||||
|
|||||||
@@ -9,24 +9,23 @@ impl Checks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
pub fn item_in_container(
|
pub fn _item_in_container(
|
||||||
container: &Vec<String>,
|
_container: &Vec<String>,
|
||||||
item: &String,
|
_item: &String,
|
||||||
func: fn(a: &String, b: &String) -> String,
|
_func: fn(a: &String, b: &String) -> String,
|
||||||
) -> String {
|
) -> String {
|
||||||
return String::from("");
|
return String::from("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
pub fn item_iter_in_container(
|
pub fn _item_iter_in_container(
|
||||||
container: &Vec<String>,
|
_container: &Vec<String>,
|
||||||
item: &String,
|
_item: &String,
|
||||||
func: fn(a: &String, b: &String) -> String,
|
_func: fn(a: &String, b: &String) -> String,
|
||||||
) -> String {
|
) -> String {
|
||||||
return String::from("");
|
return String::from("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement
|
|
||||||
pub fn index_of_item_in_container<F>(container: &String, item: &char, func: F) -> i32
|
pub fn index_of_item_in_container<F>(container: &String, item: &char, func: F) -> i32
|
||||||
where
|
where
|
||||||
F: Fn(&char, &char) -> bool,
|
F: Fn(&char, &char) -> bool,
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ use serde::{Deserialize, Serialize};
|
|||||||
pub struct Conversions {}
|
pub struct Conversions {}
|
||||||
|
|
||||||
impl Conversions {
|
impl Conversions {
|
||||||
pub fn to_lower_char(val: &mut char) {
|
pub fn _to_lower_char(val: &mut char) {
|
||||||
if val.is_alphabetic() {
|
if val.is_alphabetic() {
|
||||||
*val = val.to_lowercase().next().unwrap();
|
*val = val.to_lowercase().next().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initialize_values(&self) {}
|
pub fn _initialize_values(&self) {}
|
||||||
|
|
||||||
pub fn print_value<T: std::fmt::Debug>(&self, val: T) {
|
pub fn _print_value<T: std::fmt::Debug>(&self, val: T) {
|
||||||
println!("Going to print value");
|
println!("Going to print value");
|
||||||
println!("{:?}", val);
|
println!("{:?}", val);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user