Replaced Token with AccessToken from icarus-models

This commit is contained in:
phoenix
2025-03-13 21:26:37 -04:00
parent e3cd1f4018
commit 2f00ce6abf
8 changed files with 16 additions and 57 deletions
+2 -2
View File
@@ -175,7 +175,7 @@ impl CommitManager {
let api = prsr.retrieve_api();
let token = self.parse_token(&api);
println!("Message: {}", token.message.clone().unwrap());
println!("Message: {}", token.message);
let mut dwn_loader = syncers::download::Download { api: api.clone() };
let mut song = models::song::Song::default();
@@ -234,7 +234,7 @@ impl CommitManager {
panic!("Not supported");
}
fn parse_token(&self, api: &models::api::API) -> models::token::Token {
fn parse_token(&self, api: &models::api::API) -> icarus_models::token::AccessToken {
println!("Fetching token");
let mut usr_mgr: managers::user_manager::UserManager =
+10 -3
View File
@@ -21,14 +21,21 @@ impl Default for TokenManager {
}
impl TokenManager {
pub async fn request_token(&self) -> Result<models::token::Token, std::io::Error> {
pub async fn request_token(&self) -> Result<icarus_models::token::AccessToken, std::io::Error> {
println!("Sending request for a token");
let url = self.retrieve_url();
println!("URL: {}", url);
let mut token = models::token::Token::default();
let mut token = icarus_models::token::AccessToken{
user_id: -1,
username: String::new(),
token: String::new(),
token_type: String::new(),
expiration: -1,
message: String::new(),
};
let client = reqwest::Client::new();
let response = client.post(&url).json(&self.user).send().await.unwrap();
@@ -36,7 +43,7 @@ impl TokenManager {
match response.status() {
reqwest::StatusCode::OK => {
// on success, parse our JSON to an APIResponse
let s = response.json::<models::token::Token>().await;
let s = response.json::<icarus_models::token::AccessToken>().await;
match s {
//
Ok(parsed) => {
-1
View File
@@ -2,5 +2,4 @@ pub mod api;
pub mod flags;
pub mod icarus_action;
pub mod song;
pub mod token;
pub mod upload_form;
-47
View File
@@ -1,47 +0,0 @@
use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct Token {
#[serde(alias = "user_id")]
pub user_id: i32,
#[serde(alias = "username")]
pub username: Option<String>,
#[serde(alias = "token")]
pub access_token: Option<String>,
#[serde(alias = "token_type")]
pub token_type: Option<String>,
#[serde(alias = "expiration")]
pub expiration: Option<i32>,
#[serde(alias = "message")]
pub message: Option<String>,
}
impl Default for Token {
fn default() -> Self {
Token {
user_id: -1,
username: None,
access_token: None,
token_type: None,
expiration: None,
message: None,
}
}
}
impl Token {
pub fn bearer_token(&self) -> String {
let mut token: String = String::from("Bearer ");
match &self.access_token {
Some(tok) => {
token += tok;
}
None => {}
}
return token;
}
}
+1 -1
View File
@@ -20,7 +20,7 @@ impl Default for Delete {
impl Delete {
pub async fn delete_song(
&mut self,
token: &models::token::Token,
token: &icarus_models::token::AccessToken,
song: &models::song::Song,
) -> Result<models::song::Song, std::io::Error> {
self.api.endpoint = "song/data/delete".to_owned();
+1 -1
View File
@@ -23,7 +23,7 @@ pub enum MyError {
impl Download {
pub async fn download_song(
&mut self,
token: &models::token::Token,
token: &icarus_models::token::AccessToken,
song: &models::song::Song,
) -> Result<String, MyError> {
self.api.endpoint = String::from("song/data/download");
+1 -1
View File
@@ -18,7 +18,7 @@ impl Default for RetrieveRecords {
impl RetrieveRecords {
pub async fn get_all_songs(
&mut self,
token: &models::token::Token,
token: &icarus_models::token::AccessToken,
) -> Result<Vec<models::song::Song>, Error> {
self.api.endpoint = String::from("song");
let mut songs: Vec<models::song::Song> = Vec::new();
+1 -1
View File
@@ -46,7 +46,7 @@ impl Default for Upload {
impl Upload {
pub async fn upload_song_with_metadata(
&mut self,
token: &models::token::Token,
token: &icarus_models::token::AccessToken,
song: &models::song::Song,
cover: &models::song::CoverArt,
album: &models::song::Album,