chhoto-url/actix/src/utils.rs

22 lines
448 B
Rust
Raw Normal View History

2023-04-03 13:26:23 +10:00
use crate::database;
use actix_web::web;
use regex::Regex;
pub fn get_longurl(shortlink: web::Path<String>) -> String {
if validate_link(&shortlink) {
database::find_url(shortlink.as_str())
} else {
2023-04-04 06:46:22 +10:00
"".to_string()
2023-04-03 13:26:23 +10:00
}
}
fn validate_link(link: &str) -> bool {
let re = Regex::new("[a-z0-9-_]+").unwrap();
re.is_match(link)
}
2023-04-04 02:55:27 +10:00
pub fn getall() -> String {
let links = database::getall();
links.join("\n")
}