diff --git a/servers/eisen/configuration.nix b/servers/eisen/configuration.nix index 08c5db1..4110f68 100644 --- a/servers/eisen/configuration.nix +++ b/servers/eisen/configuration.nix @@ -211,6 +211,7 @@ in }; pages = import ./glance-pages.nix; }; + environmentFile = "/etc/secrets/glance.env"; }; caddy = { diff --git a/servers/eisen/glance-pages.nix b/servers/eisen/glance-pages.nix index 6eb3006..91c2899 100644 --- a/servers/eisen/glance-pages.nix +++ b/servers/eisen/glance-pages.nix @@ -1,3 +1,29 @@ +let + jellyfinConfig = + { + title, + library-name ? null, + mode, + }: + { + inherit title; + type = "custom-api"; + # url = "http://jellyfin.eisen.danbulant.cloud"; + frameless = true; + cache = "5m"; + options = { + inherit library-name mode; + base-url = "http://jellyfin.eisen.danbulant.cloud"; + api-key = "\${JELLYFIN_KEY}"; + user-name = "dan"; + item-count = "10"; + small-column = false; + show-thumbnail = true; + thumbnail-aspect-ratio = "default"; + }; + template = builtins.readFile ./glance/jellyfin-latest; + }; +in [ { name = "Home"; @@ -17,6 +43,24 @@ } ]; } + { + + # - type: custom-api + # title: "Jellyfin/Emby Stats" + # base-url: ${JELLYFIN_URL} + # options: + # url: ${JELLYFIN_URL} + # key: ${JELLYFIN_API_KEY} + # + type = "custom-api"; + title = "Jellyfin Stats"; + # url = "http://jellyfin.eisen.danbulant.cloud"; + options = { + url = "http://jellyfin.eisen.danbulant.cloud"; + key = "\${JELLYFIN_KEY}"; + }; + template = builtins.readFile ./glance/jellyfin-stats; + } { type = "custom-api"; title = "Uptime Kuma"; @@ -28,61 +72,24 @@ }; }; cache = "10m"; - template = '' - {{ $hb := .Subrequest "heartbeats" }} - - {{ if not (.JSON.Exists "publicGroupList") }} -
Error reading response
- {{ else if eq (len (.JSON.Array "publicGroupList")) 0 }} -No monitors found
- {{ else }} - -{{ . }}
+{{ end }} + +{{/* Check required fields */}} +{{ if or (eq $baseURL "") (eq $apiKey "") (eq $userName "") (eq $mode "") (and (eq $mode "latest") (eq $libraryName "")) }} + {{ template "errorMsg" "Some required options are not set." }} +{{ else }} + + {{/* Fetch user ID */}} + {{ $userID := "" }} + {{ $usersCall := newRequest (print $baseURL "/Users") + | withParameter "api_key" $apiKey + | withHeader "Accept" "application/json" + | getResponse }} + + {{ range $i, $user := $usersCall.JSON.Array "" }} + {{ if eq ($user.String "Name") $userName }} + {{ $userID = $user.String "Id" }} + {{ break }} + {{ end }} + {{ end }} + {{ if eq $userID "" }} + {{ template "errorMsg" (printf "User '%s' not found." $userName) }} + {{ else }} + + {{ $items := "" }} + + {{ if eq $mode "latest" }} + + {{/* Fetch library ID */}} + {{ $libraryID := "" }} + {{ $userViewsCall := newRequest (print $baseURL "/UserViews") + | withParameter "api_key" $apiKey + | withParameter "userId" $userID + | withHeader "Accept" "application/json" + | getResponse }} + + {{ range $i, $item := $userViewsCall.JSON.Array "Items" }} + {{ if eq ($item.String "Name") $libraryName }} + {{ $libraryID = $item.String "Id" }} + {{ break }} + {{ end }} + {{ end }} + + {{ if eq $libraryID "" }} + {{ template "errorMsg" (printf "Library '%s' not found." $libraryName) }} + {{ else }} + {{/* Fetch latest items */}} + {{ $latestCall := newRequest (print $baseURL "/Users/" $userID "/Items/Latest") + | withParameter "api_key" $apiKey + | withParameter "Limit" $itemCount + | withParameter "ParentId" $libraryID + | withParameter "IncludeItemTypes" $mediaTypes + | withParameter "GroupItems" "true" + | withHeader "Accept" "application/json" + | getResponse }} + {{ $items = $latestCall.JSON.Array "" }} + {{ end }} + + {{ else if eq $mode "nextup" }} + + {{/* Fetch next up items */}} + {{ $nextUpCall := newRequest (print $baseURL "/Shows/NextUp") + | withParameter "api_key" $apiKey + | withParameter "UserId" $userID + | withParameter "Limit" $itemCount + | withParameter "EnableResumable" "true" + | withHeader "Accept" "application/json" + | getResponse }} + {{ $items = $nextUpCall.JSON.Array "Items" }} + + {{ else }} + {{ template "errorMsg" "Unknown mode, expected 'latest' or 'nextup'" }} + {{ end }} + + {{ if eq (len $items) 0 }} +No items found, start streaming something!
+ {{ else }} + + {{/* Display the item carousel */}} +Error: The URL or API Key was not configured in the widget options.
+ +{{- else -}} + + {{- $requestUrl := printf "%s/emby/Items/Counts?api_key=%s" $url $key -}} + {{- $jellyfinData := newRequest $requestUrl | getResponse -}} + + {{- if eq $jellyfinData.Response.StatusCode 200 -}} +Failed: {{ $jellyfinData.Response.Status }}
+ {{- end -}} +{{- end -}} diff --git a/servers/eisen/glance/tailscale b/servers/eisen/glance/tailscale new file mode 100644 index 0000000..177f261 --- /dev/null +++ b/servers/eisen/glance/tailscale @@ -0,0 +1,106 @@ + +Error reading response
+{{ else if eq (len (.JSON.Array "publicGroupList")) 0 }} +No monitors found
+{{ else }} + +