aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/src/lib.rs7
-rw-r--r--common/src/impl.rs11
-rw-r--r--common/src/lib.rs8
-rw-r--r--server/src/import.rs12
-rw-r--r--server/src/routes/ui/assets.rs11
5 files changed, 31 insertions, 18 deletions
diff --git a/client/src/lib.rs b/client/src/lib.rs
index b80f705..96349ed 100644
--- a/client/src/lib.rs
+++ b/client/src/lib.rs
@@ -93,7 +93,7 @@ impl Session {
pub async fn node_asset(
&self,
id: &str,
- role: &str,
+ role: AssetRole,
width: usize,
mut writer: impl tokio::io::AsyncWrite + std::marker::Unpin,
) -> Result<()> {
@@ -101,8 +101,9 @@ impl Session {
let mut r = self
.client
.get(format!(
- "{}/n/{id}/asset?role={role}&width={width}",
- self.instance.base()
+ "{}/n/{id}/asset?role={}&width={width}",
+ self.instance.base(),
+ role.as_str()
))
.send()
.await?;
diff --git a/common/src/impl.rs b/common/src/impl.rs
index 55364ab..ff2ce22 100644
--- a/common/src/impl.rs
+++ b/common/src/impl.rs
@@ -3,7 +3,7 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
-use crate::{SourceTrack, SourceTrackKind};
+use crate::{AssetRole, SourceTrack, SourceTrackKind};
impl SourceTrackKind {
pub fn letter(&self) -> char {
@@ -15,6 +15,15 @@ impl SourceTrackKind {
}
}
+impl AssetRole {
+ pub fn as_str(&self) -> &'static str {
+ match self {
+ AssetRole::Poster => "poster",
+ AssetRole::Backdrop => "backdrop",
+ }
+ }
+}
+
impl std::fmt::Display for SourceTrack {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let kspec = match &self.kind {
diff --git a/common/src/lib.rs b/common/src/lib.rs
index 8292e87..1a08750 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -147,3 +147,11 @@ pub enum SourceTrackKind {
},
Subtitles,
}
+
+#[rustfmt::skip]
+#[derive(Debug, Clone, Copy)]
+#[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))]
+pub enum AssetRole {
+ #[cfg_attr(feature = "rocket", field(value = "poster"))] Poster,
+ #[cfg_attr(feature = "rocket", field(value = "backdrop"))] Backdrop,
+}
diff --git a/server/src/import.rs b/server/src/import.rs
index 55d1a32..dc32fbf 100644
--- a/server/src/import.rs
+++ b/server/src/import.rs
@@ -9,7 +9,7 @@ use async_recursion::async_recursion;
use futures::{stream::FuturesUnordered, StreamExt, TryFutureExt};
use jellybase::cache::async_cache_file;
use jellyclient::Session;
-use jellycommon::{AssetLocation, MediaSource, Node, NodePrivate, RemoteImportOptions};
+use jellycommon::{AssetLocation, AssetRole, MediaSource, Node, NodePrivate, RemoteImportOptions};
use log::{debug, error, info};
use std::{
ffi::OsStr,
@@ -167,8 +167,10 @@ async fn import_remote(
return Ok(vec![]); // node is federated from us, lets not import it
}
- 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?;
+ let poster =
+ cache_federation_asset(session.to_owned(), opts.id.clone(), AssetRole::Poster).await?;
+ let backdrop =
+ cache_federation_asset(session.to_owned(), opts.id.clone(), AssetRole::Backdrop).await?;
drop(_permit);
@@ -237,10 +239,10 @@ async fn import_remote(
async fn cache_federation_asset(
session: Arc<Session>,
identifier: String,
- role: &'static str,
+ role: AssetRole,
) -> anyhow::Result<AssetLocation> {
async_cache_file(
- &["federation-asset", role, &identifier.clone()],
+ &["federation-asset", role.as_str(), &identifier.clone()],
move |out| async move {
let session = session;
session
diff --git a/server/src/routes/ui/assets.rs b/server/src/routes/ui/assets.rs
index 48c569a..f00c416 100644
--- a/server/src/routes/ui/assets.rs
+++ b/server/src/routes/ui/assets.rs
@@ -10,19 +10,12 @@ use crate::{
use anyhow::{anyhow, Context};
use jellybase::{permission::NodePermissionExt, AssetLocationExt};
use jellycommon::AssetLocation;
+pub use jellycommon::AssetRole;
use log::info;
-use rocket::{get, http::ContentType, FromFormField, State, UriDisplayQuery};
+use rocket::{get, http::ContentType, State};
use std::{path::PathBuf, str::FromStr};
use tokio::fs::File;
-#[derive(FromFormField, UriDisplayQuery)]
-pub enum AssetRole {
- #[field(value = "poster")]
- Poster,
- #[field(value = "backdrop")]
- Backdrop,
-}
-
#[get("/n/<id>/asset?<role>&<width>")]
pub async fn r_item_assets(
session: Session,