mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-03-31 09:05:33 +00:00
implement info-hash enum
This commit is contained in:
parent
b3bf89b6f7
commit
dcbb4108fd
3 changed files with 23 additions and 8 deletions
14
src/api.rs
14
src/api.rs
|
|
@ -1,8 +1,11 @@
|
||||||
|
mod info_hash;
|
||||||
|
use info_hash::InfoHash;
|
||||||
|
|
||||||
/// Parse infohash from the source filepath,
|
/// Parse infohash from the source filepath,
|
||||||
/// decode hash bytes to String array on success.
|
/// decode hash bytes to `InfoHash` array on success.
|
||||||
///
|
///
|
||||||
/// * return `None` if the `path` is not reachable
|
/// * return `None` if the `path` is not reachable
|
||||||
pub fn get(path: &str) -> Option<Vec<String>> {
|
pub fn get(path: &str) -> Option<Vec<InfoHash>> {
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
if path.contains("://") {
|
if path.contains("://") {
|
||||||
todo!("URL sources yet not supported")
|
todo!("URL sources yet not supported")
|
||||||
|
|
@ -16,12 +19,7 @@ pub fn get(path: &str) -> Option<Vec<String>> {
|
||||||
if l != L {
|
if l != L {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
r.push(
|
r.push(InfoHash::V1(b[..l].to_vec()))
|
||||||
b[..l]
|
|
||||||
.iter()
|
|
||||||
.map(|i| format!("{i:02x}"))
|
|
||||||
.collect::<String>(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Some(r)
|
Some(r)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
src/api/info_hash.rs
Normal file
15
src/api/info_hash.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
pub enum InfoHash {
|
||||||
|
V1(Vec<u8>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for InfoHash {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::V1(i) => write!(
|
||||||
|
f,
|
||||||
|
"{}",
|
||||||
|
i.iter().map(|b| format!("{b:02x}")).collect::<String>()
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -98,6 +98,8 @@ async fn main() -> Result<()> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} {
|
} {
|
||||||
|
// convert to string once
|
||||||
|
let i = i.to_string();
|
||||||
// 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