aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/import.rs14
-rw-r--r--server/src/routes/api/mod.rs19
-rw-r--r--server/src/routes/mod.rs3
3 files changed, 26 insertions, 10 deletions
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,
],
)
}