aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2024-04-07 15:35:46 -0400
committerShav Kinderlehrer <[email protected]>2024-04-07 15:35:46 -0400
commitf080854b84d80f6063b4f9392d059a84ec09e66c (patch)
treec5b64f79fc808b0dd417ca18753aa81e17444770
parent2405c9cf315f3bba470a2d373089ff011a20572e (diff)
downloadchela-f080854b84d80f6063b4f9392d059a84ec09e66c.tar.gz
chela-f080854b84d80f6063b4f9392d059a84ec09e66c.zip
Version 1.0v1.0.0
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/get.rs8
-rw-r--r--src/main.rs3
-rw-r--r--src/post.rs10
5 files changed, 12 insertions, 13 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 35d1164..131718f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -194,7 +194,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chela"
-version = "0.3.0"
+version = "1.0.0"
dependencies = [
"axum",
"color-eyre",
diff --git a/Cargo.toml b/Cargo.toml
index df4e751..741083f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "chela"
-version = "0.3.1"
+version = "1.0.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/src/get.rs b/src/get.rs
index e6b7426..61c5dd2 100644
--- a/src/get.rs
+++ b/src/get.rs
@@ -43,9 +43,7 @@ pub async fn id(
Path(id): Path<String>,
) -> impl IntoResponse {
let mut show_request = false;
- let ip = get_ip(headers.clone(), addr, state.clone())
- .await
- .unwrap_or_default();
+ let ip = get_ip(&headers, addr, &state).unwrap_or_default();
log!("Request for '{}' from {}", id.clone(), ip);
let mut use_id = id;
if use_id.ends_with('+') {
@@ -96,7 +94,7 @@ pub async fn id(
async fn save_analytics(headers: HeaderMap, item: UrlRow, addr: SocketAddr, state: ServerState) {
let id = item.id;
- let ip = get_ip(headers.clone(), addr, state.clone()).await;
+ let ip = get_ip(&headers, addr, &state);
let referer = match headers.get("referer") {
Some(it) => {
if let Ok(i) = it.to_str() {
@@ -136,7 +134,7 @@ VALUES ($1,$2,$3,$4)
}
}
-async fn get_ip(headers: HeaderMap, addr: SocketAddr, state: ServerState) -> Option<String> {
+fn get_ip(headers: &HeaderMap, addr: SocketAddr, state: &ServerState) -> Option<String> {
if state.behind_proxy {
match headers.get("x-real-ip") {
Some(it) => {
diff --git a/src/main.rs b/src/main.rs
index ccad3e8..e307b8e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -98,7 +98,8 @@ async fn init_db() -> eyre::Result<Pool<Postgres>> {
CREATE TABLE IF NOT EXISTS chela.urls (
index BIGSERIAL PRIMARY KEY,
id TEXT NOT NULL UNIQUE,
- url TEXT NOT NULL
+ url TEXT NOT NULL,
+ custom_id BOOLEAN NOT NULL
)
",
)
diff --git a/src/post.rs b/src/post.rs
index b597f99..e19d6ae 100644
--- a/src/post.rs
+++ b/src/post.rs
@@ -44,8 +44,8 @@ pub async fn create_link(
if let Some(index) = id.index {
res = sqlx::query(
"
-INSERT INTO chela.urls (index,id,url)
-VALUES ($1,$2,$3)
+INSERT INTO chela.urls (index,id,url,custom_id)
+VALUES ($1,$2,$3,false)
",
)
.bind(index)
@@ -56,8 +56,8 @@ VALUES ($1,$2,$3)
} else {
res = sqlx::query(
"
-INSERT INTO chela.urls (id,url)
-VALUES ($1,$2)
+INSERT INTO chela.urls (id,url,custom_id)
+VALUES ($1,$2,true)
",
)
.bind(id.id.clone())
@@ -102,7 +102,7 @@ VALUES ($1,$2)
async fn generate_id(form: CreateForm, state: ServerState) -> eyre::Result<NextId> {
if form.id.is_empty() {
let existing_row: Result<UrlRow, sqlx::Error> =
- sqlx::query_as("SELECT * FROM chela.urls WHERE url = $1")
+ sqlx::query_as("SELECT * FROM chela.urls WHERE url = $1 AND custom_id = 'false'")
.bind(form.url.as_str())
.fetch_one(&state.db_pool)
.await;