diff options
author | metamuffin <metamuffin@disroot.org> | 2025-05-31 14:37:07 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-05-31 14:37:07 +0200 |
commit | 31cce6db5373ee99ef4c4c17ddf27b81040017eb (patch) | |
tree | 854be97a7c5c1e06def80136e44b12203f902f29 /server/src/helper | |
parent | 72a8d6c8cff8869019c3ce0cb1a38f806d964604 (diff) | |
download | jellything-31cce6db5373ee99ef4c4c17ddf27b81040017eb.tar jellything-31cce6db5373ee99ef4c4c17ddf27b81040017eb.tar.bz2 jellything-31cce6db5373ee99ef4c4c17ddf27b81040017eb.tar.zst |
Fix nodefiltersort fromform instance very badly
Diffstat (limited to 'server/src/helper')
-rw-r--r-- | server/src/helper/filter_sort.rs | 136 |
1 files changed, 126 insertions, 10 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, +} |