summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/command.rs5
-rw-r--r--src/utils/mod.rs12
-rw-r--r--src/utils/request.rs7
3 files changed, 13 insertions, 11 deletions
diff --git a/src/utils/command.rs b/src/utils/command.rs
index 1a7de5b..3876f3d 100644
--- a/src/utils/command.rs
+++ b/src/utils/command.rs
@@ -98,10 +98,7 @@ pub fn run_loader_command(path: &str, extension: &str, loader_command: &str) ->
anyhow!("Invalid rag document loader '{extension}': `{loader_command}`")
})?;
let mut use_stdout = true;
- let outpath = env::temp_dir()
- .join(format!("aichat-output-{}", sha256(path)))
- .display()
- .to_string();
+ let outpath = temp_file("-output-", "").display().to_string();
let cmd_args: Vec<_> = cmd_args
.into_iter()
.map(|mut v| {
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index e36a54b..548c6f1 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -38,8 +38,8 @@ pub fn now() -> String {
pub fn get_env_name(key: &str) -> String {
format!(
"{}_{}",
- env!("CARGO_CRATE_NAME").to_ascii_uppercase(),
- key.to_ascii_uppercase(),
+ env!("CARGO_CRATE_NAME").to_uppercase(),
+ key.to_uppercase(),
)
}
@@ -183,6 +183,14 @@ pub fn safe_join_path<T1: AsRef<Path>, T2: AsRef<Path>>(
}
}
+pub fn temp_file(prefix: &str, suffix: &str) -> PathBuf {
+ env::temp_dir().join(format!(
+ "{}{prefix}{}{suffix}",
+ env!("CARGO_CRATE_NAME").to_lowercase(),
+ uuid::Uuid::new_v4()
+ ))
+}
+
pub fn set_proxy(
builder: reqwest::ClientBuilder,
proxy: Option<&String>,
diff --git a/src/utils/request.rs b/src/utils/request.rs
index bc5388c..fadd3b8 100644
--- a/src/utils/request.rs
+++ b/src/utils/request.rs
@@ -3,7 +3,7 @@ use super::*;
use anyhow::{bail, Result};
use http::header::CONTENT_TYPE;
use lazy_static::lazy_static;
-use std::{collections::HashMap, env, time::Duration};
+use std::{collections::HashMap, time::Duration};
use tokio::io::AsyncWriteExt;
pub const URL_LOADER: &str = "url";
@@ -48,10 +48,7 @@ pub async fn fetch(loaders: &HashMap<String, String>, path: &str) -> Result<(Str
}
let result = match loaders.get(&extension) {
Some(loader_command) => {
- let save_path = env::temp_dir()
- .join(format!("aichat-download-{}.{extension}", sha256(path)))
- .display()
- .to_string();
+ let save_path = temp_file("-download-", "").display().to_string();
let mut save_file = tokio::fs::File::create(&save_path).await?;
let mut size = 0;
while let Some(chunk) = res.chunk().await? {