regex date checking
This commit is contained in:
@@ -26,6 +26,7 @@ scraper = "0.24.0"
|
|||||||
once_cell = "1.21.3"
|
once_cell = "1.21.3"
|
||||||
rustc-hash = "2.1.1"
|
rustc-hash = "2.1.1"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
|
regex = "1.12.2"
|
||||||
|
|
||||||
[lints.rust]
|
[lints.rust]
|
||||||
unexpected_cfgs = "allow"
|
unexpected_cfgs = "allow"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use error_chain::error_chain;
|
|||||||
use htmlentity::entity::{ICodedDataTrait, decode};
|
use htmlentity::entity::{ICodedDataTrait, decode};
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
foreign_links {
|
foreign_links {
|
||||||
@@ -18,6 +19,12 @@ error_chain! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_valid_date(s: &str) -> bool {
|
||||||
|
// Regex: strict yyyy-mm-dd (no validation of real calendar dates, just format)
|
||||||
|
let re = Regex::new(r"^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$").unwrap();
|
||||||
|
re.is_match(s)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct XxdbxProvider {
|
pub struct XxdbxProvider {
|
||||||
url: String,
|
url: String,
|
||||||
@@ -124,6 +131,8 @@ impl XxdbxProvider {
|
|||||||
search_type = "channels";
|
search_type = "channels";
|
||||||
} else if self.stars.read().unwrap().iter().map(|s|s.to_ascii_lowercase()).collect::<Vec<String>>().contains(&search_string.to_ascii_lowercase()) {
|
} else if self.stars.read().unwrap().iter().map(|s|s.to_ascii_lowercase()).collect::<Vec<String>>().contains(&search_string.to_ascii_lowercase()) {
|
||||||
search_type = "stars";
|
search_type = "stars";
|
||||||
|
} else if is_valid_date(&search_string){
|
||||||
|
search_type = "dates";
|
||||||
}
|
}
|
||||||
|
|
||||||
let video_url = format!(
|
let video_url = format!(
|
||||||
|
|||||||
Reference in New Issue
Block a user