Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: release #272

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ Plex Rewind is also available in the Community Apps store for Unraid. Search for

To update, run `docker compose pull` and then `docker compose up -d`.

Optionally, you can also set up automatic updates with [Watchtower](https://containrrr.dev/watchtower).

## Donate

If you like this project and wish to support it, you can do so by donating via [Patreon](https://www.patreon.com/PlexRewind) or [PayPal](https://paypal.me/raunot). Thank you! ❤️
If you like this project and wish to support it, you can do so with a one-time donation via [PayPal](https://paypal.me/raunot) or a recurring one on [Patreon](https://www.patreon.com/PlexRewind) or [GitHub Sponsors](https://github.com/sponsors/RaunoT) (preferred). Thank you! ❤️

### Supporters

_Please note that supporting does not guarantee any support or future developments._
- NAS Assist

## Learn More

Expand Down
3 changes: 1 addition & 2 deletions src/app/dashboard/_components/PeriodSelectContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { GlobalContext } from '@/app/_components/GlobalContextProvider'
import { DashboardSearchParams } from '@/types/dashboard'
import { Settings } from '@/types/settings'
import { pluralize } from '@/utils/formatting'
import Link from 'next/link'
import { usePathname, useSearchParams } from 'next/navigation'
import { useContext, useEffect } from 'react'
Expand Down Expand Up @@ -38,7 +37,7 @@ export default function PeriodSelectContent({ settings }: Props) {
const periodOptions = [
{ label: '7 days', value: '7days' },
{
label: `${pluralize(customPeriod, 'day')}`,
label: customPeriod > 1 ? `${customPeriod} days` : 'Today',
value: 'custom',
},
{ label: 'Past year', value: 'pastYear' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const schema = z.object({
(value) => {
const number = parseFloat(value)

return number > 1 && number <= 3000
return number > 0 && number <= 3000
},
{
message: 'Custom period must be > 1 and <= 3000',
message: 'Custom period must be > 0 and <= 3000',
},
)
.optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export default function DashboardSettingsForm({ settings }: Props) {
/>
<span className='label'>
<span className='label-wrapper'>Custom period</span>
<small>In days.</small>
</span>
</label>
<DatePicker
Expand Down
2 changes: 1 addition & 1 deletion src/components/MediaItem/MediaItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export default function MediaItem({
</li>
)}
{/* Requests */}
{activeStats.includes('requests') && isUsers && data.requests > 0 && (
{activeStats.includes('requests') && isUsers && isOverseerrActive && (
<li className='icon-stat-wrapper'>
<QuestionMarkCircleIcon />
{pluralize(data.requests, 'request')}
Expand Down
25 changes: 18 additions & 7 deletions src/utils/fetchOverseerr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ type OverseerrRequestItem = {
}
}

const PAGE_SIZE = 20

export default async function fetchOverseerr<T>(
endpoint: string,
cache: boolean = false,
additionalParams?: Record<string, string>,
): Promise<T | null> {
const settings = getSettings()
const overseerrUrl = settings.connection.overseerrUrl
Expand All @@ -46,7 +49,11 @@ export default async function fetchOverseerr<T>(
return null
}

const apiUrl = `${overseerrUrl}/api/v1/${endpoint}`
const queryParams = new URLSearchParams({
take: String(PAGE_SIZE),
...additionalParams,
})
const apiUrl = `${overseerrUrl}/api/v1/${endpoint}?${queryParams.toString()}`

try {
const res = await fetch(apiUrl, {
Expand Down Expand Up @@ -84,15 +91,17 @@ export async function fetchOverseerrStats(
startDate: string,
endDate?: string,
): Promise<OverseerrRequestItem[]> {
const pageSize = 10

let requestsArr: OverseerrRequestItem[] = []

async function fetchRequests(
page: number,
): Promise<OverseerrResponse<OverseerrRequestItem> | null> {
return await fetchOverseerr<OverseerrResponse<OverseerrRequestItem>>(
`${req}?skip=${pageSize * (page - 1)}`,
req,
undefined,
{
skip: String(PAGE_SIZE * (page - 1)),
},
)
}

Expand Down Expand Up @@ -133,15 +142,17 @@ export async function fetchOverseerrStats(
export async function fetchOverseerrUserId(
plexId: string,
): Promise<number | null> {
const pageSize = 10

let userId: number | null = null

async function fetchUsers(
page: number,
): Promise<OverseerrResponse<OverseerrUser> | null> {
return await fetchOverseerr<OverseerrResponse<OverseerrUser>>(
`user?skip=${pageSize * (page - 1)}`,
`user`,
undefined,
{
skip: String(PAGE_SIZE * (page - 1)),
},
)
}

Expand Down
18 changes: 17 additions & 1 deletion src/utils/getUsersTop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import fetchTautulli, {
getUsersCount,
} from './fetchTautulli'
import getSettings from './getSettings'
import { anonymizeUsers } from './helpers'

type UserRequestCounts =
| {
Expand Down Expand Up @@ -206,3 +205,20 @@ async function getInactiveUserInTimePeriod(

return nonActive
}

function anonymizeUsers(
users: TautulliItemRow[],
loggedInUserId: string,
): TautulliItemRow[] {
return users.map((user) => {
const isLoggedIn = user.user_id === Number(loggedInUserId)

return {
...user,
user: isLoggedIn ? user.user : 'Anonymous',
friendly_name: isLoggedIn ? user.friendly_name : 'Anonymous',
user_thumb: isLoggedIn ? user.user_thumb : '',
user_id: isLoggedIn ? user.user_id : 0,
}
})
}
18 changes: 0 additions & 18 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Settings } from '@/types/settings'
import { TautulliItemRow } from '@/types/tautulli'
import { PERIODS, SETTINGS_PAGES } from './constants'

const REQUIRED_SETTINGS = [
Expand Down Expand Up @@ -40,20 +39,3 @@ export function getRewindDateRange(settings: Settings) {

return { startDate, endDate }
}

export function anonymizeUsers(
users: TautulliItemRow[],
loggedInUserId: string,
): TautulliItemRow[] {
return users.map((user) => {
const isLoggedIn = user.user_id === Number(loggedInUserId)

return {
...user,
user: isLoggedIn ? user.user : 'Anonymous',
friendly_name: isLoggedIn ? user.friendly_name : 'Anonymous',
user_thumb: isLoggedIn ? user.user_thumb : '',
user_id: isLoggedIn ? user.user_id : 0,
}
})
}