1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*
This file is part of jellything (https://codeberg.org/metamuffin/jellything)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
use crate::{user::NodeUserData, Node};
#[cfg(feature = "rocket")]
use rocket::{FromForm, FromFormField, UriDisplayQuery};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
type NodesWithUdata = Vec<(Arc<Node>, NodeUserData)>;
#[derive(Serialize, Deserialize)]
pub struct ApiNodeResponse {
pub parents: NodesWithUdata,
pub children: NodesWithUdata,
pub node: Arc<Node>,
pub userdata: NodeUserData,
}
#[derive(Serialize, Deserialize)]
pub struct ApiSearchResponse {
pub count: usize,
pub results: NodesWithUdata,
}
#[derive(Serialize, Deserialize)]
pub struct ApiItemsResponse {
pub count: usize,
pub pages: usize,
pub items: NodesWithUdata,
}
#[derive(Serialize, Deserialize)]
pub struct ApiHomeResponse {
pub toplevel: NodesWithUdata,
pub categories: Vec<(String, NodesWithUdata)>,
}
#[derive(Debug, Default, Clone)]
#[cfg_attr(feature = "rocket", derive(FromForm, UriDisplayQuery))]
pub struct NodeFilterSort {
pub sort_by: Option<SortProperty>,
pub filter_kind: Option<Vec<FilterProperty>>,
pub sort_order: Option<SortOrder>,
}
#[rustfmt::skip]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))]
pub enum SortOrder {
#[field(value = "ascending")] Ascending,
#[field(value = "descending")] Descending,
}
macro_rules! form_enum {
(enum $i:ident { $($vi:ident = $vk:literal),*, }) => {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))]
pub enum $i { $(#[cfg_attr(feature = "rocket", field(value = $vk))] $vi),* }
impl $i { #[allow(unused)] const ALL: &'static [$i] = &[$($i::$vi),*]; }
};
}
form_enum!(
enum FilterProperty {
FederationLocal = "fed_local",
FederationRemote = "fed_remote",
Watched = "watched",
Unwatched = "unwatched",
WatchProgress = "watch_progress",
KindMovie = "kind_movie",
KindVideo = "kind_video",
KindShortFormVideo = "kind_short_form_video",
KindMusic = "kind_music",
KindCollection = "kind_collection",
KindChannel = "kind_channel",
KindShow = "kind_show",
KindSeries = "kind_series",
KindSeason = "kind_season",
KindEpisode = "kind_episode",
}
);
form_enum!(
enum SortProperty {
ReleaseDate = "release_date",
Title = "title",
Index = "index",
Duration = "duration",
RatingRottenTomatoes = "rating_rt",
RatingMetacritic = "rating_mc",
RatingImdb = "rating_imdb",
RatingTmdb = "rating_tmdb",
RatingYoutubeViews = "rating_yt_views",
RatingYoutubeLikes = "rating_yt_likes",
RatingYoutubeFollowers = "rating_yt_followers",
RatingUser = "rating_user",
RatingLikesDivViews = "rating_loved",
}
);
|