Skip to content
Closed
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
45 changes: 44 additions & 1 deletion lumen/i18n-keys.json
Original file line number Diff line number Diff line change
Expand Up @@ -5797,5 +5797,48 @@
"lumen.tvAvailability.sourceHd",
"lumen.tvAvailability.source4k",
"lumen.tvAvailability.sharedHd",
"lumen.tvAvailability.shared4k"
"lumen.tvAvailability.shared4k",
"lumen.admin.dest.aurral",
"lumen.collectors.unavailableSocial",
"lumen.music.all",
"lumen.music.artists",
"lumen.music.browseCatalog",
"lumen.music.genres",
"lumen.music.genresArtists",
"lumen.music.newReleases",
"lumen.music.noGenreMatches",
"lumen.music.noRequests",
"lumen.music.noResults",
"lumen.music.noResultsTitle",
"lumen.music.requestSong",
"lumen.music.requestTrack",
"lumen.music.requestingTrack",
"lumen.music.requestedSongToast",
"lumen.music.requestSongFailed",
"lumen.music.requestStatus.searching",
"lumen.music.requestStatus.declined",
"lumen.music.requestStatus.failed",
"lumen.music.requestStatus.cancelled",
"lumen.music.searchPlaceholderAurral",
"lumen.music.seeAllSongs",
"lumen.music.shortcuts",
"lumen.music.singlesEps",
"lumen.music.songs",
"lumen.music.subtitleAurral",
"lumen.music.topResult",
"lumen.music.topSongs",
"lumen.music.trendingArtists",
"lumen.music.trendingSongs",
"lumen.music.type.album",
"lumen.music.type.artist",
"lumen.music.type.song",
"lumen.music.viewAll",
"lumen.music.yourRequests",
"lumen.requests.openInAurral",
"lumen.requests.openTrackRequests",
"lumen.shell.searchMusic",
"lumen.songIdentify.unavailable",
"lumen.songIdentify.unavailableAurral",
"lumen.trackRequests.unavailable",
"lumen.trackRequests.unavailableAurral"
]
469 changes: 256 additions & 213 deletions lumen/i18n-overrides.json

Large diffs are not rendered by default.

83 changes: 79 additions & 4 deletions lumen/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,30 @@ export class ApiError extends Error {
public reason?: string,
public retryAt?: number,
public testResults?: unknown,
public allowOverride = false
public allowOverride = false,
// the parsed JSON error body, when there was one
public body?: unknown
) {
super(message);
}
}

