Skip to content

Commit

Permalink
fix: sanitize filenames for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
falko17 committed Dec 22, 2024
1 parent 7fb0897 commit f71f8fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ itertools = "0.13.0"
log = "0.4.22"
regex = "1.11.1"
reqwest = { version = "0.12.9", features = ["gzip"] }
sanitize-filename = "0.6.0"
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.133"
serde_with = { version = "3.11.0", features = ["chrono"] }
Expand Down
2 changes: 1 addition & 1 deletion src/data/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Case {

/// Returns what we shall use as a file or directory name for this case.
pub(crate) fn filename(&self) -> String {
format!("{}_{}", &self.case_information.title, self.id())
sanitize_filename::sanitize(format!("{}_{}", &self.case_information.title, self.id()))
}

/// Retrieves a case using the given [`case_id`] from Ace Attorney Online.
Expand Down
9 changes: 7 additions & 2 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use itertools::Itertools;
use log::{debug, error, trace, warn};
use regex::Regex;
use reqwest::Client;
use sanitize_filename::sanitize;
use serde_json::Value;
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -186,12 +187,16 @@ impl AssetCollector {
let name = urlencoding::decode(&name)
.map(Cow::into_owned)
.unwrap_or(name);
let first_choice = self.output.join("assets").join(&name).with_extension(&ext);
let first_choice = self
.output
.join("assets")
.join(sanitize(name.clone()))
.with_extension(&ext);
// If we used this filename already, we need to append a hash.
if self.path_exists(&first_choice) {
self.output
.join("assets")
.join(format!("{name}-{}", Self::hash(url)))
.join(sanitize(format!("{name}-{}", Self::hash(url))))
.with_extension(ext)
} else {
first_choice
Expand Down

0 comments on commit f71f8fb

Please sign in to comment.