diff options
-rw-r--r-- | common/src/user.rs | 8 | ||||
-rw-r--r-- | server/src/routes/ui/account/settings.rs | 11 | ||||
-rw-r--r-- | server/src/routes/ui/player.rs | 9 | ||||
-rwxr-xr-x | web/native-protocol/jellynative | 41 | ||||
-rw-r--r-- | web/script/transition.ts | 1 |
5 files changed, 53 insertions, 17 deletions
diff --git a/common/src/user.rs b/common/src/user.rs index 4b39673..5f2b0e4 100644 --- a/common/src/user.rs +++ b/common/src/user.rs @@ -13,16 +13,16 @@ use std::{ fmt::Display, }; +#[rustfmt::skip] #[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, 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 theme: Theme, + #[serde(default)] pub player_preference: PlayerKind, + #[serde(default)] pub native_secret: String, pub permissions: PermissionSet, } diff --git a/server/src/routes/ui/account/settings.rs b/server/src/routes/ui/account/settings.rs index e91bec0..ec92ba2 100644 --- a/server/src/routes/ui/account/settings.rs +++ b/server/src/routes/ui/account/settings.rs @@ -36,6 +36,7 @@ pub struct SettingsForm { display_name: Option<String>, theme: Option<Theme>, player_preference: Option<PlayerKind>, + native_secret: Option<String>, } fn option_len<'v>(value: &Option<String>, range: Range<usize>) -> form::Result<'v, ()> { @@ -90,6 +91,12 @@ fn settings_page(session: Session, flash: Option<MyResult<String>>) -> DynLayout } input[type="submit", value="Apply"]; } + form[method="POST", action=uri!(r_account_settings_post())] { + label[for="native_secret"] { "Native Secret" } + input[type="password", id="native_secret", name="native_secret"]; + input[type="submit", value="Update"]; + p { "The secret can be found in " code{"$XDG_CONFIG_HOME/jellynative_secret"} " or by clicking " a.button[href="jellynative://show-secret"] { "Show Secret" } "." } + } }, ..Default::default() } @@ -151,6 +158,10 @@ pub fn r_account_settings_post( user.player_preference = player_preference; out += "Player preference changed.\n"; } + if let Some(native_secret) = &form.native_secret { + user.native_secret = native_secret.to_owned(); + out += "Native secret updated.\n"; + } users.insert(&*session.user.name, Ser(user))?; drop(users); diff --git a/server/src/routes/ui/player.rs b/server/src/routes/ui/player.rs index be40d4c..becda91 100644 --- a/server/src/routes/ui/player.rs +++ b/server/src/routes/ui/player.rs @@ -46,9 +46,9 @@ impl PlayerConfig { } } -fn jellynative_url(action: &str, node: &str) -> String { +fn jellynative_url(action: &str, secret: &str, node: &str) -> String { format!( - "jellynative://{action}/http://{}{}", + "jellynative://{action}/{secret}/http://{}{}", CONF.hostname, uri!(r_stream( node, @@ -72,12 +72,15 @@ pub fn r_player<'a>( PlayerKind::Browser => (), PlayerKind::Native => { return Ok(Either::Right(Redirect::temporary(jellynative_url( - "player", id, + "player", + &sess.user.native_secret, + id, )))) } PlayerKind::NativeFullscreen => { return Ok(Either::Right(Redirect::temporary(jellynative_url( "player-fullscreen", + &sess.user.native_secret, id, )))) } diff --git a/web/native-protocol/jellynative b/web/native-protocol/jellynative index 1653e3f..e1b310c 100755 --- a/web/native-protocol/jellynative +++ b/web/native-protocol/jellynative @@ -2,33 +2,54 @@ set parts (string split / $argv[1]) set protocol $parts[1] set action $parts[3] -set arg (string join / $parts[4..]) +set secret $parts[4] -function die - notify-send -u critical 'Jellynative Error' $argv[1] - exit 1 -end if not test $protocol = "jellynative:" die "Wrong protocol" end + +function die + notify-send -u critical -t 5000 'Jellynative Error' $argv[1] + exit 1 +end + function player if which mpv &>/dev/null set playercommand mpv else if which vlc &>/dev/null set playercommand vlc else - die "No Media Player detected" + die 'No Media Player detected' end notify-send -u low -t 1000 Jellynative 'Player ist launching...' if not $playercommand $argv[2..] $argv[1] - die "Player exited with error code" + die 'Player exited with error code' end end + +set config_dir $XDG_CONFIG_HOME +if test -z $config + set config_dir ~/.config +end +set config $config_dir/jellynative_secret +if not test -e $config + random 0 4000000000 >$config +end +set secret (cat $config) + +if test $action != show-secret + if test $secret != $parts[4] + die 'Incorrect secret' + end +end + switch $action + case show-secret + notify-send -u low Jellynative "Secret: $secret" case player - player $arg + player (string join / $parts[5..]) case player-fullscreen - player $arg --fullscreen + player (string join / $parts[5..]) --fullscreen case '*' - die "Unknown action" + die 'Unknown action' end diff --git a/web/script/transition.ts b/web/script/transition.ts index a15a6b0..03338ca 100644 --- a/web/script/transition.ts +++ b/web/script/transition.ts @@ -23,6 +23,7 @@ globalThis.addEventListener("navigationrequiresreload", () => { function patch_page() { document.querySelectorAll("a").forEach(el => { + if (!el.href.startsWith("http")) return el.addEventListener("click", async ev => { ev.preventDefault() await transition_to(el.href) |