Version 1.0
This commit is contained in:
parent
2405c9cf31
commit
f080854b84
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -194,7 +194,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chela"
|
||||
version = "0.3.0"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"color-eyre",
|
||||
|
@ -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
|
||||
|
@ -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) => {
|
||||
|
@ -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
|
||||
)
|
||||
",
|
||||
)
|
||||
|
10
src/post.rs
10
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;
|
||||
|
Loading…
Reference in New Issue
Block a user