diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/Cargo.toml | 3 | ||||
-rw-r--r-- | server/src/import.rs | 39 | ||||
-rw-r--r-- | server/src/routes/ui/assets.rs | 7 | ||||
-rw-r--r-- | server/src/routes/ui/layout.rs | 2 |
4 files changed, 28 insertions, 23 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml index 291f56b..fbb9f63 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -25,10 +25,9 @@ vte = "0.12.0" argon2 = "0.5.2" aes-gcm-siv = "0.11.1" -async-std = "1.12.0" async-recursion = "1.0.5" futures = "0.3.28" -tokio = { version = "1.32.0", features = ["io-util"] } +tokio = { workspace = true } tokio-util = { version = "0.7.9", features = ["io", "io-util"] } markup = "0.13.1" diff --git a/server/src/import.rs b/server/src/import.rs index 7e62b47..8d8198a 100644 --- a/server/src/import.rs +++ b/server/src/import.rs @@ -7,11 +7,17 @@ use crate::{database::Database, federation::Federation, CONF}; use anyhow::{anyhow, bail, Context, Ok}; use async_recursion::async_recursion; use futures::{stream::FuturesUnordered, StreamExt, TryFutureExt}; -use jellybase::{cache_file, AssetLocationExt}; +use jellybase::async_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, sync::LazyLock}; +use std::{ + ffi::OsStr, + fs::File, + os::unix::prelude::OsStrExt, + path::PathBuf, + sync::{Arc, LazyLock}, +}; use tokio::sync::Semaphore; static IMPORT_SEM: LazyLock<Semaphore> = LazyLock::new(|| Semaphore::new(1)); @@ -133,7 +139,7 @@ static SEM_REMOTE_IMPORT: LazyLock<Semaphore> = LazyLock::new(|| Semaphore::new( async fn import_remote( mut opts: RemoteImportOptions, db: &Database, - session: &Session, + session: &Arc<Session>, identifier: String, parent: Option<String>, ) -> anyhow::Result<Vec<String>> { @@ -149,11 +155,11 @@ async fn import_remote( .context("fetching remote node")?; if node.federated.is_some() { - return Ok(vec![]) // node is federated, lets not import it + return Ok(vec![]); // node is federated, lets not import it } - let poster = cache_federation_asset(session, &opts.id, "poster").await?; - let backdrop = cache_federation_asset(session, &opts.id, "backdrop").await?; + let poster = cache_federation_asset(session.to_owned(), opts.id.clone(), "poster").await?; + let backdrop = cache_federation_asset(session.to_owned(), opts.id.clone(), "backdrop").await?; drop(_permit); @@ -215,15 +221,16 @@ async fn import_remote( } async fn cache_federation_asset( - session: &Session, - identifier: &String, - role: &str, + session: Arc<Session>, + identifier: String, + role: &'static str, ) -> anyhow::Result<AssetLocation> { - let poster = cache_file(&["federation-asset", role, identifier]); - if !poster.path().exists() { - session - .node_asset(&identifier, role, File::create(&poster.path())?) - .await?; - } - Ok(poster) + async_cache_file( + &["federation-asset", role, &identifier.clone()], + move |out| async move { + let session = session; + session.node_asset(identifier.as_str(), role, out).await + }, + ) + .await } diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs index 992e3da..8c0496e 100644 --- a/server/src/routes/ui/assets.rs +++ b/server/src/routes/ui/assets.rs @@ -8,7 +8,7 @@ use crate::{ routes::ui::{account::session::Session, error::MyError, CacheControlFile}, }; use anyhow::anyhow; -use async_std::task::spawn_blocking; +use jellybase::AssetLocationExt; use jellycommon::AssetLocation; use log::info; use rocket::{get, http::ContentType, FromFormField, State, UriDisplayQuery}; @@ -53,11 +53,10 @@ pub async fn r_item_assets( )); // fit the resolution into a finite set so the maximum cache is finite too. let width = 2usize.pow(width.unwrap_or(2048).clamp(128, 8196).ilog2()); - let path = - spawn_blocking(move || jellytranscoder::image::transcode(asset, 50., 5, width)).await?; + let path = jellytranscoder::image::transcode(asset, 50., 5, width).await?; info!("loading asset from {path:?}"); Ok(( ContentType::AVIF, - CacheControlFile::new(File::open(path).await?).await, + CacheControlFile::new(File::open(path.path()).await?).await, )) } diff --git a/server/src/routes/ui/layout.rs b/server/src/routes/ui/layout.rs index fdda3e4..1c47247 100644 --- a/server/src/routes/ui/layout.rs +++ b/server/src/routes/ui/layout.rs @@ -16,7 +16,7 @@ use crate::{ }, uri, }; -use async_std::task::block_on; +use futures::executor::block_on; use jellybase::CONF; use markup::{DynRender, Render}; use rocket::{ |