aboutsummaryrefslogtreecommitdiff
path: root/base/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-08-06 13:52:09 +0200
committermetamuffin <metamuffin@disroot.org>2023-08-06 13:52:09 +0200
commitc3c4734beb7b9650936b3c74df21d72a597cd94c (patch)
tree3728d62a70cfc65231beac41ae62f0da4d971308 /base/src/lib.rs
parent8551bf2e34d9543fa41a83fae785ed81d6a6c10f (diff)
downloadjellything-c3c4734beb7b9650936b3c74df21d72a597cd94c.tar
jellything-c3c4734beb7b9650936b3c74df21d72a597cd94c.tar.bz2
jellything-c3c4734beb7b9650936b3c74df21d72a597cd94c.tar.zst
transcode images
Diffstat (limited to 'base/src/lib.rs')
-rw-r--r--base/src/lib.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/base/src/lib.rs b/base/src/lib.rs
index 62f93e7..df80036 100644
--- a/base/src/lib.rs
+++ b/base/src/lib.rs
@@ -5,8 +5,8 @@
*/
#![feature(lazy_cell)]
use base64::Engine;
-use jellycommon::config::GlobalConfig;
-use std::{fs::File, path::PathBuf, str::FromStr, sync::LazyLock};
+use jellycommon::{config::GlobalConfig, AssetLocation};
+use std::{fs::File, path::PathBuf, sync::LazyLock};
pub static CONF: LazyLock<GlobalConfig> = LazyLock::new(|| {
serde_json::from_reader(
@@ -20,7 +20,7 @@ pub static CONF: LazyLock<GlobalConfig> = LazyLock::new(|| {
.unwrap()
});
-pub fn cache_file(seed: &[&str]) -> (PathBuf, Option<File>) {
+pub fn cache_file(seed: &[&str]) -> PathBuf {
use sha2::Digest;
let mut d = sha2::Sha512::new();
for s in seed {
@@ -30,13 +30,19 @@ pub fn cache_file(seed: &[&str]) -> (PathBuf, Option<File>) {
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 path = CONF.cache_path.join(fname);
+ path
+}
- let f = if !fullpath.exists() {
- Some(File::create(&fullpath).unwrap())
- } else {
- None
- };
- (cachepath, f)
+pub trait AssetLocationExt {
+ fn path(&self) -> PathBuf;
+}
+impl AssetLocationExt for AssetLocation {
+ fn path(&self) -> PathBuf {
+ match self {
+ AssetLocation::Assets(p) => CONF.asset_path.join(p),
+ AssetLocation::Cache(p) => CONF.cache_path.join(p),
+ AssetLocation::Library(p) => CONF.library_path.join(p),
+ }
+ }
}