mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-18 15:23:13 +00:00
feat(downloads): add dedicated Torrent category
This commit is contained in:
@@ -120,6 +120,7 @@ pub enum DownloadCategory {
|
||||
Documents,
|
||||
Pictures,
|
||||
Applications,
|
||||
Torrents,
|
||||
Other,
|
||||
}
|
||||
|
||||
|
||||
+21
-1
@@ -486,7 +486,9 @@ pub fn get_file_category(filename: String) -> DownloadCategory {
|
||||
"run", "sh", "bin", "jar",
|
||||
];
|
||||
|
||||
if music_exts.contains(&ext.as_str()) {
|
||||
if ext == "torrent" {
|
||||
DownloadCategory::Torrents
|
||||
} else if music_exts.contains(&ext.as_str()) {
|
||||
DownloadCategory::Musics
|
||||
} else if movie_exts.contains(&ext.as_str()) {
|
||||
DownloadCategory::Movies
|
||||
@@ -689,3 +691,21 @@ pub fn is_supported_media(url: String) -> bool {
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::get_file_category;
|
||||
use crate::ipc::DownloadCategory;
|
||||
|
||||
#[test]
|
||||
fn classifies_torrent_files_as_torrents() {
|
||||
assert!(matches!(
|
||||
get_file_category("Example.TORRENT".to_string()),
|
||||
DownloadCategory::Torrents
|
||||
));
|
||||
assert!(matches!(
|
||||
get_file_category("Example.mkv".to_string()),
|
||||
DownloadCategory::Movies
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,6 +693,7 @@ fn default_category_subfolders() -> HashMap<String, String> {
|
||||
("Documents", "Documents"),
|
||||
("Pictures", "Pictures"),
|
||||
("Applications", "Applications"),
|
||||
("Torrents", "Torrents"),
|
||||
("Other", "Other"),
|
||||
]
|
||||
.into_iter()
|
||||
@@ -762,6 +763,7 @@ fn migrate_location_settings(state: &mut Value) -> Result<(), String> {
|
||||
("Documents", "Documents"),
|
||||
("Pictures", "Images"),
|
||||
("Applications", "Apps"),
|
||||
("Torrents", "Torrents"),
|
||||
("Other", "Other"),
|
||||
];
|
||||
for (category, alias) in aliases {
|
||||
@@ -1044,6 +1046,7 @@ mod tests {
|
||||
|
||||
assert_eq!(settings.base_download_folder, "/Users/test/Downloads");
|
||||
assert_eq!(settings.category_subfolders["Movies"], "Movies");
|
||||
assert_eq!(settings.category_subfolders["Torrents"], "Torrents");
|
||||
assert!(!settings.category_directory_overrides.contains_key("Movies"));
|
||||
assert_eq!(
|
||||
settings.category_directory_overrides["Documents"],
|
||||
|
||||
Reference in New Issue
Block a user