mirror of
https://github.com/LowderPlay/cheburcheck.git
synced 2026-09-22 22:37:59 +03:00
fix: download bases without locking
This commit is contained in:
Generated
+1
-1
@@ -4225,7 +4225,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "website"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"dotenvy",
|
||||
"env_logger",
|
||||
|
||||
+15
-29
@@ -7,6 +7,7 @@ use chrono::{DateTime, Utc};
|
||||
use ipnet::IpNet;
|
||||
use log::error;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::io;
|
||||
use std::net::IpAddr;
|
||||
use std::sync::Arc;
|
||||
use maxminddb::MaxMindDbError;
|
||||
@@ -53,6 +54,8 @@ pub enum CheckError {
|
||||
NotFound,
|
||||
}
|
||||
|
||||
pub type Bases = (<GeoIp as Updatable>::Base, <RuBlacklist as Updatable>::Base, <CdnList as Updatable>::Base);
|
||||
|
||||
impl Checker {
|
||||
pub async fn new() -> Checker {
|
||||
let (tx, rx) = watch::channel(None);
|
||||
@@ -132,38 +135,21 @@ impl Checker {
|
||||
self.rx.borrow().clone()
|
||||
}
|
||||
|
||||
pub async fn update_all(&self) {
|
||||
match GeoIp::download().await {
|
||||
Ok(base) => {
|
||||
if let Err(e) = self.geo_ip.write().await.install(base).await {
|
||||
error!("Failed to update GeoIP: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to download GeoIP: {}", e);
|
||||
}
|
||||
pub async fn download_all() -> Result<Bases, io::Error> {
|
||||
Ok((GeoIp::download().await?, RuBlacklist::download().await?, CdnList::download().await?))
|
||||
}
|
||||
|
||||
pub async fn update_all(&self, (geo_ip, ru_blacklist, cdn_list): Bases) {
|
||||
if let Err(e) = self.geo_ip.write().await.install(geo_ip).await {
|
||||
error!("Failed to update GeoIP: {}", e);
|
||||
}
|
||||
match RuBlacklist::download().await {
|
||||
Ok(base) => {
|
||||
if let Err(e) = self.ru_blacklist.write().await.install(base).await {
|
||||
error!("Failed to update RKN: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to download RKN: {}", e);
|
||||
}
|
||||
if let Err(e) = self.ru_blacklist.write().await.install(ru_blacklist).await {
|
||||
error!("Failed to update RKN: {}", e);
|
||||
}
|
||||
if let Err(e) = self.cdn_list.write().await.install(cdn_list).await {
|
||||
error!("Failed to update CDN: {}", e);
|
||||
}
|
||||
|
||||
match CdnList::download().await {
|
||||
Ok(base) => {
|
||||
if let Err(e) = self.cdn_list.write().await.install(base).await {
|
||||
error!("Failed to update CDN: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to download CDN: {}", e);
|
||||
}
|
||||
}
|
||||
self.tx.send(Some(Utc::now())).unwrap();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "website"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
+8
-2
@@ -281,8 +281,14 @@ async fn rocket() -> _ {
|
||||
loop {
|
||||
interval.tick().await;
|
||||
log::info!("Updating all DBs");
|
||||
checker_clone.read().await.update_all().await;
|
||||
log::info!("Updated databases");
|
||||
match Checker::download_all().await {
|
||||
Ok(bases) => {
|
||||
log::info!("Downloaded, updating...");
|
||||
checker_clone.read().await.update_all(bases).await;
|
||||
log::info!("Updated databases");
|
||||
},
|
||||
Err(e) => log::error!("Failed to download all DBs"),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user