mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-04-02 18:15:31 +00:00
handle incomplete (updating) feed sources
This commit is contained in:
parent
8c37cab04e
commit
f4425557ee
2 changed files with 14 additions and 11 deletions
14
src/api.rs
14
src/api.rs
|
|
@ -1,16 +1,10 @@
|
||||||
/// Parse infohash from the source filepath,
|
/// Parse infohash from the source filepath,
|
||||||
/// decode JSON to array on success
|
/// decode JSON to array on success, return None if the feed is damaged (incomplete)
|
||||||
pub fn infohashes(path: &str) -> anyhow::Result<Vec<String>> {
|
pub fn infohashes(path: &str) -> anyhow::Result<Option<Vec<String>>> {
|
||||||
if path.contains("://") {
|
if path.contains("://") {
|
||||||
todo!("URL sources yet not supported")
|
todo!("URL sources yet not supported")
|
||||||
}
|
}
|
||||||
let mut f = std::fs::File::open(path)?;
|
let s = std::fs::read_to_string(path)?;
|
||||||
let mut s = String::new();
|
let r: Option<Vec<String>> = serde_json::from_str(&s).ok();
|
||||||
|
|
||||||
use std::io::Read;
|
|
||||||
f.read_to_string(&mut s)?;
|
|
||||||
|
|
||||||
let r: Vec<String> = serde_json::from_str(&s)?;
|
|
||||||
|
|
||||||
Ok(r)
|
Ok(r)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/main.rs
11
src/main.rs
|
|
@ -89,7 +89,16 @@ async fn main() -> Result<()> {
|
||||||
// * aquatic server may update the stats at this moment, handle result manually
|
// * aquatic server may update the stats at this moment, handle result manually
|
||||||
match api::infohashes(source) {
|
match api::infohashes(source) {
|
||||||
Ok(infohashes) => {
|
Ok(infohashes) => {
|
||||||
for i in infohashes {
|
for i in match infohashes {
|
||||||
|
Some(h) => h,
|
||||||
|
None => {
|
||||||
|
// skip without panic
|
||||||
|
debug.error(&format!(
|
||||||
|
"The feed `{source}` has an incomplete format (or is still updating); skip."
|
||||||
|
));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} {
|
||||||
// is already indexed?
|
// is already indexed?
|
||||||
if index.has(&i) {
|
if index.has(&i) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue