1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2024-10-16 21:33:54 -05:00
chhoto-url/actix/src/utils.rs
2023-04-03 15:46:22 -05:00

21 lines
448 B
Rust

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 {
"".to_string()
}
}
fn validate_link(link: &str) -> bool {
let re = Regex::new("[a-z0-9-_]+").unwrap();
re.is_match(link)
}
pub fn getall() -> String {
let links = database::getall();
links.join("\n")
}