Add URL logging to urls.txt during size calculation phase

This commit is contained in:
Yuhki 2025-05-23 16:50:28 +02:00
parent 7bd0b77bd0
commit 808f929e62
5 changed files with 148 additions and 130 deletions

View file

@ -2,8 +2,8 @@ use colored::Colorize;
use reqwest::blocking::Client; use reqwest::blocking::Client;
use serde_json::Value; use serde_json::Value;
use std::{ use std::{
fs::File, fs::{self, File},
io, io::{self, Write},
sync::Arc, sync::Arc,
thread, thread,
time::{Duration, Instant}, time::{Duration, Instant},
@ -37,6 +37,23 @@ pub fn bytes_to_human(bytes: u64) -> String {
} }
} }
fn log_url(url: &str) {
let sanitized_url = if let Some(index) = url.find("://") {
let (scheme, rest) = url.split_at(index + 3);
format!("{}{}", scheme, rest.replace("//", "/"))
} else {
url.replace("//", "/")
};
if let Ok(mut url_log) = fs::OpenOptions::new()
.create(true)
.append(true)
.open("urls.txt")
{
let _ = writeln!(url_log, "{}", sanitized_url);
}
}
pub fn calculate_total_size(resources: &[Value], client: &Client, config: &Config) -> u64 { pub fn calculate_total_size(resources: &[Value], client: &Client, config: &Config) -> u64 {
let mut total_size = 0; let mut total_size = 0;
let mut failed_urls = 0; let mut failed_urls = 0;
@ -50,6 +67,7 @@ pub fn calculate_total_size(resources: &[Value], client: &Client, config: &Confi
for base_url in &config.zip_bases { for base_url in &config.zip_bases {
let url = format!("{}/{}", base_url, dest); let url = format!("{}/{}", base_url, dest);
log_url(&url);
match client.head(&url).send() { match client.head(&url).send() {
Ok(response) => { Ok(response) => {
if let Some(len) = response.headers().get("content-length") { if let Some(len) = response.headers().get("content-length") {
@ -189,7 +207,7 @@ pub fn start_title_thread(
String::new() String::new()
}; };
let title = format!( let _title = format!(
"Wuthering Waves Downloader - {}/{} files - Total Downloaded: {}{} - Speed: {}{} - Total ETA: {}", "Wuthering Waves Downloader - {}/{} files - Total Downloaded: {}{} - Speed: {}{} - Total ETA: {}",
current_success, current_success,
total_files, total_files,