mirror of
https://codeberg.org/YGGverse/ytd.git
synced 2026-04-08 12:55:32 +00:00
prevent unexpected item ID handle as used the {ID} exec context
This commit is contained in:
parent
dab3454972
commit
4e2f3d5de4
1 changed files with 8 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ use clap::Parser;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use database::Database;
|
use database::Database;
|
||||||
use log::*;
|
use log::*;
|
||||||
|
use regex::Regex;
|
||||||
use rustypipe::client::RustyPipe;
|
use rustypipe::client::RustyPipe;
|
||||||
use std::{env::var, process::Command, thread, time::Duration};
|
use std::{env::var, process::Command, thread, time::Duration};
|
||||||
|
|
||||||
|
|
@ -34,6 +35,7 @@ async fn main() {
|
||||||
let sleep = config.sleep.map(Duration::from_secs);
|
let sleep = config.sleep.map(Duration::from_secs);
|
||||||
let mut database = Database::new(&config.database).unwrap();
|
let mut database = Database::new(&config.database).unwrap();
|
||||||
let rp = RustyPipe::new();
|
let rp = RustyPipe::new();
|
||||||
|
let channel_item_id_regex = Regex::new(r"^[A-z0-9_-]{11}$").unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(ref before) = config.before {
|
if let Some(ref before) = config.before {
|
||||||
|
|
@ -52,6 +54,12 @@ async fn main() {
|
||||||
channel.items_limit
|
channel.items_limit
|
||||||
);
|
);
|
||||||
for (i, item) in items.into_iter().enumerate() {
|
for (i, item) in items.into_iter().enumerate() {
|
||||||
|
if !channel_item_id_regex.is_match(&item.id) {
|
||||||
|
panic!(
|
||||||
|
"received unexpected item ID `{}`; unsafe to continue in the exec context",
|
||||||
|
&item.id
|
||||||
|
)
|
||||||
|
}
|
||||||
if channel.items_limit.is_some_and(|l| i >= l) {
|
if channel.items_limit.is_some_and(|l| i >= l) {
|
||||||
debug!("items limit for channel `{c}` reached at {i}; break.");
|
debug!("items limit for channel `{c}` reached at {i}; break.");
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue