diff options
author | Vika <vika@fireburn.ru> | 2022-09-19 17:30:38 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2022-09-19 17:30:38 +0300 |
commit | 66049566ae865e1a4bd049257d6afc0abded16e9 (patch) | |
tree | 6013a26fa98a149d103eb4402ca91d698ef02ac2 /kittybox-rs/src/media/storage/file.rs | |
parent | 696458657b26032e6e2a987c059fd69aaa10508d (diff) | |
download | kittybox-66049566ae865e1a4bd049257d6afc0abded16e9.tar.zst |
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)
Diffstat (limited to 'kittybox-rs/src/media/storage/file.rs')
-rw-r--r-- | kittybox-rs/src/media/storage/file.rs | 30 |
1 files changed, 4 insertions, 26 deletions
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<tokio::io::Error> for MediaStoreError { } } - impl FileStore { pub fn new<T: Into<PathBuf>>(base: T) -> Self { Self { base: base.into() } } async fn mktemp(&self) -> Result<(PathBuf, BufWriter<tokio::fs::File>)> { - 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::<Vec<u8>>(); - 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) } } |