Skip to content

Commit

Permalink
fix(redacted): check if files exceed redacteds allowed path limit
Browse files Browse the repository at this point in the history
  • Loading branch information
DevYukine committed Apr 23, 2023
1 parent 3b56f9d commit 020afab
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Arc;

use clap::{arg, Parser, Subcommand};
use console::Term;
use dialoguer::Confirm;
use dialoguer::{Confirm, Input};
use html_escape::decode_html_entities;
use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle};
use lazy_static::lazy_static;
Expand All @@ -22,6 +22,7 @@ use transcode::transcode::transcode_release;
use crate::fs::util::get_all_files_with_extension;
use crate::redacted::api::client::RedactedApi;
use crate::redacted::api::constants::TRACKER_URL;
use crate::redacted::api::path::is_path_exceeding_redacted_path_limit;
use crate::redacted::models::{Category, Media, ReleaseType};
use crate::redacted::upload::TorrentUploadData;
use crate::redacted::util::perma_link;
Expand Down Expand Up @@ -533,6 +534,22 @@ async fn handle_url(

for (path, format, command) in &path_format_command_triple {
let release_name = path.file_name().unwrap().to_str().unwrap();
let mut exceeds_red_path_length = is_path_exceeding_redacted_path_limit(&path).await?;

while exceeds_red_path_length {
let mut editor = Input::new();

let edited_text = editor
.with_prompt(format!(
"{} Folder Name {} is too long for RED, please shorten the folder name\n",
ERROR, release_name
))
.default(release_name.to_string())
.interact_text()?;

let new_path = path.parent().unwrap().join(edited_text);
exceeds_red_path_length = is_path_exceeding_redacted_path_limit(&new_path).await?;
}

let torrent_path = torrent_directory.join(release_name.to_owned() + ".torrent");

Expand Down
1 change: 1 addition & 0 deletions src/redacted/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod client;
pub mod constants;
pub mod error;
pub mod model;
pub mod path;
22 changes: 22 additions & 0 deletions src/redacted/api/path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::fs::util::get_all_files_with_extension;
use std::path::PathBuf;

const REDACTED_MAX_LENGTH: usize = 180;

pub async fn is_path_exceeding_redacted_path_limit(folder_path: &PathBuf) -> anyhow::Result<bool> {
let folder_name = folder_path.file_name().unwrap().to_str().unwrap();

let dir = get_all_files_with_extension(folder_path, ".flac").await?;

for flac_path in dir {
let flac_name = flac_path.file_name().unwrap().to_str().unwrap();

let full_path = format!("{}/{}", folder_name, flac_name);

if full_path.len() > REDACTED_MAX_LENGTH {
return Ok(true);
}
}

Ok(false)
}

0 comments on commit 020afab

Please # to comment.