aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/import.rs8
-rw-r--r--server/src/main.rs2
-rw-r--r--server/src/routes/ui/assets.rs24
3 files changed, 10 insertions, 24 deletions
diff --git a/server/src/import.rs b/server/src/import.rs
index 48bdcdc..ef58e09 100644
--- a/server/src/import.rs
+++ b/server/src/import.rs
@@ -186,9 +186,11 @@ async fn cache_federation_asset(
identifier: &String,
role: &str,
) -> anyhow::Result<PathBuf> {
- let (poster, download) = cache_file(&["federation-asset", role, identifier]);
- if let Some(d) = download {
- session.node_asset(&identifier, role, d).await?;
+ let poster = cache_file(&["federation-asset", role, identifier]);
+ if !poster.exists() {
+ session
+ .node_asset(&identifier, role, File::create(&poster)?)
+ .await?;
}
Ok(poster)
}
diff --git a/server/src/main.rs b/server/src/main.rs
index 73d90a4..2b8b91a 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -11,6 +11,7 @@ use federation::Federation;
use jellybase::CONF;
use jellyremuxer::RemuxerContext;
use routes::build_rocket;
+use tokio::fs::create_dir_all;
pub mod database;
pub mod federation;
@@ -29,6 +30,7 @@ fn main() {
.block_on(async_main())
}
async fn async_main() {
+ create_dir_all(&CONF.cache_path).await.unwrap();
let remuxer = RemuxerContext::new();
let database = Database::open(&CONF.database_path).unwrap();
let federation = Federation::initialize();
diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs
index 8a14133..2d175f9 100644
--- a/server/src/routes/ui/assets.rs
+++ b/server/src/routes/ui/assets.rs
@@ -8,7 +8,6 @@ use crate::{
routes::ui::{account::session::Session, error::MyError, CacheControlFile},
};
use anyhow::anyhow;
-use jellybase::CONF;
use jellycommon::AssetLocation;
use log::info;
use rocket::{get, http::ContentType, FromFormField, State, UriDisplayQuery};
@@ -29,7 +28,7 @@ pub async fn r_item_assets(
db: &State<Database>,
id: String,
role: AssetRole,
- width: Option<u32>,
+ width: Option<usize>,
) -> Result<(ContentType, CacheControlFile), MyError> {
let node = db.node.get(&id)?.ok_or(anyhow!("node does not exist"))?;
let mut asset = match role {
@@ -48,27 +47,10 @@ pub async fn r_item_assets(
let asset = asset.unwrap_or(AssetLocation::Assets(
PathBuf::from_str("fallback.jpeg").unwrap(),
));
- let path = asset.path();
+ let path = jellytranscoder::image::transcode(asset, 50., 5, width.unwrap_or(2048))?;
info!("loading asset from {path:?}");
- let ext = path
- .extension()
- .map(|e| e.to_str().unwrap())
- .unwrap_or("jpeg");
Ok((
- ContentType::from_extension(ext).unwrap(),
+ ContentType::AVIF,
CacheControlFile::new(File::open(path).await?).await,
))
}
-
-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),
- }
- }
-}