chore: 支持使用 leaky-bucket 限制请求频率 (#211)

* chore: 移除之前引入的 delay

* feat: 支持为 b 站请求配置频率限制
This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ
2025-01-11 23:24:01 +08:00
committed by GitHub
parent 66a7b1394e
commit 0113bf704d
13 changed files with 57 additions and 65 deletions

View File

@@ -5,12 +5,8 @@ pub mod nfo;
pub mod status;
use chrono::{DateTime, Utc};
use rand::Rng;
use tokio::time;
use tracing_subscriber::util::SubscriberInitExt;
use crate::config::Delay;
pub fn init_logger(log_level: &str) {
tracing_subscriber::fmt::Subscriber::builder()
.with_env_filter(tracing_subscriber::EnvFilter::builder().parse_lossy(log_level))
@@ -26,19 +22,3 @@ pub fn init_logger(log_level: &str) {
pub fn id_time_key(bvid: &String, time: &DateTime<Utc>) -> String {
format!("{}-{}", bvid, time.timestamp())
}
pub(crate) async fn delay(delay: Option<&Delay>) {
match delay {
None => {}
Some(Delay::Random { min, max }) => {
let delay = {
let mut rng = rand::thread_rng();
rng.gen_range(*min..=*max)
};
time::sleep(time::Duration::from_millis(delay)).await;
}
Some(Delay::Fixed(delay)) => {
time::sleep(time::Duration::from_millis(*delay)).await;
}
}
}