1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2024-12-25 23:28:37 -06:00

change: Improve consistency in string declaration whenever suitable

This commit is contained in:
Sayantan Santra 2023-05-23 17:58:57 -05:00
parent ff0a17e57b
commit 7b59a9aa5c
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F
4 changed files with 9 additions and 9 deletions

View file

@ -31,7 +31,7 @@ fn check(token: Option<String>) -> bool {
}
pub fn gen_token() -> String {
let token_text = "session-token".to_string();
let token_text = String::from("session-token");
let time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("Time went backwards!")

View file

@ -9,7 +9,7 @@ pub fn find_url(shortlink: &str, db: &Connection) -> String {
.query_map([shortlink], |row| row.get("long_url"))
.unwrap();
let mut longlink = "".to_string();
let mut longlink = String::new();
for link in links {
longlink = link.unwrap();
}

View file

@ -50,7 +50,7 @@ async fn getall(data: web::Data<AppState>, session: Session) -> HttpResponse {
#[get("/api/siteurl")]
async fn siteurl(session: Session) -> HttpResponse {
if auth::validate(session) {
let site_url = env::var("site_url").unwrap_or("unset".to_string());
let site_url = env::var("site_url").unwrap_or(String::from("unset"));
HttpResponse::Ok().body(site_url)
} else {
HttpResponse::Forbidden().body("logged_out")
@ -73,7 +73,7 @@ async fn link_handler(shortlink: web::Path<String>, data: web::Data<AppState>) -
if longlink == *"" {
Redirect::to("/err/404")
} else {
let redirect_method = env::var("redirect_method").unwrap_or("PERMANENT".to_string());
let redirect_method = env::var("redirect_method").unwrap_or(String::from("PERMANENT"));
database::add_hit(shortlink.as_str(), &data.db);
if redirect_method == *"TEMPORARY" {
Redirect::to(longlink)
@ -118,9 +118,9 @@ async fn main() -> std::io::Result<()> {
// Generate session key in runtime so that restart invalidates older logins
let secret_key = Key::generate();
let db_location = env::var("db_url").unwrap_or("/urls.sqlite".to_string());
let db_location = env::var("db_url").unwrap_or(String::from("/urls.sqlite"));
let port = env::var("port")
.unwrap_or("4567".to_string())
.unwrap_or(String::from("4567"))
.parse::<u16>()
.expect("Supplied port is not an integer");

View file

@ -7,7 +7,7 @@ pub fn get_longurl(shortlink: String, db: &Connection) -> String {
if validate_link(&shortlink) {
database::find_url(shortlink.as_str(), db)
} else {
"".to_string()
String::new()
}
}
@ -23,7 +23,7 @@ pub fn getall(db: &Connection) -> String {
pub fn add_link(req: String, db: &Connection) -> (bool, String) {
let chunks: Vec<&str> = req.split(';').collect();
let longlink = chunks[0].to_string();
let longlink = String::from(chunks[0]);
let mut shortlink;
if chunks.len() > 1 {
@ -41,7 +41,7 @@ pub fn add_link(req: String, db: &Connection) -> (bool, String) {
shortlink,
)
} else {
(false, "shortUrl not valid or already in use".to_string())
(false, String::from("shortUrl not valid or already in use"))
}
}