1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2024-12-26 23:58:35 -06:00

change: Do not dereference str whenever possible

This commit is contained in:
Sayantan Santra 2023-05-23 18:03:27 -05:00
parent 7b59a9aa5c
commit a4e7c6b444
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F
2 changed files with 4 additions and 4 deletions

View file

@ -70,12 +70,12 @@ async fn error404() -> impl Responder {
async fn link_handler(shortlink: web::Path<String>, data: web::Data<AppState>) -> impl Responder { async fn link_handler(shortlink: web::Path<String>, data: web::Data<AppState>) -> impl Responder {
let shortlink_str = shortlink.to_string(); let shortlink_str = shortlink.to_string();
let longlink = utils::get_longurl(shortlink_str, &data.db); let longlink = utils::get_longurl(shortlink_str, &data.db);
if longlink == *"" { if longlink.is_empty() {
Redirect::to("/err/404") Redirect::to("/err/404")
} else { } else {
let redirect_method = env::var("redirect_method").unwrap_or(String::from("PERMANENT")); let redirect_method = env::var("redirect_method").unwrap_or(String::from("PERMANENT"));
database::add_hit(shortlink.as_str(), &data.db); database::add_hit(shortlink.as_str(), &data.db);
if redirect_method == *"TEMPORARY" { if redirect_method == "TEMPORARY" {
Redirect::to(longlink) Redirect::to(longlink)
} else { } else {
// Defaults to permanent redirection // Defaults to permanent redirection

View file

@ -28,14 +28,14 @@ pub fn add_link(req: String, db: &Connection) -> (bool, String) {
let mut shortlink; let mut shortlink;
if chunks.len() > 1 { if chunks.len() > 1 {
shortlink = chunks[1].to_string().to_lowercase(); shortlink = chunks[1].to_string().to_lowercase();
if shortlink == *"" { if shortlink.is_empty() {
shortlink = random_name(); shortlink = random_name();
} }
} else { } else {
shortlink = random_name(); shortlink = random_name();
} }
if validate_link(shortlink.as_str()) && get_longurl(shortlink.clone(), db) == *"" { if validate_link(shortlink.as_str()) && get_longurl(shortlink.clone(), db).is_empty() {
( (
database::add_link(shortlink.clone(), longlink, db), database::add_link(shortlink.clone(), longlink, db),
shortlink, shortlink,