// encodeURIComponent leaves ! ' ( ) * alone, and SeerrNG's request validator rejects them
// in a query string ("p*rnstar" failed), so the query part gets them percent-encoded too.
export const strictQuery = (path: string) => {
const at = path.indexOf('?');
if (at < 0) return path;
return (
path.slice(0, at + 1) +
path
.slice(at + 1)
.replace(
/[!'()*]/g,
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`
)
);
};

export async function api<T>(
path: string,
{
Expand All @@ -38,7 +56,7 @@ export async function api<T>(
}: RequestInit & { invalidateCache?: boolean } = {},
response: 'json' | 'empty' = 'json'
): Promise<T> {
const res = await fetch('/api/v1' + path, {
const res = await fetch('/api/v1' + strictQuery(path), {
credentials: 'same-origin',
// SeerrNG marks detail responses cacheable for 5 minutes (stale for 30), which would hide
// a request someone just made. Revalidate every time; unchanged answers come back as 304.
Expand All @@ -57,8 +75,10 @@ export async function api<T>(
let reason: string | undefined;
let testResults: unknown;
let allowOverride = false;
let body: unknown;
try {
const b = await res.json();
body = b;
msg = b.message || b.error || msg;
testResults = b.tests;
allowOverride = b.allowOverride === true;
Expand Down Expand Up @@ -91,7 +111,8 @@ export async function api<T>(
reason,
retryAt,
testResults,
allowOverride
allowOverride,
body
);
}
// a request or other change: saved answers may now be out of date
Expand Down Expand Up @@ -151,7 +172,10 @@ export interface MediaInfo {
availableEbookServiceIds?: number[] | null;
availableAudiobookServiceIds?: number[] | null;
ratingKey?: string | null;
serviceId?: number | null;
musicServiceType?: 'lidarr' | 'aurral' | null;
externalServiceId?: number | null;
serviceUrl?: string;
audiobookExternalServiceId?: number | null;
audiobookLibraryServiceId?: number | null;
audiobookLibraryItemId?: string | null;
Expand Down Expand Up @@ -454,7 +478,7 @@ export function proxiedArtPath(raw: string, host: string): string | undefined {
return u.pathname.slice(1) || undefined;
}
const LOCAL_ART_ROUTE =
/^(?:\/imageproxy\/.+|\/api\/v1\/(?:(?:sportarr|magazine)\/cover\/[^/]+\/[^/]+|(?:movie|tv|author|adult)\/[^/]+\/cover|book-series\/covers\/image))$/;
/^(?:\/imageproxy\/.+|\/api\/v1\/(?:(?:sportarr|magazine)\/cover\/[^/]+\/[^/]+|(?:movie|tv|author|adult)\/[^/]+\/cover|book-series\/covers\/image|music\/library-art\/(?:albums|artists)\/\d{1,10}|music\/artist-image\/[0-9a-fA-F-]{36}|music\/album-art\/[0-9a-fA-F-]{36}|music\/song-art|podcast\/cover\/[A-Za-z0-9_-]{1,64}))$/;

function localArt(raw: string) {
const path = raw.split(/[?#]/, 1)[0];
Expand Down Expand Up @@ -764,6 +788,57 @@ export const audiobookshelfLink = (
}
return url.href;
};

export interface MusicServiceSummary {
id: number;
name: string;
isDefault: boolean;
backendType: 'lidarr' | 'aurral';
musicQuality?: 'mp3' | 'flac';
externalUrl?: string;
hostname?: string;
port?: number;
useSsl?: boolean;
urlBase?: string;
}

export const aurralAlbumLink = (
media: MediaInfo | undefined,
services?: MusicServiceSummary[] | null
): string | null => {
if (!media || media.musicServiceType !== 'aurral') return null;
const albumId = media.externalServiceId;
if (
typeof albumId !== 'number' ||
!Number.isSafeInteger(albumId) ||
albumId <= 0
)
return null;
const aurral =
(media.serviceId != null
? services?.find(
(service) =>
service.backendType === 'aurral' && service.id === media.serviceId
)
: undefined) ??
services?.find((service) => service.backendType === 'aurral');
const candidate =
aurral?.externalUrl ||
(aurral?.hostname
? /^https?:\/\//i.test(aurral.hostname)
? aurral.hostname
: `${aurral.useSsl ? 'https' : 'http'}://${aurral.hostname}${aurral.port ? `:${aurral.port}` : ''}${aurral.urlBase ? `/${aurral.urlBase.replace(/^\/+|\/+$/g, '')}` : ''}`
: undefined) ||
media.serviceUrl;
const base = candidate ? readerServiceUrl(candidate) : null;
if (!base) return null;
base.search = '';
base.hash = '';
const root =
candidate === media.serviceUrl ? '' : base.pathname.replace(/\/+$/, '');
base.pathname = `${root}/library/albums/${albumId}`;
return base.href;
};
export const bookMediaForFormat = (
media: MediaInfo | undefined,
format: 'ebook' | 'audiobook'
Expand Down
2 changes: 1 addition & 1 deletion lumen/src/apiCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const SAVE_DELAY_MS = 400;
export const RECHECK_MS = 15_000;
// these change as people use the site: always asked again (still shown at once meanwhile)
const ALWAYS_CHECK =
/^\/(request|auth|user\/\d+\/quota|settings\/public|live-tv\/status|comic\/work\/)/;
/^\/(request|music\/track-requests|music\/library|podcast\/library|auth|user\/\d+\/quota|settings\/public|live-tv\/status|comic\/work\/)/;
// These answers depend on current account category and maturity policies.
// Never serve cached person details, watchlists, or personal library data after those settings tighten.
const NEVER_CACHE =
Expand Down
3 changes: 2 additions & 1 deletion lumen/src/components/ConfiguredDiscoverShelves.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type { Album } from '../extras';
import { useApi, usePublicSettings } from '../hooks';
import { AlbumCard } from '../pages/Music';
import { PersonCard } from '../pages/People';
import { apiQueryString } from '../searchParams';
import {
BookCard,
CollectionCard,
Expand Down Expand Up @@ -116,7 +117,7 @@ function shelfDestination(
endpoint.delete('sort');
endpoint.set('page', '1');
return {
endpoint: `/discover/music?${endpoint}`,
endpoint: `/discover/music?${apiQueryString(endpoint)}`,
href: `/music?${query}`,
kind: 'music',
};
Expand Down
3 changes: 2 additions & 1 deletion lumen/src/components/IdentityMapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { api, type Paged, type TitleResult } from '../api';
import { friendlyError } from '../errors';
import { useApi } from '../hooks';
import { useLumenLocale } from '../i18n';
import { apiQueryString } from '../searchParams';
import { ServiceNote } from './extra';
import { useToast } from './toast';

Expand Down Expand Up @@ -43,7 +44,7 @@ export default function IdentityMapping({
const toast = useToast();
const search = useApi<Paged<TitleResult>>(
open && matches
? `/search?${new URLSearchParams({ query: matches.term, type: matches.type, page: '1' })}`
? `/search?${apiQueryString(new URLSearchParams({ query: matches.term, type: matches.type, page: '1' }))}`
: null,
{ currentPathOnly: true }
);
Expand Down
Loading
Loading