From 66049566ae865e1a4bd049257d6afc0abded16e9 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 19 Sep 2022 17:30:38 +0300 Subject: feat: indieauth support Working: - Tokens and codes - Authenticating with a password Not working: - Setting the password (need to patch onboarding) - WebAuthn (the JavaScript is too complicated) --- kittybox-rs/src/media/storage/file.rs | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) (limited to 'kittybox-rs/src/media/storage') diff --git a/kittybox-rs/src/media/storage/file.rs b/kittybox-rs/src/media/storage/file.rs index c554d9e..1e0ff0e 100644 --- a/kittybox-rs/src/media/storage/file.rs +++ b/kittybox-rs/src/media/storage/file.rs @@ -29,38 +29,16 @@ impl From for MediaStoreError { } } - impl FileStore { pub fn new>(base: T) -> Self { Self { base: base.into() } } async fn mktemp(&self) -> Result<(PathBuf, BufWriter)> { - use rand::{Rng, distributions::Alphanumeric}; - tokio::fs::create_dir_all(self.base.as_path()).await?; - loop { - let filename = self.base.join(format!("temp.{}", { - let string = rand::thread_rng() - .sample_iter(&Alphanumeric) - .take(16) - .collect::>(); - String::from_utf8(string).unwrap() - })); - - match OpenOptions::new() - .create_new(true) - .write(true) - .open(&filename) - .await - { - // TODO: determine if BufWriter provides benefit here - Ok(file) => return Ok((filename, BufWriter::with_capacity(BUF_CAPACITY, file))), - Err(err) => match err.kind() { - std::io::ErrorKind::AlreadyExists => continue, - _ => return Err(err.into()) - } - } - } + kittybox_util::fs::mktemp(&self.base, "temp", 16) + .await + .map(|(name, file)| (name, BufWriter::new(file))) + .map_err(Into::into) } } -- cgit 1.4.1