pusher/
util.rs

1use regex::Regex;
2
3pub fn validate_channels(channels: &Vec<String>) -> Result<bool, String> {
4    if channels.len() > 10 {
5        return Err("Cannot trigger on more than 10 channels".to_string());
6    }
7
8    let channel_regex = Regex::new(r"^[-a-zA-Z0-9_=@,.;]+$").unwrap(); // how to make this global?
9
10    for channel in channels {
11        if channel.len() > 200 {
12            return Err("Channel names must be under 200 characters".to_string());
13        }
14        if !channel_regex.is_match(channel) {
15            return Err("Channels must be formatted as such: ^[-a-zA-Z0-9_=@,.;]+$".to_string());
16        }
17    }
18    Ok(true)
19}