Skip to content

Commit

Permalink
Fixed required USER-AGENT
Browse files Browse the repository at this point in the history
  • Loading branch information
tonymushah committed Aug 17, 2023
1 parent df5641e commit d24eee8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mangadex-desktop-api2"
version = "0.3.0"
version = "0.4.0"
authors = ["tonymushah <tonymushahdev06@yahoo.com>"]
license = "MIT OR Apache-2.0"
description = "A Actix server for downloading manga, chapters, covers from Mangadex"
Expand Down
4 changes: 2 additions & 2 deletions src/methods/get.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::methods::get_params;
use crate::settings::files_dirs::DirsOptions;
use crate::r#static::history::{get_history_w_file_by_rel_or_init};
use crate::r#static::history::get_history_w_file_by_rel_or_init;
use crate::utils::chapter::get_all_downloaded_chapters;
use crate::utils::query::get_query_hash_value_or_else;
use crate::utils::manga::{
Expand All @@ -17,7 +17,7 @@ use mangadex_api_schema_rust::{ApiData, ApiObject};
use mangadex_api_types_rust::RelationshipType;
use std::num::ParseIntError;
use std::path::Path;
use std::str::{FromStr};
use std::str::FromStr;

/// try if the app is ok
/// # How to use
Expand Down
4 changes: 2 additions & 2 deletions src/methods/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use crate::download::cover::{
use crate::download::manga::download_manga;
use crate::server::AppState;
use crate::this_api_result;
use actix_web::http::header::{ContentType};
use actix_web::http::header::ContentType;
use actix_web::{
put, web, HttpResponse,
Responder,
};
use log::{info};
use log::info;
use mangadex_api::utils::download::cover::CoverQuality;

// NOTE All download methods
Expand Down
26 changes: 22 additions & 4 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use futures::lock::Mutex;
use mangadex_api::{HttpClient, HttpClientRef};
#[cfg(feature = "unix-socket-support")]
mod unix;
use reqwest::header::{HeaderMap, HeaderValue};
use reqwest::Client;
#[cfg(feature = "unix-socket-support")]
pub use unix::launch_async_server_with_unix_socket;
/*use self::state::AppState;
Expand All @@ -42,7 +44,7 @@ pub mod state;
/// url not found handler
///
///
///
///

#[derive(Clone)]
pub struct AppState {
Expand All @@ -68,7 +70,9 @@ fn not_found_message<B>(
Ok(ErrorHandlerResponse::Response(res))
}

pub fn get_actix_app() -> App<
pub fn get_actix_app(
client: Client,
) -> App<
impl ServiceFactory<
ServiceRequest,
Config = (),
Expand All @@ -78,7 +82,7 @@ pub fn get_actix_app() -> App<
> + 'static,
> {
let state = AppState {
http_client: Arc::new(Mutex::new(HttpClient::default())),
http_client: Arc::new(Mutex::new(HttpClient::new(client))),
};
App::new()
.app_data(web::Data::new(state))
Expand Down Expand Up @@ -131,7 +135,21 @@ pub fn get_actix_app() -> App<

/// Get the server handle
pub fn launch_async_server(address: &str, port: u16) -> std::io::Result<Server> {
Ok(HttpServer::new(get_actix_app)
let mut headers = HeaderMap::new();
headers.insert(
"User-Agent",
HeaderValue::from_static("special-eureka-manager/0.4.0"),
);
let client = match Client::builder().default_headers(headers).build() {
Ok(c) => c,
Err(e) => {
return std::io::Result::Err(std::io::Error::new(
std::io::ErrorKind::Other,
e.to_string(),
))
}
};
Ok(HttpServer::new(move|| get_actix_app(client.clone()))
.bind((address, port))?
.run())
}

0 comments on commit d24eee8

Please sign in to comment.