diff --git a/crates/api_clients/artcraft/artcraft_client/Cargo.toml b/crates/api_clients/artcraft/artcraft_client/Cargo.toml index 6987761299..4fa416b0aa 100644 --- a/crates/api_clients/artcraft/artcraft_client/Cargo.toml +++ b/crates/api_clients/artcraft/artcraft_client/Cargo.toml @@ -33,6 +33,7 @@ chrono.workspace = true cookie.workspace = true log.workspace = true reqwest = { workspace = true, features = ["multipart", "gzip"] } +tokio = { workspace = true, features = ["fs"] } url.workspace = true # Serialization diff --git a/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/legacy_upload_media_file_from_file.rs b/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/legacy_upload_media_file_from_file.rs index 9d0b0e1d59..964ec52c4a 100644 --- a/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/legacy_upload_media_file_from_file.rs +++ b/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/legacy_upload_media_file_from_file.rs @@ -60,7 +60,7 @@ pub async fn legacy_upload_media_file_from_file>( .build() .map_err(|err| StorytellerError::Client(ClientError::from(err)))?; - let file_bytes = std::fs::read(args.path.as_ref()) + let file_bytes = tokio::fs::read(args.path.as_ref()).await .map_err(|err| StorytellerError::Client(ClientError::from(err)))?; let file_name = args.path.as_ref().file_name() .and_then(|n| n.to_str()).unwrap_or("file").to_string(); diff --git a/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/upload_image_media_file_from_file.rs b/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/upload_image_media_file_from_file.rs index 70105963e9..39c9a6358f 100644 --- a/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/upload_image_media_file_from_file.rs +++ b/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/upload_image_media_file_from_file.rs @@ -69,7 +69,7 @@ pub async fn upload_image_media_file_from_file_with_idempotency_token>( let client = storyteller_client_builder(api_host) .build()?; - let file_bytes = std::fs::read(path.as_ref())?; + let file_bytes = tokio::fs::read(path.as_ref()).await?; let file_name = path.as_ref().file_name() .and_then(|n| n.to_str()).unwrap_or("file").to_string(); let mut form = Form::new() diff --git a/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/upload_video_media_file_from_file.rs b/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/upload_video_media_file_from_file.rs index 332a5464aa..d0864b126a 100644 --- a/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/upload_video_media_file_from_file.rs +++ b/crates/api_clients/artcraft/artcraft_client/src/endpoints/media_files/upload_video_media_file_from_file.rs @@ -61,7 +61,7 @@ pub async fn upload_video_media_file_from_file>( let client = storyteller_client_builder(args.api_host) .build()?; - let file_bytes = std::fs::read(args.path.as_ref())?; + let file_bytes = tokio::fs::read(args.path.as_ref()).await?; let file_name = args.path.as_ref().file_name() .and_then(|n| n.to_str()).unwrap_or("file").to_string(); let mut form = Form::new() diff --git a/crates/api_clients/artcraft/artcraft_client/src/recipes/download_media_file.rs b/crates/api_clients/artcraft/artcraft_client/src/recipes/download_media_file.rs index a4eb3903b6..8c42250b13 100644 --- a/crates/api_clients/artcraft/artcraft_client/src/recipes/download_media_file.rs +++ b/crates/api_clients/artcraft/artcraft_client/src/recipes/download_media_file.rs @@ -1,5 +1,3 @@ -use std::fs; -use std::io::Write; use std::path::{Path, PathBuf}; use log::{info, warn}; @@ -68,13 +66,7 @@ pub async fn download_media_file>( let bytes = download_bytes(cdn_url).await?; // 4. Write to disk. - let mut file = fs::File::create(&output_path) - .map_err(|err| StorytellerError::Client(ClientError::IoError(err)))?; - - file.write_all(&bytes) - .map_err(|err| StorytellerError::Client(ClientError::IoError(err)))?; - - file.flush() + tokio::fs::write(&output_path, &bytes).await .map_err(|err| StorytellerError::Client(ClientError::IoError(err)))?; info!("Downloaded {} bytes to {:?}", bytes.len(), output_path); diff --git a/crates/api_clients/artcraft/artcraft_router/Cargo.toml b/crates/api_clients/artcraft/artcraft_router/Cargo.toml index 3fd929faee..8edabf415c 100644 --- a/crates/api_clients/artcraft/artcraft_router/Cargo.toml +++ b/crates/api_clients/artcraft/artcraft_router/Cargo.toml @@ -31,7 +31,7 @@ reqwest.workspace = true serde.workspace = true wreq.workspace = true serde_derive.workspace = true -tokio.workspace = true +tokio = { workspace = true, features = ["fs"] } uuid.workspace = true [dev-dependencies] diff --git a/crates/api_clients/artcraft/artcraft_router/src/generate/generate_video/providers/kinovi/upload.rs b/crates/api_clients/artcraft/artcraft_router/src/generate/generate_video/providers/kinovi/upload.rs index ae878a16a3..1900d0465b 100644 --- a/crates/api_clients/artcraft/artcraft_router/src/generate/generate_video/providers/kinovi/upload.rs +++ b/crates/api_clients/artcraft/artcraft_router/src/generate/generate_video/providers/kinovi/upload.rs @@ -24,7 +24,7 @@ pub(crate) async fn upload_to_kinovi_web( .unwrap_or_else(|| "jpg".to_string()); let file_bytes = match maybe_local_path { - Some(local_path) => match std::fs::read(local_path) { + Some(local_path) => match tokio::fs::read(local_path).await { Ok(bytes) => { info!("Reusing predownloaded file for kinovi upload: {}", source_url); bytes diff --git a/crates/api_clients/midjourney_client/src/credentials/credential_manager.rs b/crates/api_clients/midjourney_client/src/credentials/credential_manager.rs index 2909961236..fb9472a468 100644 --- a/crates/api_clients/midjourney_client/src/credentials/credential_manager.rs +++ b/crates/api_clients/midjourney_client/src/credentials/credential_manager.rs @@ -93,7 +93,7 @@ impl MidjourneyCredentialManager { let _guard = self.mutation.lock().await; // Remove every format, so a later startup cannot migrate a logged-out account. for path in self.legacy_paths.iter().chain([&self.credential_path]) { - match std::fs::remove_file(path) { + match tokio::fs::remove_file(path).await { Ok(()) => {}, Err(err) if err.kind() == std::io::ErrorKind::NotFound => {}, Err(err) => return Err(err.into()), diff --git a/crates/api_clients/openai_sora_client/src/requests/deprecated/job_status/sora_job_status.rs b/crates/api_clients/openai_sora_client/src/requests/deprecated/job_status/sora_job_status.rs index fce3287c0c..5338d98de0 100644 --- a/crates/api_clients/openai_sora_client/src/requests/deprecated/job_status/sora_job_status.rs +++ b/crates/api_clients/openai_sora_client/src/requests/deprecated/job_status/sora_job_status.rs @@ -11,7 +11,7 @@ use errors::AnyhowResult; use log::{debug, error, warn}; use serde_derive::{Deserialize, Serialize}; use std::fmt::{Debug, Display}; -use std::{fs::File, io::Write, path::Path}; +use std::path::Path; use url::Url; use wreq::Client; @@ -271,9 +271,7 @@ pub async fn get_image_gen_status(status_request: &StatusRequest, credentials: & pub async fn save_generations_to_dir(generations: &[Generation], dir: &str) -> AnyhowResult<()> { let dir = Path::new(dir); - if !dir.exists() { - std::fs::create_dir_all(dir)?; - } + tokio::fs::create_dir_all(dir).await?; for generation in generations { let response = wreq::get(generation.url.clone()).send().await?; let image_bytes = response.bytes().await?; @@ -282,15 +280,13 @@ pub async fn save_generations_to_dir(generations: &[Generation], dir: &str) -> A let ext = url.path().split(".").last().unwrap_or("png"); let path = Path::new(dir).join(format!("{}.{}", generation.id, ext)); - let mut file = File::create(path)?; - file.write_all(&image_bytes)?; + tokio::fs::write(path, &image_bytes).await?; let thumbnail_url = generation.encodings.thumbnail.path.clone(); let thumbnail_response = wreq::get(thumbnail_url).send().await?; let thumbnail_bytes = thumbnail_response.bytes().await?; let thumbnail_path = Path::new(dir).join(format!("{}_thumbnail.{}", generation.id, ext)); - let mut thumbnail_file = File::create(thumbnail_path)?; - thumbnail_file.write_all(&thumbnail_bytes)?; + tokio::fs::write(thumbnail_path, &thumbnail_bytes).await?; } Ok(())