ultima chance

This commit is contained in:
2026-06-30 02:16:23 -03:00
parent 1fbe319a10
commit 5761deb298
2 changed files with 96 additions and 18 deletions
+68 -6
View File
@@ -367,26 +367,55 @@ fn load_csv_targets(file: Option<&Path>, inline: Option<&str>) -> Result<Vec<Str
}
if let Some(file) = file {
let content = fs::read_to_string(file)
.with_context(|| format!("failed to read CSV file {}", file.display()))?;
match fs::read_to_string(file) {
Ok(content) => {
let targets = parse_csv_targets(&content);
if !targets.is_empty() {
return Ok(targets);
}
return Err(anyhow!("arquivo CSV vazio: {}", file.display()));
}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
let targets = parse_csv_targets(include_str!("../camfinder-open-rtsp.csv"));
if !targets.is_empty() {
return Ok(targets);
}
return Err(anyhow!(
"arquivo CSV padrão embutido vazio: ../camfinder-open-rtsp.csv"
));
}
Err(err) => {
return Err(anyhow!(err))
.with_context(|| format!("failed to read CSV file {}", file.display()));
}
}
}
if let Ok(path) = env::var("RTSP_TARGETS_FILE") {
let path = path.trim();
if !path.is_empty() {
let content = fs::read_to_string(path)
.with_context(|| format!("failed to read CSV file {path}"))?;
match fs::read_to_string(path) {
Ok(content) => {
let targets = parse_csv_targets(&content);
if !targets.is_empty() {
return Ok(targets);
}
return Err(anyhow!("arquivo CSV vazio: {path}"));
}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
let targets = parse_csv_targets(include_str!("../camfinder-open-rtsp.csv"));
if !targets.is_empty() {
return Ok(targets);
}
return Err(anyhow!(
"arquivo CSV padrão embutido vazio: ../camfinder-open-rtsp.csv"
));
}
Err(err) => {
return Err(err).with_context(|| format!("failed to read CSV file {path}"));
}
}
}
}
if let Ok(value) = env::var("RTSP_TARGETS") {
@@ -449,7 +478,20 @@ fn load_rtsp_paths(file: Option<&Path>, inline: Option<&str>) -> Result<Vec<Stri
if let Ok(path) = env::var("RTSP_PATHS_FILE") {
let path = path.trim();
if !path.is_empty() {
return load_rtsp_paths_from_file(Path::new(path));
return match load_rtsp_paths_from_file(Path::new(path)) {
Ok(paths) => Ok(paths),
Err(err) if is_not_found(&err) => {
let paths = parse_rtsp_paths(include_str!("../rtsp_paths.txt"));
if !paths.is_empty() {
Ok(paths)
} else {
Err(anyhow!(
"arquivo de paths RTSP padrão embutido vazio: ../rtsp_paths.txt"
))
}
}
Err(err) => Err(err),
};
}
}
@@ -463,7 +505,20 @@ fn load_rtsp_paths(file: Option<&Path>, inline: Option<&str>) -> Result<Vec<Stri
}
}
load_rtsp_paths_from_file(Path::new("/app/rtsp_paths.txt"))
match load_rtsp_paths_from_file(Path::new("/app/rtsp_paths.txt")) {
Ok(paths) => Ok(paths),
Err(err) if is_not_found(&err) => {
let paths = parse_rtsp_paths(include_str!("../rtsp_paths.txt"));
if !paths.is_empty() {
Ok(paths)
} else {
Err(anyhow!(
"arquivo de paths RTSP padrão embutido vazio: ../rtsp_paths.txt"
))
}
}
Err(err) => Err(err),
}
}
fn load_rtsp_paths_from_file(file: &Path) -> Result<Vec<String>> {
@@ -476,6 +531,13 @@ fn load_rtsp_paths_from_file(file: &Path) -> Result<Vec<String>> {
Err(anyhow!("arquivo de paths RTSP vazio: {}", file.display()))
}
fn is_not_found(err: &anyhow::Error) -> bool {
err.chain()
.find_map(|cause| cause.downcast_ref::<std::io::Error>())
.map(|err| err.kind() == std::io::ErrorKind::NotFound)
.unwrap_or(false)
}
fn parse_rtsp_paths(input: &str) -> Vec<String> {
let mut seen = std::collections::HashSet::new();
input
+20 -4
View File
@@ -548,8 +548,15 @@ async fn sqlite_exec(sqlite_path: &Path, sql: &str) -> Result<()> {
}
fn load_ip_list(input: &str) -> Result<Vec<String>> {
let content =
fs::read_to_string(input).with_context(|| format!("failed to read input CSV {input}"))?;
let content = match fs::read_to_string(input) {
Ok(content) => content,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
include_str!("../camfinder-open-rtsp.csv").to_string()
}
Err(err) => {
return Err(anyhow!(err)).with_context(|| format!("failed to read input CSV {input}"));
}
};
let mut ips = Vec::new();
for line in content.lines() {
@@ -682,8 +689,17 @@ impl RtspCredential {
}
fn load_rtsp_credentials(path: &Path) -> Result<Vec<RtspCredential>> {
let content = fs::read_to_string(path)
.with_context(|| format!("failed to read RTSP credential file {}", path.display()))?;
let content = match fs::read_to_string(path) {
Ok(content) => content,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
include_str!("../main_ids.json").to_string()
}
Err(err) => {
return Err(anyhow!(err)).with_context(|| {
format!("failed to read RTSP credential file {}", path.display())
});
}
};
let usernames = parse_json_string_array(&content, "usernames")?;
let passwords = parse_json_string_array(&content, "passwords")?;
Ok(build_rtsp_credentials(&usernames, &passwords))