mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
update redb api
This commit is contained in:
parent
b4d379c650
commit
66c9e35481
2 changed files with 36 additions and 79 deletions
|
|
@ -23,6 +23,6 @@ urlencoding = "2.1"
|
||||||
yggtracker-redb = "0.1"
|
yggtracker-redb = "0.1"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
# yggtracker-redb = { path = "../yggtracker-redb" }
|
|
||||||
yggtracker-redb = { git = "https://github.com/YGGverse/yggtracker-redb.git", rev="ca9ebedd790b67caf64c049a26d3f45f8e6529d1" }
|
|
||||||
librqbit = { git = "https://github.com/ikatson/rqbit.git", rev="b580a9610ae7c6eaacd305a3905f7e2d3202ca69" }
|
librqbit = { git = "https://github.com/ikatson/rqbit.git", rev="b580a9610ae7c6eaacd305a3905f7e2d3202ca69" }
|
||||||
|
yggtracker-redb = { git = "https://github.com/yggverse/yggtracker-redb.git", rev="9910e0b157591f2ba064aa53bd2720c247485243" }
|
||||||
|
# yggtracker-redb = { path = "../yggtracker-redb" }
|
||||||
|
|
|
||||||
91
src/main.rs
91
src/main.rs
|
|
@ -12,14 +12,12 @@ use librqbit::{
|
||||||
};
|
};
|
||||||
use peers::Peers;
|
use peers::Peers;
|
||||||
use preload::Preload;
|
use preload::Preload;
|
||||||
use std::{
|
use std::{collections::HashSet, num::NonZero, os::unix::ffi::OsStrExt, time::Duration};
|
||||||
collections::HashSet, num::NonZero, os::unix::ffi::OsStrExt, path::PathBuf, time::Duration,
|
|
||||||
};
|
|
||||||
use trackers::Trackers;
|
use trackers::Trackers;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use yggtracker_redb::{
|
use yggtracker_redb::{
|
||||||
Database,
|
Database,
|
||||||
torrent::{Torrent, meta::*},
|
torrent::{Image, Torrent},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|
@ -139,20 +137,20 @@ async fn main() -> Result<()> {
|
||||||
{
|
{
|
||||||
Ok(r) => match r {
|
Ok(r) => match r {
|
||||||
Ok(AddTorrentResponse::Added(id, mt)) => {
|
Ok(AddTorrentResponse::Added(id, mt)) => {
|
||||||
let mut images: HashSet<PathBuf> = HashSet::with_capacity(
|
let mut only_files = HashSet::with_capacity(
|
||||||
config
|
config
|
||||||
.preload_max_filecount
|
.preload_max_filecount
|
||||||
.unwrap_or(config.index_capacity),
|
.unwrap_or(config.index_capacity),
|
||||||
);
|
);
|
||||||
let mut only_files: HashSet<usize> = HashSet::with_capacity(
|
let mut images = Vec::with_capacity(
|
||||||
config
|
config
|
||||||
.preload_max_filecount
|
.preload_max_filecount
|
||||||
.unwrap_or(config.index_capacity),
|
.unwrap_or(config.index_capacity),
|
||||||
);
|
);
|
||||||
mt.wait_until_initialized().await?;
|
mt.wait_until_initialized().await?;
|
||||||
let (name, files, is_private, length, bytes) = mt.with_metadata(|m| {
|
let bytes = mt.with_metadata(|m| {
|
||||||
for info in &m.file_infos {
|
for info in &m.file_infos {
|
||||||
if preload.max_filecount.is_some_and(|limit| images.len() + 1 > limit) {
|
if preload.max_filecount.is_some_and(|limit| only_files.len() + 1 > limit) {
|
||||||
if config.debug {
|
if config.debug {
|
||||||
println!(
|
println!(
|
||||||
"\t\t\ttotal files count limit ({}) for `{i}` reached!",
|
"\t\t\ttotal files count limit ({}) for `{i}` reached!",
|
||||||
|
|
@ -173,77 +171,37 @@ async fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
assert!(images.insert(info.relative_filename.clone()));
|
assert!(only_files.insert(id));
|
||||||
assert!(only_files.insert(id))
|
images.push(info.relative_filename.clone());
|
||||||
}
|
}
|
||||||
let mi = m.info.info();
|
m.info_bytes.to_vec()
|
||||||
(
|
|
||||||
mi.name.as_ref().map(|s| s.to_string()),
|
|
||||||
mi.files.as_ref().map(|f| {
|
|
||||||
let mut b = Vec::with_capacity(f.len());
|
|
||||||
let mut i = f.iter();
|
|
||||||
for f in i.by_ref() {
|
|
||||||
b.push(File {
|
|
||||||
path: String::from_utf8(
|
|
||||||
f.path
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.flat_map(|(n, b)| {
|
|
||||||
if n == 0 {
|
|
||||||
b.0.to_vec()
|
|
||||||
} else {
|
|
||||||
let mut p = vec![b'/'];
|
|
||||||
p.extend(b.0.to_vec());
|
|
||||||
p
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
.ok(),
|
|
||||||
length: f.length,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
b.sort_by(|a, b| a.path.cmp(&b.path)); // @TODO optional
|
|
||||||
b
|
|
||||||
}),
|
|
||||||
mi.private,
|
|
||||||
mi.length,
|
|
||||||
m.torrent_bytes.clone().into()
|
|
||||||
)
|
|
||||||
})?;
|
})?;
|
||||||
session.update_only_files(&mt, &only_files).await?;
|
session.update_only_files(&mt, &only_files).await?;
|
||||||
session.unpause(&mt).await?;
|
session.unpause(&mt).await?;
|
||||||
mt.wait_until_completed().await?;
|
mt.wait_until_completed().await?;
|
||||||
assert!(
|
|
||||||
database
|
// persist torrent data resolved
|
||||||
.set_torrent(
|
database.set_torrent(
|
||||||
&i,
|
&i,
|
||||||
Torrent {
|
Torrent {
|
||||||
bytes,
|
bytes,
|
||||||
meta: Meta {
|
|
||||||
comment: None, // @TODO
|
|
||||||
files,
|
|
||||||
images: if images.is_empty() {
|
images: if images.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let mut b = Vec::with_capacity(images.len());
|
Some(
|
||||||
for p in images {
|
images
|
||||||
b.push(Image {
|
.into_iter()
|
||||||
bytes: preload.bytes(&p)?,
|
.map(|i| Image {
|
||||||
path: p.to_string_lossy().to_string(),
|
alt: i.to_str().map(|p| p.to_string()),
|
||||||
|
bytes: preload.bytes(&i).unwrap(),
|
||||||
})
|
})
|
||||||
}
|
.collect(),
|
||||||
Some(b)
|
)
|
||||||
},
|
},
|
||||||
is_private,
|
|
||||||
name,
|
|
||||||
length,
|
|
||||||
time: chrono::Utc::now(),
|
time: chrono::Utc::now(),
|
||||||
},
|
},
|
||||||
},
|
)?;
|
||||||
)?
|
|
||||||
.is_none()
|
|
||||||
);
|
|
||||||
// remove torrent from session as indexed
|
// remove torrent from session as indexed
|
||||||
session
|
session
|
||||||
.delete(librqbit::api::TorrentIdOrHash::Id(id), false)
|
.delete(librqbit::api::TorrentIdOrHash::Id(id), false)
|
||||||
|
|
@ -254,7 +212,7 @@ async fn main() -> Result<()> {
|
||||||
preload.clear_output_folder(&i)?;
|
preload.clear_output_folder(&i)?;
|
||||||
|
|
||||||
if config.debug {
|
if config.debug {
|
||||||
println!("\t\t\tadd `{i}` to index.")
|
println!("\t\t\ttorrent data successfully resolved.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(_) => panic!(),
|
Ok(_) => panic!(),
|
||||||
|
|
@ -270,8 +228,7 @@ async fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
if config.debug {
|
if config.debug {
|
||||||
println!(
|
println!(
|
||||||
"Queue completed on {time_queue}\n\ttotal: {}\n\ttime: {} s\n\tuptime: {} s\n\tawait {} seconds to continue...",
|
"Queue completed on {time_queue}\n\ttime: {} s\n\tuptime: {} s\n\tawait {} seconds to continue...",
|
||||||
database.torrents_total()?,
|
|
||||||
Local::now()
|
Local::now()
|
||||||
.signed_duration_since(time_queue)
|
.signed_duration_since(time_queue)
|
||||||
.as_seconds_f32(),
|
.as_seconds_f32(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue