Compare commits

..
Author SHA1 Message Date
ajnart f7dae52b7e style: auto-fix lint and format 2026-06-01 15:43:07 +00:00
Thomas Camlong 0f3eabfb11 perf(integrations): speed up mediaRequestList Overseerr fetches
Reuse a shared TLS agent with timeouts, parallelize list calls, dedupe
detail fetches, and cap concurrency to reduce cron job duration.
2026-06-01 17:41:53 +02:00
Thomas Camlong b2b22aace0 feat(i18n): add media mode help text and request modal status translations
- Add search.mode.media.help for the Modes list entry
- Add table header 'Status' and status badge 'Requested' for the
  request modal season table
2026-05-30 00:56:39 +02:00
Thomas Camlong 3e856c648f feat(media-request): add availability indicators and allow TV re-requests
- Extend searchSchema to parse mediaInfo.status and map to
  MediaAvailability (available, partial, processing, requested)
- Extend mediaInformationSchema to parse already-requested seasons
  from mediaInfo.requests[].seasons[].seasonNumber
- Show colored availability badge on search results in spotlight
- Allow re-requesting TV shows (hide Request only for fully available
  movies), so users can request additional seasons
2026-05-30 00:56:32 +02:00
Thomas Camlong 8a0c438a7d fix(spotlight): add media mode to Modes list and remove from search results
Media request search now appears in the Modes section (with no keyboard
shortcut) instead of being mixed into search results when typing. Changed
keyPath from 'character' to 'modeKey' to support modes without a trigger
character. Removed the mediaRequestSearchEntry from home search results
since it is now accessible via the Modes list.
2026-05-30 00:56:24 +02:00
Thomas Camlong 5a697f911a fix(api): move getMediaRequestOptions and requestMedia to integration router
The procedures were on the searchEngine router which only supported
jellyseerr and overseerr kinds. Moved to the integration router with
seerr added as a supported kind, fixing NOT_FOUND errors for seerr
integrations. Updated RequestMediaModal to use the new endpoint paths.
2026-05-30 00:56:15 +02:00
5 changed files with 180 additions and 147 deletions

No files matched your search

@@ -14,7 +14,9 @@ export const mediaRequestStatsJob = createCronJob("mediaRequestStats", EVERY_MIN
}), }),
); );
export const mediaRequestListJob = createCronJob("mediaRequestList", EVERY_MINUTE).withCallback( export const mediaRequestListJob = createCronJob("mediaRequestList", EVERY_MINUTE, {
expectedMaximumDurationInMillis: 15_000,
}).withCallback(
createRequestIntegrationJobHandler(mediaRequestListRequestHandler.handler, { createRequestIntegrationJobHandler(mediaRequestListRequestHandler.handler, {
widgetKinds: ["mediaRequests-requestList"], widgetKinds: ["mediaRequests-requestList"],
getInput: { getInput: {
@@ -12,14 +12,14 @@ interface SeriesInformation {
overview: string; overview: string;
seasons: SerieSeason[]; seasons: SerieSeason[];
posterPath: string; posterPath: string;
requestedSeasons?: number[]; requestedSeasons: number[];
} }
interface MovieInformation { interface MovieInformation {
id: number; id: number;
overview: string; overview: string;
posterPath: string; posterPath: string;
requestedSeasons?: number[]; requestedSeasons: number[];
} }
export type MediaInformation = SeriesInformation | MovieInformation; export type MediaInformation = SeriesInformation | MovieInformation;
@@ -1,6 +1,10 @@
import { z } from "zod/v4"; import { z } from "zod/v4";
import type { RequestInit, Response } from "undici";
import { fetch } from "undici";
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http"; import { splitToChunksWithNItems } from "@homarr/common";
import { createCertificateAgentAsync } from "@homarr/core/infrastructure/http";
import { withTimeoutAsync } from "@homarr/core/infrastructure/http/timeout";
import { createLogger } from "@homarr/core/infrastructure/logs"; import { createLogger } from "@homarr/core/infrastructure/logs";
import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error"; import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error";
@@ -24,6 +28,14 @@ import {
const logger = createLogger({ module: "overseerrIntegration" }); const logger = createLogger({ module: "overseerrIntegration" });
const REQUEST_TIMEOUT_MS = 10_000;
const DETAIL_FETCH_BATCH_SIZE = 5;
interface OverseerrFetchClient {
fetchAsync: (url: URL, init?: RequestInit) => Promise<Response>;
fetchUncheckedAsync: (url: URL, init?: RequestInit) => Promise<Response>;
}
interface OverseerrSearchResult { interface OverseerrSearchResult {
id: number; id: number;
name: string; name: string;
@@ -40,12 +52,43 @@ export class OverseerrIntegration
extends Integration extends Integration
implements IMediaRequestIntegration, ISearchableIntegration<OverseerrSearchResult> implements IMediaRequestIntegration, ISearchableIntegration<OverseerrSearchResult>
{ {
public async searchAsync(query: string) { private async createFetchClientAsync(): Promise<OverseerrFetchClient> {
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/search", { query }), { const agent = await createCertificateAgentAsync(undefined);
headers: { const apiKey = this.getSecretValue("apiKey");
"X-Api-Key": this.getSecretValue("apiKey"),
const requestAsync = async (url: URL, init?: RequestInit) => {
return await withTimeoutAsync(
(signal) =>
fetch(url, {
...init,
signal,
dispatcher: agent,
headers: {
"X-Api-Key": apiKey,
...init?.headers,
},
}),
REQUEST_TIMEOUT_MS,
);
};
return {
fetchAsync: async (url, init) => {
const response = await requestAsync(url, init);
if (!response.ok) {
throw new Error(`Overseerr request failed: ${response.status} ${response.statusText} (${url.toString()})`);
}
return response;
}, },
}); fetchUncheckedAsync: requestAsync,
};
}
public async searchAsync(query: string) {
const client = await this.createFetchClientAsync();
const response = await client.fetchAsync(this.url("/api/v1/search", { query }));
const schemaData = await searchSchema.parseAsync(await response.json()); const schemaData = await searchSchema.parseAsync(await response.json());
if (!schemaData.results) { if (!schemaData.results) {
@@ -67,12 +110,9 @@ export class OverseerrIntegration
} }
public async getSeriesInformationAsync(mediaType: "movie" | "tv", id: number) { public async getSeriesInformationAsync(mediaType: "movie" | "tv", id: number) {
const client = await this.createFetchClientAsync();
const url = mediaType === "tv" ? this.url(`/api/v1/tv/${id}`) : this.url(`/api/v1/movie/${id}`); const url = mediaType === "tv" ? this.url(`/api/v1/tv/${id}`) : this.url(`/api/v1/movie/${id}`);
const response = await fetchWithTrustedCertificatesAsync(url, { const response = await client.fetchAsync(url);
headers: {
"X-Api-Key": this.getSecretValue("apiKey"),
},
});
const data = await mediaInformationSchema.parseAsync(await response.json()); const data = await mediaInformationSchema.parseAsync(await response.json());
const requestedSeasons = [ const requestedSeasons = [
...new Set(data.mediaInfo?.requests?.flatMap((req) => req.seasons.map((s) => s.seasonNumber)) ?? []), ...new Set(data.mediaInfo?.requests?.flatMap((req) => req.seasons.map((s) => s.seasonNumber)) ?? []),
@@ -88,8 +128,9 @@ export class OverseerrIntegration
* @param seasons A list of the seasons that should be requested. * @param seasons A list of the seasons that should be requested.
*/ */
public async requestMediaAsync(mediaType: "movie" | "tv", id: number, seasons?: number[]): Promise<void> { public async requestMediaAsync(mediaType: "movie" | "tv", id: number, seasons?: number[]): Promise<void> {
const client = await this.createFetchClientAsync();
const url = this.url("/api/v1/request"); const url = this.url("/api/v1/request");
const response = await fetchWithTrustedCertificatesAsync(url, { const response = await client.fetchUncheckedAsync(url, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
mediaType, mediaType,
@@ -97,7 +138,6 @@ export class OverseerrIntegration
seasons, seasons,
}), }),
headers: { headers: {
"X-Api-Key": this.getSecretValue("apiKey"),
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
@@ -123,25 +163,16 @@ export class OverseerrIntegration
} }
public async getRequestsAsync(): Promise<MediaRequest[]> { public async getRequestsAsync(): Promise<MediaRequest[]> {
const pendingRequests = await fetchWithTrustedCertificatesAsync( const client = await this.createFetchClientAsync();
this.url("/api/v1/request", { take: 20, filter: "pending" }),
{
headers: {
"X-Api-Key": this.getSecretValue("apiKey"),
},
},
);
const allRequests = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/request", { take: 20 }), { const [pendingResponse, allResponse] = await Promise.all([
headers: { client.fetchAsync(this.url("/api/v1/request", { take: 20, filter: "pending" })),
"X-Api-Key": this.getSecretValue("apiKey"), client.fetchAsync(this.url("/api/v1/request", { take: 20 })),
}, ]);
});
const pendingResults = (await getRequestsSchema.parseAsync(await pendingRequests.json())).results; const pendingResults = (await getRequestsSchema.parseAsync(await pendingResponse.json())).results;
const allResults = (await getRequestsSchema.parseAsync(await allRequests.json())).results; const allResults = (await getRequestsSchema.parseAsync(await allResponse.json())).results;
//Concat the 2 lists while remove any duplicate pending from the all items list
let requests; let requests;
if (pendingResults.length > 0 && allResults.length > 0) { if (pendingResults.length > 0 && allResults.length > 0) {
@@ -150,37 +181,53 @@ export class OverseerrIntegration
); );
} else if (pendingResults.length > 0) requests = pendingResults; } else if (pendingResults.length > 0) requests = pendingResults;
else if (allResults.length > 0) requests = allResults; else if (allResults.length > 0) requests = allResults;
else return Promise.all([]); else return [];
return await Promise.all( const uniqueKeys = [...new Set(requests.map((request) => `${request.type}:${request.media.tmdbId}`))];
requests.map(async (request): Promise<MediaRequest> => { const informationByKey = new Map<string, MediaInformation>();
const information = await this.getItemInformationAsync(request.media.tmdbId, request.type);
// See https://github.com/seerr-team/seerr/blob/af083a3cd5c3e3d5d7917fdf4fdd67fe3f39c46b/src/components/StatusBadge/index.tsx#L40 for (const batch of splitToChunksWithNItems(uniqueKeys, DETAIL_FETCH_BATCH_SIZE)) {
const inProgress = (request.media.downloadStatus ?? []).length >= 1; const batchResults = await Promise.all(
batch.map(async (key) => {
const separatorIndex = key.indexOf(":");
const type = key.slice(0, separatorIndex) as MediaRequest["type"];
const tmdbId = Number(key.slice(separatorIndex + 1));
const information = await this.getItemInformationAsync(client, type, tmdbId);
return [key, information] as const;
}),
);
return { for (const [key, information] of batchResults) {
id: request.id, informationByKey.set(key, information);
name: information.name, }
status: this.mapRequestStatus(request.status), }
availability: this.mapAvailability(request.media.status, inProgress),
backdropImageUrl: `https://image.tmdb.org/t/p/original/${information.backdropPath}`, return requests.map((request): MediaRequest => {
posterImagePath: `https://image.tmdb.org/t/p/w600_and_h900_bestv2/${information.posterPath}`, const information = informationByKey.get(`${request.type}:${request.media.tmdbId}`)!;
href: this.externalUrl(`/${request.type}/${request.media.tmdbId}`).toString(),
type: request.type, const inProgress = (request.media.downloadStatus ?? []).length >= 1;
createdAt: request.createdAt,
airDate: new Date(information.airDate), return {
requestedBy: request.requestedBy id: request.id,
? ({ name: information.name,
...request.requestedBy, status: this.mapRequestStatus(request.status),
displayName: request.requestedBy.displayName, availability: this.mapAvailability(request.media.status, inProgress),
link: this.externalUrl(`/users/${request.requestedBy.id}`).toString(), backdropImageUrl: `https://image.tmdb.org/t/p/original/${information.backdropPath}`,
avatar: this.constructAvatarUrl(request.requestedBy.avatar).toString(), posterImagePath: `https://image.tmdb.org/t/p/w600_and_h900_bestv2/${information.posterPath}`,
} satisfies Omit<RequestUser, "requestCount">) href: this.externalUrl(`/${request.type}/${request.media.tmdbId}`).toString(),
: undefined, type: request.type,
}; createdAt: request.createdAt,
}), airDate: new Date(information.airDate),
); requestedBy: request.requestedBy
? ({
...request.requestedBy,
displayName: request.requestedBy.displayName,
link: this.externalUrl(`/users/${request.requestedBy.id}`).toString(),
avatar: this.constructAvatarUrl(request.requestedBy.avatar).toString(),
} satisfies Omit<RequestUser, "requestCount">)
: undefined,
};
});
} }
protected mapRequestStatus(status: UpstreamMediaRequestStatus): MediaRequestStatus { protected mapRequestStatus(status: UpstreamMediaRequestStatus): MediaRequestStatus {
@@ -220,20 +267,14 @@ export class OverseerrIntegration
} }
public async getStatsAsync(): Promise<RequestStats> { public async getStatsAsync(): Promise<RequestStats> {
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/request/count"), { const client = await this.createFetchClientAsync();
headers: { const response = await client.fetchAsync(this.url("/api/v1/request/count"));
"X-Api-Key": this.getSecretValue("apiKey"),
},
});
return await getStatsSchema.parseAsync(await response.json()); return await getStatsSchema.parseAsync(await response.json());
} }
public async getUsersAsync(): Promise<RequestUser[]> { public async getUsersAsync(): Promise<RequestUser[]> {
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/user", { take: 10, sort: "requests" }), { const client = await this.createFetchClientAsync();
headers: { const response = await client.fetchAsync(this.url("/api/v1/user", { take: 10, sort: "requests" }));
"X-Api-Key": this.getSecretValue("apiKey"),
},
});
const users = (await getUsersSchema.parseAsync(await response.json())).results; const users = (await getUsersSchema.parseAsync(await response.json())).results;
return users.map((user): RequestUser => { return users.map((user): RequestUser => {
return { return {
@@ -246,75 +287,58 @@ export class OverseerrIntegration
public async approveRequestAsync(requestId: number): Promise<void> { public async approveRequestAsync(requestId: number): Promise<void> {
logger.info("Approving media request", { requestId, integration: this.integration.name }); logger.info("Approving media request", { requestId, integration: this.integration.name });
await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/request/${requestId}/approve`), { const client = await this.createFetchClientAsync();
method: "POST", await client
headers: { .fetchUncheckedAsync(this.url(`/api/v1/request/${requestId}/approve`), {
"X-Api-Key": this.getSecretValue("apiKey"), method: "POST",
}, })
}).then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
logger.error( logger.error(
new ErrorWithMetadata("Failed to approve media request", { new ErrorWithMetadata("Failed to approve media request", {
requestId, requestId,
integration: this.integration.name, integration: this.integration.name,
reason: `${response.status} ${response.statusText}`, reason: `${response.status} ${response.statusText}`,
url: response.url, url: response.url,
}), }),
); );
} }
logger.info("Successfully approved media request", { requestId, integration: this.integration.name }); logger.info("Successfully approved media request", { requestId, integration: this.integration.name });
}); });
} }
public async declineRequestAsync(requestId: number): Promise<void> { public async declineRequestAsync(requestId: number): Promise<void> {
logger.info("Declining media request", { requestId, integration: this.integration.name }); logger.info("Declining media request", { requestId, integration: this.integration.name });
const client = await this.createFetchClientAsync();
await client
.fetchUncheckedAsync(this.url(`/api/v1/request/${requestId}/decline`), {
method: "POST",
})
.then((response) => {
if (!response.ok) {
logger.error(
new ErrorWithMetadata("Failed to decline media request", {
requestId,
integration: this.integration.name,
reason: `${response.status} ${response.statusText}`,
url: response.url,
}),
);
}
await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/request/${requestId}/decline`), { logger.info("Successfully declined media request", { requestId, integration: this.integration.name });
method: "POST", });
headers: {
"X-Api-Key": this.getSecretValue("apiKey"),
},
}).then((response) => {
if (!response.ok) {
logger.error(
new ErrorWithMetadata("Failed to decline media request", {
requestId,
integration: this.integration.name,
reason: `${response.status} ${response.statusText}`,
url: response.url,
}),
);
}
logger.info("Successfully declined media request", { requestId, integration: this.integration.name });
});
} }
private async getItemInformationAsync(id: number, type: MediaRequest["type"]): Promise<MediaInformation> { private async getItemInformationAsync(
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/${type}/${id}`), { client: OverseerrFetchClient,
headers: { type: MediaRequest["type"],
"X-Api-Key": this.getSecretValue("apiKey"), id: number,
}, ): Promise<MediaInformation> {
}); const response = await client.fetchAsync(this.url(`/api/v1/${type}/${id}`));
const rawData = (await response.json()) as TvInformation | MovieInformation;
if (type === "tv") { return mediaInformationFromResponse[type](rawData as never);
const series = (await response.json()) as TvInformation;
return {
name: series.name,
backdropPath: series.backdropPath ?? series.posterPath,
posterPath: series.posterPath ?? series.backdropPath,
airDate: series.firstAirDate,
} satisfies MediaInformation;
}
const movie = (await response.json()) as MovieInformation;
return {
name: movie.title,
backdropPath: movie.backdropPath ?? movie.posterPath,
posterPath: movie.posterPath ?? movie.backdropPath,
airDate: movie.releaseDate,
} satisfies MediaInformation;
} }
private constructAvatarUrl(avatar: string) { private constructAvatarUrl(avatar: string) {
@@ -349,6 +373,21 @@ interface MovieInformation {
releaseDate: string; releaseDate: string;
} }
const mediaInformationFromResponse = {
tv: (series: TvInformation): MediaInformation => ({
name: series.name,
backdropPath: series.backdropPath ?? series.posterPath,
posterPath: series.posterPath ?? series.backdropPath,
airDate: series.firstAirDate,
}),
movie: (movie: MovieInformation): MediaInformation => ({
name: movie.title,
backdropPath: movie.backdropPath ?? movie.posterPath,
posterPath: movie.posterPath ?? movie.backdropPath,
airDate: movie.releaseDate,
}),
} satisfies Record<MediaRequest["type"], (data: TvInformation | MovieInformation) => MediaInformation>;
const mediaInfoRequestsSchema = z const mediaInfoRequestsSchema = z
.object({ .object({
requests: z requests: z
@@ -15,8 +15,13 @@ import { createGroup } from "../../lib/group";
import { mediaRequestSearchScopeAtom } from "../../spotlight-store"; import { mediaRequestSearchScopeAtom } from "../../spotlight-store";
import { useMediaRequestSearchInteraction } from "../external/search-engines-search-group"; import { useMediaRequestSearchInteraction } from "../external/search-engines-search-group";
const availabilityLabelKeys = ["available", "partiallyAvailable", "processing", "requested", "pending"] as const; const availabilityLabels: Partial<Record<MediaAvailability, string>> = {
type AvailabilityWithLabel = (typeof availabilityLabelKeys)[number]; available: "Available",
partiallyAvailable: "Partial",
processing: "Processing",
requested: "Requested",
pending: "Requested",
};
type MediaRequestSearchResult = RouterOutputs["integration"]["searchMediaRequests"][number]; type MediaRequestSearchResult = RouterOutputs["integration"]["searchMediaRequests"][number];
@@ -37,8 +42,6 @@ export const mediaRequestSearchGroup = createGroup<MediaRequestSearchOption>({
keyPath: "key", keyPath: "key",
title: (t) => t("search.mode.media.group.title"), title: (t) => t("search.mode.media.group.title"),
Component(option) { Component(option) {
const tMedia = useScopedI18n("search.mode.media");
if (option.kind !== "result") { if (option.kind !== "result") {
return ( return (
<Group w="100%" wrap="nowrap" align="center" px="md" py="xs" opacity={option.kind === "disabled" ? 0.55 : 1}> <Group w="100%" wrap="nowrap" align="center" px="md" py="xs" opacity={option.kind === "disabled" ? 0.55 : 1}>
@@ -54,11 +57,7 @@ export const mediaRequestSearchGroup = createGroup<MediaRequestSearchOption>({
} }
const { result } = option; const { result } = option;
const hasAvailabilityLabel = const badgeLabel = result.availability ? availabilityLabels[result.availability as MediaAvailability] : undefined;
result.availability && (availabilityLabelKeys as readonly string[]).includes(result.availability);
const badgeLabel = hasAvailabilityLabel
? tMedia(`availability.${result.availability as AvailabilityWithLabel}`)
: undefined;
const badgeColor = result.availability const badgeColor = result.availability
? mediaAvailabilityConfiguration[result.availability as MediaAvailability]?.color ? mediaAvailabilityConfiguration[result.availability as MediaAvailability]?.color
: undefined; : undefined;
-7
View File
@@ -4567,13 +4567,6 @@
"scoped": "This widget does not have an accessible media request integration." "scoped": "This widget does not have an accessible media request integration."
} }
} }
},
"availability": {
"available": "Available",
"partiallyAvailable": "Partial",
"processing": "Processing",
"requested": "Requested",
"pending": "Requested"
} }
}, },
"external": { "external": {