use text for key
This commit is contained in:
parent
66c51f8391
commit
a2c466f5ac
|
@ -612,6 +612,7 @@ dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
"hex",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
"rand",
|
"rand",
|
||||||
|
|
|
@ -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"] }
|
clap = { version = "4.5", default-features = false, features = ["std", "derive", "unicode", "help", "usage"] }
|
||||||
dotenvy = { version = "0.15", default-features = false }
|
dotenvy = { version = "0.15", default-features = false }
|
||||||
env_logger = { version = "0.11", default-features = false, features = ["humantime"] }
|
env_logger = { version = "0.11", default-features = false, features = ["humantime"] }
|
||||||
|
hex = "0.4"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
log = { version = "0.4", default-features = false, features = ["std"] }
|
log = { version = "0.4", default-features = false, features = ["std"] }
|
||||||
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] }
|
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"] }
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
create table if not exists hits (
|
create table if not exists hits (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
page text not null, -- the slug from the page
|
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
|
accessed timestamp not null default CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::{
|
||||||
use axum::{
|
use axum::{
|
||||||
debug_handler,
|
debug_handler,
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
http::{header::REFERER, method::Method, HeaderMap, HeaderValue},
|
http::{method::Method, HeaderMap, HeaderValue},
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,6 @@ use ring::digest::{Context, SHA256};
|
||||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions};
|
use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions};
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tower_http::cors::{self, CorsLayer};
|
use tower_http::cors::{self, CorsLayer};
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref HITMAN_ORIGIN: String =
|
static ref HITMAN_ORIGIN: String =
|
||||||
|
@ -72,7 +71,7 @@ async fn register_hit(
|
||||||
|
|
||||||
let salt = *SESSION_SALT;
|
let salt = *SESSION_SALT;
|
||||||
let key = format!("{now}{host}{slug}{salt}").into_bytes();
|
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,)
|
sqlx::query!("insert into hits (page, hit_key) values (?, ?)", slug, key,)
|
||||||
.execute(&db)
|
.execute(&db)
|
||||||
|
|
Loading…
Reference in New Issue