Skip to content

Commit

Permalink
fixup! Make built-in adapters' identifiers configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrenierejm committed Sep 4, 2024
1 parent 24f57ef commit b571372
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 85 deletions.
119 changes: 35 additions & 84 deletions src/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod zip;
use crate::{adapted_iter::AdaptedFilesIterBox, config::RgaConfig, matching::*};
use anyhow::{format_err, Context, Result};
use async_trait::async_trait;
use custom::strs;
use custom::CustomAdapterConfig;
use custom::CustomIdentifiers;
use custom::BUILTIN_SPAWNING_ADAPTERS;
Expand Down Expand Up @@ -156,128 +157,78 @@ pub fn get_all_adapters(
.ffmpeg
.extensions
.clone()
.unwrap_or_else(|| {
ffmpeg::EXTENSIONS
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
.unwrap_or_else(|| strs(ffmpeg::EXTENSIONS)),
mimetypes: custom_identifiers
.ffmpeg
.mimetypes
.clone()
.unwrap_or_else(|| {
ffmpeg::MIMETYPES
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
.unwrap_or_else(|| strs(ffmpeg::MIMETYPES)),
}),
Arc::new(zip::ZipAdapter {
extensions: custom_identifiers
.zip
.extensions
.clone()
.unwrap_or_else(|| {
zip::EXTENSIONS
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
mimetypes: custom_identifiers.zip.mimetypes.clone().unwrap_or_else(|| {
zip::MIMETYPES
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
.unwrap_or_else(|| strs(zip::EXTENSIONS)),
mimetypes: custom_identifiers
.zip
.mimetypes
.clone()
.unwrap_or_else(|| strs(zip::MIMETYPES)),
}),
Arc::new(decompress::DecompressAdapter {
extensions_gz: custom_identifiers.gz.extensions.clone().unwrap_or_else(|| {
decompress::EXTENSIONS_GZ
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
extensions_gz: custom_identifiers
.gz
.extensions
.clone()
.unwrap_or_else(|| strs(decompress::EXTENSIONS_GZ)),
extensions_bz2: custom_identifiers
.bz2
.extensions
.clone()
.unwrap_or_else(|| {
decompress::EXTENSIONS_BZ2
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
extensions_xz: custom_identifiers.xz.extensions.clone().unwrap_or_else(|| {
decompress::EXTENSIONS_XZ
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
.unwrap_or_else(|| strs(decompress::EXTENSIONS_BZ2)),
extensions_xz: custom_identifiers
.xz
.extensions
.clone()
.unwrap_or_else(|| strs(decompress::EXTENSIONS_XZ)),
extensions_zst: custom_identifiers
.zst
.extensions
.clone()
.unwrap_or_else(|| {
decompress::EXTENSIONS_ZST
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
mimetypes_gz: custom_identifiers.gz.extensions.clone().unwrap_or_else(|| {
decompress::MIMETYPES_GZ
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
.unwrap_or_else(|| strs(decompress::EXTENSIONS_ZST)),
mimetypes_gz: custom_identifiers
.gz
.extensions
.clone()
.unwrap_or_else(|| strs(decompress::MIMETYPES_GZ)),
mimetypes_bz2: custom_identifiers
.bz2
.extensions
.clone()
.unwrap_or_else(|| {
decompress::MIMETYPES_BZ2
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
mimetypes_xz: custom_identifiers.xz.extensions.clone().unwrap_or_else(|| {
decompress::MIMETYPES_XZ
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
.unwrap_or_else(|| strs(decompress::MIMETYPES_BZ2)),
mimetypes_xz: custom_identifiers
.xz
.extensions
.clone()
.unwrap_or_else(|| strs(decompress::MIMETYPES_XZ)),
mimetypes_zst: custom_identifiers
.zst
.extensions
.clone()
.unwrap_or_else(|| {
decompress::MIMETYPES_ZST
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
.unwrap_or_else(|| strs(decompress::MIMETYPES_ZST)),
}),
Arc::new(mbox::MboxAdapter {
extensions: custom_identifiers
.mbox
.extensions
.clone()
.unwrap_or_else(|| {
mbox::EXTENSIONS
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
.unwrap_or_else(|| strs(mbox::EXTENSIONS)),
mimetypes: custom_identifiers
.mbox
.mimetypes
.clone()
.unwrap_or_else(|| {
mbox::MIMETYPES
.iter()
.map(|&s| s.to_string())
.collect::<Vec<String>>()
}),
.unwrap_or_else(|| strs(mbox::MIMETYPES)),
}),
Arc::new(tar::TarAdapter::new()),
Arc::new(sqlite::SqliteAdapter::new()),
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub struct CustomAdapterConfig {
pub output_path_hint: Option<String>,
}

fn strs(arr: &[&str]) -> Vec<String> {
pub fn strs(arr: &[&str]) -> Vec<String> {
arr.iter().map(ToString::to_string).collect()
}

Expand Down

0 comments on commit b571372

Please sign in to comment.