Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
buildInputs = deps;
nativeBuildInputs = [pkgs.pkg-config];
env = {GIT_HASH = self.rev or self.dirtyRev or "nix-dirty";};

meta = {
mainProgram = "ursa-minor";
license = lib.licenses.agpl3Only;
};
};
devShells.default = mkShell {
buildInputs =
Expand Down
7 changes: 2 additions & 5 deletions src/lbin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,8 @@ impl Auction {

#[tracing::instrument(skip_all)]
fn item_bytes(&self) -> anyhow::Result<A<u8>> {
let base64_decoded = base64::engine::general_purpose::STANDARD.decode(
self.item_bytes_compressed
.as_ref()
.as_bytes(),
)?;
let base64_decoded = base64::engine::general_purpose::STANDARD
.decode(self.item_bytes_compressed.as_ref().as_bytes())?;

Ok(base64_decoded.into())
}
Expand Down
15 changes: 12 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
extern crate core;

use std::env;
use std::net::SocketAddr;
use std::net::{IpAddr, SocketAddr};
use std::str::FromStr as _;
use std::time::Duration;

use crate::hypixel::Rule;
Expand All @@ -39,8 +40,8 @@ use hyper_tls::HttpsConnector;
use tokio::task::JoinHandle;
use tokio::time::Instant;
use tokio_util::sync::CancellationToken;
use tracing::{error, info, warn};
use tracing::instrument::WithSubscriber;
use tracing::{error, info, warn};

pub mod hypixel;
pub mod meta;
Expand All @@ -67,6 +68,7 @@ pub struct RequestContext {
pub struct GlobalApplicationContext {
client: Client<HttpsConnector<HttpConnector>>,
hypixel_token: Obscure<String>,
address: IpAddr,
port: u16,
rules: Vec<Rule>,
allow_anonymous: bool,
Expand Down Expand Up @@ -173,6 +175,8 @@ fn init_config() -> anyhow::Result<GlobalApplicationContext> {
})
})
.collect::<Result<Vec<Rule>, _>>()?;
let address = IpAddr::from_str(&config_var("ADDRESS").unwrap_or("172.0.0.1".to_owned()))
.with_context(|| "Could not parse bind address at URSA_ADDRESS")?;
let port = config_var("PORT")?
.parse::<u16>()
.with_context(|| "Could not parse port at URSA_PORT")?;
Expand All @@ -191,6 +195,7 @@ fn init_config() -> anyhow::Result<GlobalApplicationContext> {
let rate_limit_bucket = config_var("RATE_LIMIT_BUCKET")?.parse::<u64>()?;
Ok(GlobalApplicationContext {
client,
address,
port,
hypixel_token: Obscure(hypixel_token),
rules,
Expand All @@ -200,6 +205,7 @@ fn init_config() -> anyhow::Result<GlobalApplicationContext> {
default_token_duration: Duration::from_secs(token_lifespan),
rate_limit_lifespan,
rate_limit_bucket,
#[cfg(feature = "influxdb")]
influx_url,
})
}
Expand Down Expand Up @@ -267,7 +273,10 @@ async fn run_server() -> anyhow::Result<()> {
"Launching with configuration: {:#?}",
*global_application_config
);
let addr = SocketAddr::from(([127, 0, 0, 1], global_application_config.port));
let addr = SocketAddr::from((
global_application_config.address,
global_application_config.port,
));
let redis_client = redis::Client::open(global_application_config.redis_url.clone())?;
let managed = redis::aio::ConnectionManager::new(redis_client).await?;
let service = make_service_fn(|_conn| {
Expand Down
4 changes: 4 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use chrono::Utc;
use hyper::http::request::Builder;
use hyper::Uri;
#[cfg(feature = "influxdb")]
use influxdb::Timestamp;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter, Write};
Expand Down Expand Up @@ -69,11 +70,14 @@ impl Debug for MillisecondTimestamp {
}
}

#[cfg(feature = "influxdb")]
impl From<MillisecondTimestamp> for Timestamp {
fn from(value: MillisecondTimestamp) -> Self {
chrono::DateTime::<Utc>::from(SystemTime::from(value)).into()
}
}

#[cfg(feature = "influxdb")]
impl From<Timestamp> for MillisecondTimestamp {
fn from(value: Timestamp) -> Self {
let datetime: chrono::DateTime<Utc> = value.into();
Expand Down