diff --git a/augmentations/api.ts b/augmentations/api.ts index 72b8c45f..da5c02a9 100644 --- a/augmentations/api.ts +++ b/augmentations/api.ts @@ -1,30 +1,46 @@ -import {Api, AUTHORIZATION_HEADER} from "@jellyfin/sdk"; -import {AxiosRequestConfig, AxiosResponse} from "axios"; -import {StreamyfinPluginConfig} from "@/utils/atoms/settings"; +import { Api, AUTHORIZATION_HEADER } from "@jellyfin/sdk"; +import { AxiosRequestConfig, AxiosResponse } from "axios"; +import { StreamyfinPluginConfig } from "@/utils/atoms/settings"; -declare module '@jellyfin/sdk' { +declare module "@jellyfin/sdk" { interface Api { - get(url: string, config?: AxiosRequestConfig): Promise> - post(url: string, data: D, config?: AxiosRequestConfig): Promise> - getStreamyfinPluginConfig(): Promise> + get( + url: string, + config?: AxiosRequestConfig + ): Promise>; + post( + url: string, + data: D, + config?: AxiosRequestConfig + ): Promise>; + getStreamyfinPluginConfig(): Promise>; } } -Api.prototype.get = function (url: string, config: AxiosRequestConfig = {}): Promise> { - return this.axiosInstance.get(url, { - ...(config ?? {}), - headers: { [AUTHORIZATION_HEADER]: this.authorizationHeader } - }) -} - -Api.prototype.post = function (url: string, data: D, config: AxiosRequestConfig): Promise> { +Api.prototype.get = function ( + url: string, + config: AxiosRequestConfig = {} +): Promise> { return this.axiosInstance.get(`${this.basePath}${url}`, { + ...(config ?? {}), + headers: { [AUTHORIZATION_HEADER]: this.authorizationHeader }, + }); +}; + +Api.prototype.post = function ( + url: string, + data: D, + config: AxiosRequestConfig +): Promise> { + return this.axiosInstance.post(`${this.basePath}${url}`, { ...(config || {}), data, - headers: { [AUTHORIZATION_HEADER]: this.authorizationHeader }} - ) -} + headers: { [AUTHORIZATION_HEADER]: this.authorizationHeader }, + }); +}; -Api.prototype.getStreamyfinPluginConfig = function (): Promise> { - return this.get("/Streamyfin/config") -} \ No newline at end of file +Api.prototype.getStreamyfinPluginConfig = function (): Promise< + AxiosResponse +> { + return this.get("/Streamyfin/config"); +}; diff --git a/components/MediaSourceSelector.tsx b/components/MediaSourceSelector.tsx index 34f02fd9..4888692a 100644 --- a/components/MediaSourceSelector.tsx +++ b/components/MediaSourceSelector.tsx @@ -29,6 +29,27 @@ export const MediaSourceSelector: React.FC = ({ [item, selected] ); + const commonPrefix = useMemo(() => { + const mediaSources = item.MediaSources || []; + if (!mediaSources.length) return ""; + + let commonPrefix = ""; + for (let i = 0; i < mediaSources[0].Name.length; i++) { + const char = mediaSources[0].Name[i]; + if (mediaSources.every((source) => source.Name[i] === char)) { + commonPrefix += char; + } else { + commonPrefix = commonPrefix.slice(0, -1); + break; + } + } + return commonPrefix; + }, [item.MediaSources]); + + const name = (name?: string | null) => { + return name?.replace(commonPrefix, "").toLowerCase(); + }; + return ( = ({ }} > - {`${name(source.Name)} - ${convertBitsToMegabitsOrGigabits( - source.Size - )}`} + {`${name(source.Name)}`} ))} @@ -74,9 +93,3 @@ export const MediaSourceSelector: React.FC = ({ ); }; - -const name = (name?: string | null) => { - if (name && name.length > 40) - return name.substring(0, 20) + " [...] " + name.substring(name.length - 20); - return name; -};