diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -1,5 +1,9 @@ +#![feature(async_closure)] + use config::Config; use db::Database; +use error::Error; +use tokio::{fs::File, io::AsyncWriteExt}; mod artist; mod artwork; @@ -25,6 +29,20 @@ impl Critch { Self { db, config } } + + pub async fn save_file(&self, file_name: &str, file_data: Vec<u8>) -> Result<()> { + let upload_dir = self.config.files_dir(); + if upload_dir.is_dir() { + let file_handle = upload_dir.join(file_name); + let mut file = File::create(file_handle).await?; + file.write_all(&file_data).await?; + return Ok(()); + } else { + return Err(Error::UploadDirectory( + self.config.files_dir().to_string_lossy().to_string(), + )); + } + } } include!(concat!(env!("OUT_DIR"), "/templates.rs")); |