Add Reference id

This commit is contained in:
2025-10-26 18:25:30 +08:00
parent 11dad7daac
commit ab7f6fe206
7 changed files with 200 additions and 58 deletions

View File

@@ -1,14 +1,14 @@
use std::path::Path;
use clap::{Args, Command, Parser, Subcommand};
use color_eyre::eyre::eyre;
use color_eyre::eyre::Result;
use colored::Colorize;
use tokio::time::Instant;
use crate::models;
use crate::config::types::ApplicationConfig;
use crate::constants::{DB_CF_OPTIONS, DB_OPTIONS};
use crate::crawler::{dlsite, DLSiteCrawler};
use crate::helpers;
use crate::helpers::db::RocksDB;
use crate::models::DLSiteManiax;
#[derive(Parser, Debug)]
pub(super) struct SyncCommand {
@@ -50,10 +50,12 @@ impl SyncSubCommand {
impl SyncDLSiteCommand {
pub async fn handle(&self) -> color_eyre::Result<()> {
let now = Instant::now();
let app_conf = ApplicationConfig::get_config()?;
let db = RocksDB::new(DB_OPTIONS.clone(), DB_CF_OPTIONS.clone())?;
let mut db = RocksDB::new(DB_OPTIONS.clone(), DB_CF_OPTIONS.clone())?;
Self::sync_genres(&app_conf).await?;
Self::sync_works(&app_conf, &db).await?;
Self::sync_works(&app_conf, &mut db).await?;
println!("{} Done in {:.2?}", "Syncing".green(), now.elapsed());
Ok(())
}
@@ -61,14 +63,14 @@ impl SyncDLSiteCommand {
Ok(())
}
async fn sync_works(app_conf: &ApplicationConfig, db: &RocksDB) -> Result<()> {
async fn sync_works(app_conf: &ApplicationConfig, db: &mut RocksDB) -> Result<()> {
let crawler = DLSiteCrawler::new();
let mut rj_nums: Vec<String> = Vec::new();
let paths = app_conf.path_config.dlsite_paths.iter()
let config_paths = app_conf.path_config.dlsite_paths.iter()
.map(|path| Path::new(path).to_path_buf())
.collect::<Vec<_>>();
let dirs = helpers::get_all_folders(&paths).await?;
for dir_path in dirs.iter() {
let dir_paths = helpers::get_all_folders(&config_paths).await?;
for dir_path in dir_paths.iter() {
if !dir_path.is_dir() {
println!("{dir_path:?} is not a directory");
continue;
@@ -82,7 +84,9 @@ impl SyncDLSiteCommand {
}
rj_nums.push(dir_name.to_string());
}
let maniaxes = crawler.get_game_infos(rj_nums).await?;
let maniaxes: Vec<models::DLSiteManiax> = crawler.get_game_infos(rj_nums).await?.into_iter()
.map(|x| x.into())
.collect::<Vec<_>>();
db.set_values(&maniaxes)?;
Ok(())
}