Skip to content

Commit

Permalink
Replace static to const value
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Mar 17, 2024
1 parent d663d60 commit 04f3599
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
28 changes: 27 additions & 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
Expand Up @@ -11,6 +11,7 @@ axum = { version = "0.7", default-features = false, features = ["http1", "matche
bytes = "1.5"
chrono = "0.4"
clap = { version = "4.5", features = ["derive", "wrap_help"] }
const_format = "0.2.32"
filesize = "0.2"
filetime = "0.2"
futures = "0.3"
Expand All @@ -22,7 +23,6 @@ hyper-util = { version = "0.1", features = ["tokio"] }
inquire = "0.7"
log = { version = "0.4", features = ["std"] }
mime = "0.3"
once_cell = "1.19"
openssl = { version = "*", features = ["vendored"] }
parking_lot = { version = "0.12", features = ["hardware-lock-elision", "deadlock_detection"] }
pin-project-lite = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion src/gallery_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{error::Error, rpc::RPCClient, util};

type BoxError = Box<dyn std::error::Error + Send + Sync>;

static MAX_DOWNLOAD_TASK: u32 = 4;
const MAX_DOWNLOAD_TASK: u32 = 4;

pub struct GalleryDownloader {
client: Arc<RPCClient>,
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
#[no_mangle]
pub static mut malloc_conf: *const u8 = b"percpu_arena:phycpu,tcache:false,dirty_decay_ms:1000,muzzy_decay_ms:0\0".as_ptr();

static VERSION : &str = concat!(env!("CARGO_PKG_VERSION"), "-", env!("VERGEN_GIT_SHA"));
pub static CLIENT_VERSION: &str = "1.6.2";
static MAX_KEY_TIME_DRIFT: RangeInclusive<i64> = -300..=300;
const VERSION : &str = concat!(env!("CARGO_PKG_VERSION"), "-", env!("VERGEN_GIT_SHA"));
pub const CLIENT_VERSION: &str = "1.6.2";
const MAX_KEY_TIME_DRIFT: RangeInclusive<i64> = -300..=300;

#[derive(Parser)]
#[command(version = VERSION)]
Expand Down
5 changes: 2 additions & 3 deletions src/middleware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ use axum::{
response::Response,
Router,
};
use once_cell::sync::Lazy;
use const_format::concatcp;
use tower::{timeout::TimeoutLayer, ServiceBuilder};

use crate::{AppState, CLIENT_VERSION};

use self::connection_counter::ConnectionCounter;
use self::logger::Logger;

static SERVER_HEADER: Lazy<HeaderValue> =
Lazy::new(|| HeaderValue::from_maybe_shared(format!("Genetic Lifeform and Distributed Open Server {CLIENT_VERSION}")).unwrap());
static SERVER_HEADER: HeaderValue = HeaderValue::from_static(concatcp!("Genetic Lifeform and Distributed Open Server ", CLIENT_VERSION));

pub fn register_layer(router: Router<Arc<AppState>>, data: &AppState) -> Router<Arc<AppState>> {
router
Expand Down
3 changes: 2 additions & 1 deletion src/rpc_http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
};

use bytes::Bytes;
use const_format::concatcp;
use http_body_util::{BodyExt, Collected, Empty};
use hyper::{body::Incoming, client::conn::http1::handshake, http::Error as HttpError, Request, Response};
use hyper_util::rt::TokioIo;
Expand Down Expand Up @@ -163,7 +164,7 @@ async fn create_stream(server: &str) -> Result<TokioIo<TcpStream>, IoError> {
fn build_request(url: &Url) -> Result<Request<Empty<Bytes>>, HttpError> {
Request::builder()
.header("Host", url.host_str().unwrap())
.header("User-Agent", format!("Hentai@Home {CLIENT_VERSION}"))
.header("User-Agent", concatcp!("Hentai@Home ",CLIENT_VERSION))
.uri(url.as_str())
.body(Empty::<Bytes>::new())
}
3 changes: 2 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::Duration;

use const_format::concatcp;
use futures::future::try_join_all;
use openssl::sha::Sha1;
use reqwest::Proxy;
Expand All @@ -15,7 +16,7 @@ pub fn string_to_hash(str: String) -> String {

pub fn create_http_client(timeout: Duration, proxy: Option<Proxy>) -> reqwest::Client {
let mut builder = reqwest::ClientBuilder::new()
.user_agent(format!("Hentai@Home {CLIENT_VERSION}"))
.user_agent(concatcp!("Hentai@Home ", CLIENT_VERSION))
.tcp_keepalive(Duration::from_secs(75)) // Linux default keepalive inverval
.connect_timeout(Duration::from_secs(5))
.timeout(timeout)
Expand Down

0 comments on commit 04f3599

Please sign in to comment.