diff options
author | 2024-11-14 21:43:54 +0000 | |
---|---|---|
committer | 2024-11-14 21:43:54 +0000 | |
commit | 67b54449a1bbde257e9454419e7bb70ebc515c0f (patch) | |
tree | e23710c2d1f5d219205f26af727b478e455a0071 /src/lib.rs | |
parent | 469a3ad33914f7eff6edc9ca7fabb12f2950da84 (diff) | |
download | critch-67b54449a1bbde257e9454419e7bb70ebc515c0f.tar.gz critch-67b54449a1bbde257e9454419e7bb70ebc515c0f.tar.bz2 critch-67b54449a1bbde257e9454419e7bb70ebc515c0f.zip |
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")); |