diff --git a/bin/db_worker/db_worker.ml b/bin/db_worker/db_worker.ml index 56e5690..7114994 100644 --- a/bin/db_worker/db_worker.ml +++ b/bin/db_worker/db_worker.ml @@ -111,6 +111,9 @@ module Worker () = struct let on_query (type a) (q : a query) : (a, error) Fut.result = let open Fut.Result_syntax in match q with + | Set_session_uuid s -> + let () = Data_source.Jellyfin_api.set_session_uuid s in + Fut.ok () | Add_servers l -> let* idb = idb in let open Fut.Syntax in diff --git a/bin/main.ml b/bin/main.ml index 022c30c..5b56caa 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,6 +1,18 @@ open Import open Brr +(* The session uuid is stored to the local storage and used to identify a user + session. This is required by Jellyfin authorization scheme. *) +let session_uuid = + (* We never react to this var we could replace it *) + Brr_lwd_ui.Persistent.var_f ~key:"session_uuid" (fun () -> + Std.new_uuid_v4 () |> Uuidm.to_string) + +let _ = + let uuid = Lwd.peek session_uuid in + Data_source.Jellyfin_api.set_session_uuid uuid; + Worker_client.query (Set_session_uuid (Lwd.peek session_uuid)) + let fetch view i = Worker_client.(query (Get (view, i))) module P = Player.Playback_controller (struct diff --git a/lib/data_source/jellyfin_api.ml b/lib/data_source/jellyfin_api.ml index 9edbe86..c2a12cb 100644 --- a/lib/data_source/jellyfin_api.ml +++ b/lib/data_source/jellyfin_api.ml @@ -296,14 +296,19 @@ module System = struct end end +(* Forward declaration to be filled by the app *) +let session_uuid = ref None +let set_session_uuid s = session_uuid := Some s + let authorization ?token () = let token = match token with None -> "" | Some t -> Printf.sprintf ", Token=%S" t in + let session_uuid = Option.value ~default:"" !session_uuid in Printf.sprintf "MediaBrowser Client=\"Ocamix\", Device=\"Firefox\", DeviceId=\"%s\", \ Version=\"0.1\"%s" - "abcdef" token + session_uuid token let request (type pp p r) ?base_url ?token ?headers (module Q : Query @@ -317,6 +322,7 @@ let request (type pp p r) ?base_url ?token ?headers |> Result.get_ok in let authorization = authorization ?token () in + Console.log [ authorization ]; let headers = Headers.of_assoc ?init:headers Jstr. diff --git a/lib/db/db_worker_api.ml b/lib/db/db_worker_api.ml index 6929a3a..b188be2 100644 --- a/lib/db/db_worker_api.ml +++ b/lib/db/db_worker_api.ml @@ -6,6 +6,7 @@ type server = string * DS.connexion module Queries = struct type 'a query = + | Set_session_uuid : string -> unit query | Add_servers : server list -> unit query | Get_all : unit -> Api.Item.t list query | Get_libraries : unit -> Stores.Items.t list query