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 20, 2024
1 parent c078e4d commit 5f78120
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 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 @@ -52,9 +52,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/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 5f78120

Please sign in to comment.