aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-09-24 22:41:56 +0200
committermetamuffin <metamuffin@disroot.org>2023-09-24 22:41:56 +0200
commit63454aa9bd9fd4ee293c316e7ca15c88e6c5ca2a (patch)
tree36f39dd872295bec05c1b83ab9a9ab24518ce9e6
parentfb16ea9caf4cd50e94d450ea210b7f1e10adabfc (diff)
downloadjellything-63454aa9bd9fd4ee293c316e7ca15c88e6c5ca2a.tar
jellything-63454aa9bd9fd4ee293c316e7ca15c88e6c5ca2a.tar.bz2
jellything-63454aa9bd9fd4ee293c316e7ca15c88e6c5ca2a.tar.zst
fix federated assets (doesnt work bc dav1d-sys)
-rw-r--r--base/src/lib.rs5
-rw-r--r--server/src/import.rs14
-rw-r--r--server/src/routes/api/mod.rs19
-rw-r--r--server/src/routes/mod.rs3
-rw-r--r--transcoder/Cargo.toml1
-rw-r--r--transcoder/src/image.rs3
6 files changed, 31 insertions, 14 deletions
diff --git a/base/src/lib.rs b/base/src/lib.rs
index df80036..46ab576 100644
--- a/base/src/lib.rs
+++ b/base/src/lib.rs
@@ -20,7 +20,7 @@ pub static CONF: LazyLock<GlobalConfig> = LazyLock::new(|| {
.unwrap()
});
-pub fn cache_file(seed: &[&str]) -> PathBuf {
+pub fn cache_file(seed: &[&str]) -> AssetLocation {
use sha2::Digest;
let mut d = sha2::Sha512::new();
for s in seed {
@@ -30,8 +30,7 @@ pub fn cache_file(seed: &[&str]) -> PathBuf {
let d = d.finalize();
let fname = base64::engine::general_purpose::URL_SAFE.encode(d);
let fname = &fname[..22]; // about 128 bits
- let path = CONF.cache_path.join(fname);
- path
+ AssetLocation::Cache(fname.into())
}
pub trait AssetLocationExt {
diff --git a/server/src/import.rs b/server/src/import.rs
index 6e422cd..8859873 100644
--- a/server/src/import.rs
+++ b/server/src/import.rs
@@ -7,7 +7,7 @@ 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;
+use jellybase::{cache_file, AssetLocationExt};
use jellyclient::Session;
use jellycommon::{AssetLocation, MediaSource, Node, NodePrivate, RemoteImportOptions};
use log::{debug, error, info};
@@ -139,7 +139,7 @@ async fn import_remote(
) -> anyhow::Result<Vec<String>> {
let _permit = SEM_REMOTE_IMPORT.acquire().await.unwrap();
info!("loading federated node {identifier:?}");
-
+
let flatten = opts.flatten;
opts.flatten = false;
@@ -159,8 +159,8 @@ async fn import_remote(
let mut node = Node {
public: node.clone(),
private: NodePrivate {
- backdrop: Some(AssetLocation::Cache(backdrop)),
- poster: Some(AssetLocation::Cache(poster)),
+ backdrop: Some(backdrop),
+ poster: Some(poster),
import: None,
id: None,
source: Some(MediaSource::Remote {
@@ -214,11 +214,11 @@ async fn cache_federation_asset(
session: &Session,
identifier: &String,
role: &str,
-) -> anyhow::Result<PathBuf> {
+) -> anyhow::Result<AssetLocation> {
let poster = cache_file(&["federation-asset", role, identifier]);
- if !poster.exists() {
+ if !poster.path().exists() {
session
- .node_asset(&identifier, role, File::create(&poster)?)
+ .node_asset(&identifier, role, File::create(&poster.path())?)
.await?;
}
Ok(poster)
diff --git a/server/src/routes/api/mod.rs b/server/src/routes/api/mod.rs
index cc87525..23f313f 100644
--- a/server/src/routes/api/mod.rs
+++ b/server/src/routes/api/mod.rs
@@ -3,12 +3,13 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
-
use super::ui::{
- account::{login_logic, LoginForm},
+ account::{login_logic, session::AdminSession, LoginForm},
error::MyResult,
};
use crate::database::Database;
+use anyhow::{anyhow, Context};
+use jellycommon::Node;
use rocket::{
get,
http::MediaType,
@@ -38,6 +39,20 @@ pub fn r_api_account_login(database: &State<Database>, data: Json<LoginForm>) ->
Ok(json!(token))
}
+#[get("/api/node_raw/<id>")]
+pub fn r_api_node_raw(
+ _admin: AdminSession,
+ database: &State<Database>,
+ id: String,
+) -> MyResult<Json<Node>> {
+ let node = database
+ .node
+ .get(&id)
+ .context("retrieving library node")?
+ .ok_or(anyhow!("node does not exist"))?;
+ Ok(Json(node))
+}
+
pub struct AcceptJson(bool);
impl Deref for AcceptJson {
type Target = bool;
diff --git a/server/src/routes/mod.rs b/server/src/routes/mod.rs
index 6ebde33..86a55ac 100644
--- a/server/src/routes/mod.rs
+++ b/server/src/routes/mod.rs
@@ -4,7 +4,7 @@
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
use crate::{database::Database, federation::Federation, routes::ui::error::MyResult};
-use api::{r_api_account_login, r_api_root, r_api_version};
+use api::{r_api_account_login, r_api_node_raw, r_api_root, r_api_version};
use base64::Engine;
use jellybase::CONF;
use jellyremuxer::RemuxerContext;
@@ -112,6 +112,7 @@ pub fn build_rocket(
r_api_version,
r_api_account_login,
r_api_root,
+ r_api_node_raw,
],
)
}
diff --git a/transcoder/Cargo.toml b/transcoder/Cargo.toml
index 36f44af..9b533a6 100644
--- a/transcoder/Cargo.toml
+++ b/transcoder/Cargo.toml
@@ -8,6 +8,7 @@ jellycommon = { path = "../common" }
jellybase = { path = "../base" }
log = "0.4.20"
image = "0.24.7"
+# image = { version = "0.24.7", features = ["avif-decoder"] }
anyhow = "1.0.75"
rgb = "0.8.36"
rav1e = { version = "0.6.6", default-features = false, features = [
diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs
index 273d6b4..c28ef2b 100644
--- a/transcoder/src/image.rs
+++ b/transcoder/src/image.rs
@@ -18,7 +18,8 @@ pub fn transcode(
let path = cache_file(&[
original_path.as_os_str().to_str().unwrap(),
&format!("{width} {quality} {speed}"),
- ]);
+ ])
+ .path();
if !path.exists() {
info!("encoding {path:?} (speed={speed}, quality={quality}, width={width})");
let reader = image::io::Reader::new(BufReader::new(File::open(original_path)?))