aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-05-31 14:37:07 +0200
committermetamuffin <metamuffin@disroot.org>2025-05-31 14:37:07 +0200
commit31cce6db5373ee99ef4c4c17ddf27b81040017eb (patch)
tree854be97a7c5c1e06def80136e44b12203f902f29 /server
parent72a8d6c8cff8869019c3ce0cb1a38f806d964604 (diff)
downloadjellything-31cce6db5373ee99ef4c4c17ddf27b81040017eb.tar
jellything-31cce6db5373ee99ef4c4c17ddf27b81040017eb.tar.bz2
jellything-31cce6db5373ee99ef4c4c17ddf27b81040017eb.tar.zst
Fix nodefiltersort fromform instance very badly
Diffstat (limited to 'server')
-rw-r--r--server/src/helper/filter_sort.rs136
-rw-r--r--server/src/ui/items.rs10
-rw-r--r--server/src/ui/node.rs9
3 files changed, 136 insertions, 19 deletions
diff --git a/server/src/helper/filter_sort.rs b/server/src/helper/filter_sort.rs
index b30ff18..10d397a 100644
--- a/server/src/helper/filter_sort.rs
+++ b/server/src/helper/filter_sort.rs
@@ -6,22 +6,59 @@
use super::A;
use jellycommon::{
- api::NodeFilterSort,
+ api::{FilterProperty, NodeFilterSort, SortOrder, SortProperty},
user::{PlayerKind, Theme},
};
use rocket::{
async_trait,
- form::{DataField, FromFormField, Result, ValueField},
+ form::{DataField, FromForm, FromFormField, Result, ValueField},
+ UriDisplayQuery,
};
-#[async_trait]
-impl<'v> FromFormField<'v> for A<NodeFilterSort> {
- fn from_value(field: ValueField<'v>) -> Result<'v, Self> {
- // TODO
- Ok(A(NodeFilterSort::default()))
- }
- async fn from_data(field: DataField<'v, '_>) -> Result<'v, Self> {
- Ok(A(NodeFilterSort::default()))
+impl Into<NodeFilterSort> for ANodeFilterSort {
+ fn into(self) -> NodeFilterSort {
+ NodeFilterSort {
+ sort_by: self.sort_by.map(|e| match e {
+ ASortProperty::ReleaseDate => SortProperty::ReleaseDate,
+ ASortProperty::Title => SortProperty::Title,
+ ASortProperty::Index => SortProperty::Index,
+ ASortProperty::Duration => SortProperty::Duration,
+ ASortProperty::RatingRottenTomatoes => SortProperty::RatingRottenTomatoes,
+ ASortProperty::RatingMetacritic => SortProperty::RatingMetacritic,
+ ASortProperty::RatingImdb => SortProperty::RatingImdb,
+ ASortProperty::RatingTmdb => SortProperty::RatingTmdb,
+ ASortProperty::RatingYoutubeViews => SortProperty::RatingYoutubeViews,
+ ASortProperty::RatingYoutubeLikes => SortProperty::RatingYoutubeLikes,
+ ASortProperty::RatingYoutubeFollowers => SortProperty::RatingYoutubeFollowers,
+ ASortProperty::RatingUser => SortProperty::RatingUser,
+ ASortProperty::RatingLikesDivViews => SortProperty::RatingLikesDivViews,
+ }),
+ filter_kind: self.filter_kind.map(|l| {
+ l.into_iter()
+ .map(|e| match e {
+ AFilterProperty::FederationLocal => FilterProperty::FederationLocal,
+ AFilterProperty::FederationRemote => FilterProperty::FederationRemote,
+ AFilterProperty::Watched => FilterProperty::Watched,
+ AFilterProperty::Unwatched => FilterProperty::Unwatched,
+ AFilterProperty::WatchProgress => FilterProperty::WatchProgress,
+ AFilterProperty::KindMovie => FilterProperty::KindMovie,
+ AFilterProperty::KindVideo => FilterProperty::KindVideo,
+ AFilterProperty::KindShortFormVideo => FilterProperty::KindShortFormVideo,
+ AFilterProperty::KindMusic => FilterProperty::KindMusic,
+ AFilterProperty::KindCollection => FilterProperty::KindCollection,
+ AFilterProperty::KindChannel => FilterProperty::KindChannel,
+ AFilterProperty::KindShow => FilterProperty::KindShow,
+ AFilterProperty::KindSeries => FilterProperty::KindSeries,
+ AFilterProperty::KindSeason => FilterProperty::KindSeason,
+ AFilterProperty::KindEpisode => FilterProperty::KindEpisode,
+ })
+ .collect()
+ }),
+ sort_order: self.sort_order.map(|e| match e {
+ ASortOrder::Ascending => SortOrder::Ascending,
+ ASortOrder::Descending => SortOrder::Descending,
+ }),
+ }
}
}
@@ -44,3 +81,82 @@ impl<'v> FromFormField<'v> for A<PlayerKind> {
Err(field.unexpected())?
}
}
+
+#[derive(FromForm, UriDisplayQuery, Clone)]
+pub struct ANodeFilterSort {
+ sort_by: Option<ASortProperty>,
+ filter_kind: Option<Vec<AFilterProperty>>,
+ sort_order: Option<ASortOrder>,
+}
+
+#[derive(FromFormField, UriDisplayQuery, Clone)]
+enum AFilterProperty {
+ #[field(value = "fed_local")]
+ FederationLocal,
+ #[field(value = "fed_remote")]
+ FederationRemote,
+ #[field(value = "watched")]
+ Watched,
+ #[field(value = "unwatched")]
+ Unwatched,
+ #[field(value = "watch_progress")]
+ WatchProgress,
+ #[field(value = "kind_movie")]
+ KindMovie,
+ #[field(value = "kind_video")]
+ KindVideo,
+ #[field(value = "kind_short_form_video")]
+ KindShortFormVideo,
+ #[field(value = "kind_music")]
+ KindMusic,
+ #[field(value = "kind_collection")]
+ KindCollection,
+ #[field(value = "kind_channel")]
+ KindChannel,
+ #[field(value = "kind_show")]
+ KindShow,
+ #[field(value = "kind_series")]
+ KindSeries,
+ #[field(value = "kind_season")]
+ KindSeason,
+ #[field(value = "kind_episode")]
+ KindEpisode,
+}
+
+#[derive(FromFormField, UriDisplayQuery, Clone)]
+enum ASortProperty {
+ #[field(value = "release_date")]
+ ReleaseDate,
+ #[field(value = "title")]
+ Title,
+ #[field(value = "index")]
+ Index,
+ #[field(value = "duration")]
+ Duration,
+ #[field(value = "rating_rt")]
+ RatingRottenTomatoes,
+ #[field(value = "rating_mc")]
+ RatingMetacritic,
+ #[field(value = "rating_imdb")]
+ RatingImdb,
+ #[field(value = "rating_tmdb")]
+ RatingTmdb,
+ #[field(value = "rating_yt_views")]
+ RatingYoutubeViews,
+ #[field(value = "rating_yt_likes")]
+ RatingYoutubeLikes,
+ #[field(value = "rating_yt_followers")]
+ RatingYoutubeFollowers,
+ #[field(value = "rating_user")]
+ RatingUser,
+ #[field(value = "rating_loved")]
+ RatingLikesDivViews,
+}
+
+#[derive(FromFormField, UriDisplayQuery, Clone)]
+enum ASortOrder {
+ #[field(value = "ascending")]
+ Ascending,
+ #[field(value = "descending")]
+ Descending,
+}
diff --git a/server/src/ui/items.rs b/server/src/ui/items.rs
index 915963c..ace948f 100644
--- a/server/src/ui/items.rs
+++ b/server/src/ui/items.rs
@@ -4,8 +4,8 @@
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
use super::error::MyError;
-use crate::helper::{accept::Accept, RequestInfo, A};
-use jellycommon::api::{ApiItemsResponse, NodeFilterSort};
+use crate::helper::{accept::Accept, filter_sort::ANodeFilterSort, RequestInfo};
+use jellycommon::api::ApiItemsResponse;
use jellylogic::items::all_items;
use jellyui::{items::ItemsPage, render_page};
use rocket::{get, response::content::RawHtml, serde::json::Json, Either};
@@ -14,9 +14,9 @@ use rocket::{get, response::content::RawHtml, serde::json::Json, Either};
pub fn r_items(
ri: RequestInfo,
page: Option<usize>,
- filter: A<NodeFilterSort>,
+ filter: ANodeFilterSort,
) -> Result<Either<RawHtml<String>, Json<ApiItemsResponse>>, MyError> {
- let r = all_items(&ri.session, page, filter.0.clone())?;
+ let r = all_items(&ri.session, page, filter.clone().into())?;
Ok(if matches!(ri.accept, Accept::Json) {
Either::Right(Json(r))
} else {
@@ -24,7 +24,7 @@ pub fn r_items(
&ItemsPage {
lang: &ri.lang,
r,
- filter: &filter.0,
+ filter: &filter.clone().into(),
page: page.unwrap_or(0),
},
ri.render_info(),
diff --git a/server/src/ui/node.rs b/server/src/ui/node.rs
index 7085a5a..5004b7b 100644
--- a/server/src/ui/node.rs
+++ b/server/src/ui/node.rs
@@ -4,7 +4,7 @@
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
use super::error::MyResult;
-use crate::helper::{RequestInfo, A};
+use crate::helper::{filter_sort::ANodeFilterSort, RequestInfo, A};
use jellycommon::{
api::{ApiNodeResponse, NodeFilterSort},
NodeID,
@@ -17,10 +17,11 @@ use rocket::{get, response::content::RawHtml, serde::json::Json, Either};
pub async fn r_node<'a>(
ri: RequestInfo,
id: A<NodeID>,
- filter: Option<A<NodeFilterSort>>,
+ filter: Option<ANodeFilterSort>,
parents: bool,
children: bool,
) -> MyResult<Either<RawHtml<String>, Json<ApiNodeResponse>>> {
+ let filter: Option<NodeFilterSort> = filter.map(Into::into);
let filter = filter.unwrap_or_default();
let r = get_node(
@@ -28,7 +29,7 @@ pub async fn r_node<'a>(
id.0,
!ri.accept.is_json() || children,
!ri.accept.is_json() || parents,
- filter.0.clone(),
+ filter.clone(),
)?;
Ok(if ri.accept.is_json() {
@@ -41,7 +42,7 @@ pub async fn r_node<'a>(
children: &r.children,
parents: &r.parents,
similar: &[],
- filter: &filter.0,
+ filter: &filter,
lang: &ri.lang,
player: false,
},