mirror of
https://github.com/minoplhy/chhoto-url.git
synced 2024-11-22 01:06:46 +00:00
change: Do not dereference str whenever possible
This commit is contained in:
parent
7b59a9aa5c
commit
a4e7c6b444
@ -70,12 +70,12 @@ async fn error404() -> impl Responder {
|
||||
async fn link_handler(shortlink: web::Path<String>, data: web::Data<AppState>) -> impl Responder {
|
||||
let shortlink_str = shortlink.to_string();
|
||||
let longlink = utils::get_longurl(shortlink_str, &data.db);
|
||||
if longlink == *"" {
|
||||
if longlink.is_empty() {
|
||||
Redirect::to("/err/404")
|
||||
} else {
|
||||
let redirect_method = env::var("redirect_method").unwrap_or(String::from("PERMANENT"));
|
||||
database::add_hit(shortlink.as_str(), &data.db);
|
||||
if redirect_method == *"TEMPORARY" {
|
||||
if redirect_method == "TEMPORARY" {
|
||||
Redirect::to(longlink)
|
||||
} else {
|
||||
// Defaults to permanent redirection
|
||||
|
@ -28,14 +28,14 @@ pub fn add_link(req: String, db: &Connection) -> (bool, String) {
|
||||
let mut shortlink;
|
||||
if chunks.len() > 1 {
|
||||
shortlink = chunks[1].to_string().to_lowercase();
|
||||
if shortlink == *"" {
|
||||
if shortlink.is_empty() {
|
||||
shortlink = random_name();
|
||||
}
|
||||
} else {
|
||||
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),
|
||||
shortlink,
|
||||
|
Loading…
Reference in New Issue
Block a user