diff options
Diffstat (limited to 'common')
| -rw-r--r-- | common/object/src/registry.rs | 8 | ||||
| -rw-r--r-- | common/src/lib.rs | 25 | ||||
| -rw-r--r-- | common/src/user.rs | 136 |
3 files changed, 26 insertions, 143 deletions
diff --git a/common/object/src/registry.rs b/common/object/src/registry.rs index 39ed67a..c831b28 100644 --- a/common/object/src/registry.rs +++ b/common/object/src/registry.rs @@ -5,7 +5,6 @@ */ use crate::Tag; -use log::error; use std::{any::TypeId, collections::BTreeMap}; pub mod types { @@ -25,7 +24,10 @@ pub struct Registry { impl Registry { pub fn add(&mut self, tag: Tag, info: TagInfo) { if let Some(other) = self.tags.get(&tag) { - error!("Tag conflict: {:?} vs {:?}", info.name, other.name) + panic!( + "Conflicting names for tag {}: {:?} vs {:?}", + tag.0, info.name, other.name + ) } self.tags.insert(tag, info); } @@ -49,7 +51,7 @@ pub struct TagInfo { macro_rules! fields { ($($id:ident: $type:ty = $tag:literal $name:literal;)*) => { $(pub const $id: $crate::TypedTag<$type> = $crate::TypedTag($crate::Tag($tag), std::marker::PhantomData);)* - fn register_fields(reg: &mut $crate::Registry) { + pub(crate) fn register_fields(reg: &mut $crate::Registry) { $(reg.add($crate::Tag($tag), $crate::TagInfo { name: $name, r#type: Some(std::any::TypeId::of::<$type>()) });)* } }; diff --git a/common/src/lib.rs b/common/src/lib.rs index aa9da2c..38b0d05 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -5,6 +5,7 @@ */ #![feature(array_try_map)] pub mod routes; +pub mod user; use jellyobject::{Object, Registry, Tag, TypedTag, enums, fields}; pub use jellystream_types as stream; use std::sync::LazyLock; @@ -15,20 +16,26 @@ pub static TAGREG: LazyLock<Registry> = LazyLock::new(|| { let mut reg = Registry::default(); register_fields(&mut reg); register_enums(&mut reg); + user::register_fields(&mut reg); reg }); +#[test] +fn check_tag_conflicts() { + let _ = &*TAGREG; +} + fields! { - // Tag counter: 39 + // Tag counter: 40 NO_KIND: Tag = 1 "kind"; NO_TITLE: &str = 2 "title"; NO_PARENT: u64 = 3 "parent"; // multi - NO_SUBTITLE: &str = 37 "subtitle"; + NO_SUBTITLE: &str = 38 "subtitle"; NO_TAGLINE: &str = 4 "tagline"; NO_DESCRIPTION: &str = 5 "description"; NO_RELEASEDATE: i64 = 6 "releasedate"; - NO_DURATION: f64 = 37 "duration"; + NO_DURATION: f64 = 39 "duration"; NO_INDEX: u64 = 7 "index"; NO_SEASON_INDEX: u64 = 8 "season_index"; NO_TRACK: Object = 9 "track"; // multi @@ -68,10 +75,10 @@ fields! { LANG_NATIVE: &str = 0xa001 "native"; LANG_ENG: &str = 0xa002 "eng"; LANG_DEU: &str = 0xa003 "deu"; - LANG_JPN: &str = 0xa003 "jpn"; + LANG_JPN: &str = 0xa004 "jpn"; PICT_COVER: &str = 0xd001 "cover"; - PICT_BACKDROP: &str = 0xd001 "backdrop"; + PICT_BACKDROP: &str = 0xd002 "backdrop"; RTYP_IMDB: f64 = 0xf001 "imdb"; RTYP_TMDB: f64 = 0xf002 "tmdb"; @@ -114,10 +121,10 @@ enums! { VISI_REDUCED = 0xe002 "reduced"; VISI_VISIBLE = 0xe003 "visible"; - TRKIND_VIDEO = 0x1001 "video"; - TRKIND_AUDIO = 0x1002 "audio"; - TRKIND_TEXT = 0x1003 "text"; - TRKIND_UNKNOWN = 0x1004 "unknown"; + TRKIND_VIDEO = 0x3001 "video"; + TRKIND_AUDIO = 0x3002 "audio"; + TRKIND_TEXT = 0x3003 "text"; + TRKIND_UNKNOWN = 0x3004 "unknown"; KIND_MOVIE = 0xb001 "movie"; KIND_VIDEO = 0xb002 "video"; diff --git a/common/src/user.rs b/common/src/user.rs index 8302751..1509eb4 100644 --- a/common/src/user.rs +++ b/common/src/user.rs @@ -3,137 +3,11 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2026 metamuffin <metamuffin.org> */ -use serde::{Deserialize, Serialize}; -use std::{ - collections::{HashMap, HashSet}, - fmt::Display, -}; -#[rustfmt::skip] -#[derive(Debug, Clone, Serialize, Deserialize, Default)] -pub struct User { - pub name: String, - pub display_name: String, - pub password: Vec<u8>, - pub admin: bool, - #[serde(default)] pub theme: Theme, - #[serde(default)] pub player_preference: PlayerKind, - #[serde(default)] pub native_secret: String, - pub permissions: PermissionSet, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct NodeUserData { - pub watched: WatchedState, - #[serde(default)] - pub rating: i32, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[serde(rename_all = "snake_case")] -pub enum WatchedState { - None, - Progress(f64), - Watched, - Pending, -} - -url_enum!( - #[derive(Debug, Clone, Serialize, Deserialize)] - #[serde(rename_all = "snake_case")] - enum ApiWatchedState { - None = "none", - Watched = "watched", - Pending = "pending", - } -); - -#[derive(Debug, Serialize, Deserialize)] -pub struct CreateSessionParams { - pub username: String, - pub password: String, - pub expire: Option<i64>, - pub drop_permissions: Option<HashSet<UserPermission>>, -} - -url_enum!( - #[derive(Debug, Clone, Copy, Serialize, Default, Deserialize, PartialEq)] - #[serde(rename_all = "snake_case")] - enum Theme { - #[default] - Dark = "dark", - Light = "light", - Purple = "purple", - Black = "black", - } -); - -url_enum!( - #[derive(Debug, Clone, Copy, Serialize, Default, Deserialize, PartialEq)] - #[serde(rename_all = "snake_case")] - enum PlayerKind { - #[default] - Browser = "browser", - Native = "native", - NativeFullscreen = "native_fullscreen", - } -); - -#[derive(Debug, Clone, Serialize, Deserialize, Default)] -pub struct PermissionSet(pub HashMap<UserPermission, bool>); - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] -#[serde(rename_all = "snake_case")] -pub enum UserPermission { - Admin, - // ManageUsers, - // GenerateInvite, - ManageSelf, - - AccessNode(String), - Transcode, - FederatedContent, -} - -impl UserPermission { - pub const ALL_ENUMERABLE: &'static [UserPermission] = { - use UserPermission::*; - &[Admin, Transcode, ManageSelf, FederatedContent] - }; - pub fn default_value(&self) -> bool { - use UserPermission::*; - matches!(self, Transcode | ManageSelf | FederatedContent) - } -} - -impl Display for UserPermission { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&match self { - UserPermission::ManageSelf => "manage self (password, display name, etc.)".to_string(), - UserPermission::FederatedContent => "access to federated content".to_string(), - UserPermission::Admin => "administrative rights".to_string(), - // UserPermission::StreamFormat(StreamFormat::Original) => { - // "downloading the original media".to_string() - // } - // UserPermission::StreamFormat(StreamFormat::Matroska) => { - // "downloading a remuxed WebM/Matroska version of the media ".to_string() - // } - // UserPermission::StreamFormat(x) => { - // format!("downloading media via {x:?}") - // } - UserPermission::Transcode => "transcoding".to_string(), - // UserPermission::ManageUsers => format!("management of all users"), - // UserPermission::GenerateInvite => format!("inviting new users"), - UserPermission::AccessNode(s) => format!("access to library node {s:?}"), - }) - } -} +use jellyobject::fields; -impl Default for NodeUserData { - fn default() -> Self { - Self { - watched: WatchedState::None, - rating: 0, - } - } +fields! { + USER_LOGIN: &str = 0x1001 "login"; + USER_PASSWORD: &str = 0x1002 "password"; + USER_NAME: &str = 0x1003 "name"; } |