Skip to content

Commit 2c093cb

Browse files
authored
Merge pull request #242 from GiamBoscaro/main
feat: added Overseerr Users Requests widget
2 parents 2c72b1b + 2e94563 commit 2c093cb

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Overseerr Users Requests
2+
3+
* [Introduction](#introduction)
4+
* [Preview](#preview)
5+
* [Configuration](#configuration)
6+
* [Environment Variables](#environment-variables)
7+
* [Customization](#customization)
8+
* [Widget YAML](#widget-yaml)
9+
10+
## Introduction
11+
12+
Shows a leaderboard of the Overseerr users ordered by the number of requestes done.
13+
14+
## Preview
15+
16+
![Preview](preview.png "Preview")
17+
18+
## Configuration
19+
20+
### Environment Variables
21+
22+
* `OVERSEERR_API_URL`: the URL of the Overseerr instance. Include `http://` or `https://`.
23+
* `OVERSEERR_API_KEY`: the API key of the server which can be found in _Settings > General > API key_
24+
25+
### Customization
26+
27+
Customize the widget appearance by editing these options:
28+
29+
| Name | Type | Required | Default | Description |
30+
| -------------- | ------- | -------- | ------- |------------ |
31+
| max-users | int | no | 10 | Maximum number of users to get from the API |
32+
| collapse-after | int | no | 5 | How many users to show when the list is collapsed |
33+
34+
## Widget YAML
35+
36+
```yaml
37+
- type: custom-api
38+
title: Overseerr Users Requests
39+
title-url: ${OVERSEERR_API_URL}/users
40+
cache: 1h
41+
options:
42+
collapse-after: 5
43+
max-users: 10
44+
api-base-url: ${OVERSEERR_API_URL}/api/v1
45+
api-key: ${OVERSEERR_API_KEY}
46+
template: |
47+
{{ $collapseAfter := .Options.IntOr "collapse-after" 5 }}
48+
{{ $maxUsers := .Options.IntOr "max-users" 10 }}
49+
{{ $apiBaseUrl := .Options.StringOr "api-base-url" "" }}
50+
{{ $apiKey := .Options.StringOr "api-key" "" }}
51+
52+
{{ $listUsersUrl := printf "%s/user?sort=requests&take=%d" $apiBaseUrl $maxUsers }}
53+
{{ $users := newRequest $listUsersUrl
54+
| withHeader "Accept" "application/json"
55+
| withHeader "X-Api-Key" $apiKey
56+
| getResponse }}
57+
58+
<ul class="list list-gap-10 collapsible-container" data-collapse-after="{{ $collapseAfter }}">
59+
{{ range $users.JSON.Array "results" }}
60+
{{ $userId := .String "id" }}
61+
{{ $username := .String "displayName" }}
62+
{{ if eq $username "" }}{{ $username = .String "username" }}{{ end }}
63+
{{ $avatar := .String "avatar" }}
64+
65+
{{ $usersRequestsUrl := printf "%s/user/%s/requests?take=1" $apiBaseUrl $userId }}
66+
{{ $stats := newRequest $usersRequestsUrl
67+
| withHeader "Accept" "application/json"
68+
| withHeader "X-Api-Key" $apiKey
69+
| getResponse }}
70+
71+
{{ $requestCount := $stats.JSON.Int "pageInfo.results" }}
72+
73+
<li class="flex items-center gap-10">
74+
<img src="{{ $avatar }}" alt="{{ $username }}" style="width: 32px; height: 32px; border-radius: 50%; background-color: var(--color-background-soft); object-fit: cover;">
75+
<div class="shrink min-width-0">
76+
<strong class="block text-truncate color-primary">{{ $username }}</strong>
77+
<div class="size-small color-subdue">
78+
{{ $requestCount }} {{ if eq $requestCount 1 }}request{{ else }}requests{{ end }}
79+
</div>
80+
</div>
81+
</li>
82+
{{ end }}
83+
84+
{{ if eq (len ($users.JSON.Array "results")) 0 }}
85+
<li>No users found. Check your API URL and Key.</li>
86+
{{ end }}
87+
</ul>
88+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
title: Overseerr Users Requests
2+
description: Shows the list of users and their number of request made in Overseerr
3+
author: GiamBoscaro
50.7 KB
Loading

0 commit comments

Comments
 (0)