diff --git a/Cargo.lock b/Cargo.lock index de3cad8..c7c0e3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -612,6 +612,7 @@ dependencies = [ "clap", "dotenvy", "env_logger", + "hex", "lazy_static", "log", "rand", diff --git a/Cargo.toml b/Cargo.toml index c3c5168..eb2acb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ chrono = { version = "0.4", default-features = false, features = ["now"] } clap = { version = "4.5", default-features = false, features = ["std", "derive", "unicode", "help", "usage"] } dotenvy = { version = "0.15", default-features = false } env_logger = { version = "0.11", default-features = false, features = ["humantime"] } +hex = "0.4" lazy_static = "1.4" log = { version = "0.4", default-features = false, features = ["std"] } rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] } diff --git a/migrations/20240317182405_hits.up.sql b/migrations/20240317182405_hits.up.sql index a5853c2..2886a6d 100644 --- a/migrations/20240317182405_hits.up.sql +++ b/migrations/20240317182405_hits.up.sql @@ -1,7 +1,7 @@ create table if not exists hits ( id integer primary key, page text not null, -- the slug from the page - hit_key blob not null unique, + hit_key text not null unique, accessed timestamp not null default CURRENT_TIMESTAMP ); diff --git a/src/main.rs b/src/main.rs index 4c8ad56..f2d312a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use std::{ use axum::{ debug_handler, extract::{Path, State}, - http::{header::REFERER, method::Method, HeaderMap, HeaderValue}, + http::{method::Method, HeaderMap, HeaderValue}, routing::get, Router, }; @@ -18,7 +18,6 @@ use ring::digest::{Context, SHA256}; use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions}; use tokio::net::TcpListener; use tower_http::cors::{self, CorsLayer}; -use url::Url; lazy_static! { static ref HITMAN_ORIGIN: String = @@ -72,7 +71,7 @@ async fn register_hit( let salt = *SESSION_SALT; let key = format!("{now}{host}{slug}{salt}").into_bytes(); - let key = shasum(&key); + let key = hex::encode(shasum(&key)); sqlx::query!("insert into hits (page, hit_key) values (?, ?)", slug, key,) .execute(&db)