mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-12-26 07:38:36 -06:00
change: Do not dereference str whenever possible
This commit is contained in:
parent
7b59a9aa5c
commit
a4e7c6b444
2 changed files with 4 additions and 4 deletions
|
@ -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
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue