mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-12-27 16:08:37 -06:00
Compare commits
2 commits
aa097ad982
...
d8ee2ce658
Author | SHA1 | Date | |
---|---|---|---|
d8ee2ce658 | |||
5ecd29926d |
5 changed files with 26 additions and 15 deletions
18
actix/Cargo.lock
generated
18
actix/Cargo.lock
generated
|
@ -363,9 +363,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.80"
|
version = "1.0.81"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1"
|
checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
|
@ -459,9 +459,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.89"
|
version = "1.0.90"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723"
|
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jobserver",
|
"jobserver",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -475,7 +475,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chhoto-url"
|
name = "chhoto-url"
|
||||||
version = "5.0.2"
|
version = "5.0.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-files",
|
"actix-files",
|
||||||
"actix-session",
|
"actix-session",
|
||||||
|
@ -618,9 +618,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_logger"
|
name = "env_logger"
|
||||||
version = "0.11.2"
|
version = "0.11.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6c012a26a7f605efc424dd53697843a72be7dc86ad2d01f7814337794a12231d"
|
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
|
@ -1079,9 +1079,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.78"
|
version = "1.0.79"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
|
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "chhoto-url"
|
name = "chhoto-url"
|
||||||
version = "5.0.2"
|
version = "5.0.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Sayantan Santra <sayantan[dot]santra689[at]gmail[dot]com"]
|
authors = ["Sayantan Santra <sayantan[dot]santra689[at]gmail[dot]com"]
|
||||||
license = "mit"
|
license = "mit"
|
||||||
|
|
|
@ -49,9 +49,9 @@ pub fn add_link(shortlink: String, longlink: String, db: &Connection) -> bool {
|
||||||
.is_ok()
|
.is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_link(shortlink: String, db: &Connection) {
|
pub fn delete_link(shortlink: String, db: &Connection) -> bool {
|
||||||
db.execute("DELETE FROM urls WHERE short_url = ?1", [shortlink])
|
let out = db.execute("DELETE FROM urls WHERE short_url = ?1", [shortlink]);
|
||||||
.unwrap();
|
out.is_ok() && (out.unwrap() > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_db(path: String) -> Connection {
|
pub fn open_db(path: String) -> Connection {
|
||||||
|
|
|
@ -114,8 +114,11 @@ async fn delete_link(
|
||||||
session: Session,
|
session: Session,
|
||||||
) -> HttpResponse {
|
) -> HttpResponse {
|
||||||
if auth::validate(session) {
|
if auth::validate(session) {
|
||||||
database::delete_link(shortlink.to_string(), &data.db);
|
if utils::delete_link(shortlink.to_string(), &data.db) {
|
||||||
HttpResponse::Ok().body("")
|
HttpResponse::Ok().body(format!("Deleted {shortlink}"))
|
||||||
|
} else {
|
||||||
|
HttpResponse::NotFound().body("Not found!")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
HttpResponse::Forbidden().body("Wrong password!")
|
HttpResponse::Forbidden().body("Wrong password!")
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,14 @@ pub fn add_link(req: String, db: &Connection) -> (bool, String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_link(shortlink: String, db: &Connection) -> bool {
|
||||||
|
if validate_link(shortlink.as_str()) {
|
||||||
|
database::delete_link(shortlink, db)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn random_name() -> String {
|
fn random_name() -> String {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
static ADJECTIVES: [&str; 108] = ["admiring", "adoring", "affectionate", "agitated", "amazing", "angry", "awesome", "beautiful",
|
static ADJECTIVES: [&str; 108] = ["admiring", "adoring", "affectionate", "agitated", "amazing", "angry", "awesome", "beautiful",
|
||||||
|
|
Loading…
Reference in a new issue