From d193950d204ed82bdb3d6a3a111511d189f084bb Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 29 Jun 2024 13:20:00 +0800 Subject: refactor: the name of temp file (#670) --- src/utils/request.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/utils/request.rs') 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, 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? { -- cgit v1.2.3