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