mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-12-26 23:58:35 -06:00
change: Improve consistency in string declaration whenever suitable
This commit is contained in:
parent
ff0a17e57b
commit
7b59a9aa5c
4 changed files with 9 additions and 9 deletions
|
@ -31,7 +31,7 @@ fn check(token: Option<String>) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_token() -> String {
|
pub fn gen_token() -> String {
|
||||||
let token_text = "session-token".to_string();
|
let token_text = String::from("session-token");
|
||||||
let time = SystemTime::now()
|
let time = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.expect("Time went backwards!")
|
.expect("Time went backwards!")
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub fn find_url(shortlink: &str, db: &Connection) -> String {
|
||||||
.query_map([shortlink], |row| row.get("long_url"))
|
.query_map([shortlink], |row| row.get("long_url"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut longlink = "".to_string();
|
let mut longlink = String::new();
|
||||||
for link in links {
|
for link in links {
|
||||||
longlink = link.unwrap();
|
longlink = link.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ async fn getall(data: web::Data<AppState>, session: Session) -> HttpResponse {
|
||||||
#[get("/api/siteurl")]
|
#[get("/api/siteurl")]
|
||||||
async fn siteurl(session: Session) -> HttpResponse {
|
async fn siteurl(session: Session) -> HttpResponse {
|
||||||
if auth::validate(session) {
|
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)
|
HttpResponse::Ok().body(site_url)
|
||||||
} else {
|
} else {
|
||||||
HttpResponse::Forbidden().body("logged_out")
|
HttpResponse::Forbidden().body("logged_out")
|
||||||
|
@ -73,7 +73,7 @@ async fn link_handler(shortlink: web::Path<String>, data: web::Data<AppState>) -
|
||||||
if longlink == *"" {
|
if longlink == *"" {
|
||||||
Redirect::to("/err/404")
|
Redirect::to("/err/404")
|
||||||
} else {
|
} 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);
|
database::add_hit(shortlink.as_str(), &data.db);
|
||||||
if redirect_method == *"TEMPORARY" {
|
if redirect_method == *"TEMPORARY" {
|
||||||
Redirect::to(longlink)
|
Redirect::to(longlink)
|
||||||
|
@ -118,9 +118,9 @@ async fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
// Generate session key in runtime so that restart invalidates older logins
|
// Generate session key in runtime so that restart invalidates older logins
|
||||||
let secret_key = Key::generate();
|
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")
|
let port = env::var("port")
|
||||||
.unwrap_or("4567".to_string())
|
.unwrap_or(String::from("4567"))
|
||||||
.parse::<u16>()
|
.parse::<u16>()
|
||||||
.expect("Supplied port is not an integer");
|
.expect("Supplied port is not an integer");
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub fn get_longurl(shortlink: String, db: &Connection) -> String {
|
||||||
if validate_link(&shortlink) {
|
if validate_link(&shortlink) {
|
||||||
database::find_url(shortlink.as_str(), db)
|
database::find_url(shortlink.as_str(), db)
|
||||||
} else {
|
} 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) {
|
pub fn add_link(req: String, db: &Connection) -> (bool, String) {
|
||||||
let chunks: Vec<&str> = req.split(';').collect();
|
let chunks: Vec<&str> = req.split(';').collect();
|
||||||
let longlink = chunks[0].to_string();
|
let longlink = String::from(chunks[0]);
|
||||||
|
|
||||||
let mut shortlink;
|
let mut shortlink;
|
||||||
if chunks.len() > 1 {
|
if chunks.len() > 1 {
|
||||||
|
@ -41,7 +41,7 @@ pub fn add_link(req: String, db: &Connection) -> (bool, String) {
|
||||||
shortlink,
|
shortlink,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(false, "shortUrl not valid or already in use".to_string())
|
(false, String::from("shortUrl not valid or already in use"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue