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

fix: request counts #271

Merged
merged 2 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
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