From 8551bf2e34d9543fa41a83fae785ed81d6a6c10f Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 6 Aug 2023 12:52:42 +0200 Subject: move shared server code to own crate --- server/src/import.rs | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'server/src/import.rs') diff --git a/server/src/import.rs b/server/src/import.rs index 9ffab48..48bdcdc 100644 --- a/server/src/import.rs +++ b/server/src/import.rs @@ -6,14 +6,12 @@ use crate::{database::Database, federation::Federation, CONF}; use anyhow::{anyhow, bail, Context, Ok}; use async_recursion::async_recursion; -use base64::Engine; use futures::{stream::FuturesUnordered, StreamExt}; +use jellybase::cache_file; use jellyclient::Session; use jellycommon::{AssetLocation, MediaSource, Node, NodePrivate, RemoteImportOptions}; use log::{debug, error, info}; -use std::{ - ffi::OsStr, fs::File, os::unix::prelude::OsStrExt, path::PathBuf, str::FromStr, sync::LazyLock, -}; +use std::{ffi::OsStr, fs::File, os::unix::prelude::OsStrExt, path::PathBuf, sync::LazyLock}; use tokio::sync::Semaphore; static IMPORT_SEM: LazyLock = LazyLock::new(|| Semaphore::new(1)); @@ -194,24 +192,3 @@ async fn cache_federation_asset( } Ok(poster) } - -fn cache_file(seed: &[&str]) -> (PathBuf, Option) { - use sha2::Digest; - let mut d = sha2::Sha512::new(); - for s in seed { - d.update(s.as_bytes()); - d.update(b"\0"); - } - let d = d.finalize(); - let fname = base64::engine::general_purpose::URL_SAFE.encode(d); - let fname = &fname[..22]; // about 128 bits - let fullpath = CONF.cache_path.join(fname); - let cachepath = PathBuf::from_str(fname).unwrap(); - - let f = if !fullpath.exists() { - Some(File::create(&fullpath).unwrap()) - } else { - None - }; - (cachepath, f) -} -- cgit v1.2.3-70-g09d2