mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 07:25:48 +01:00
🐛 Fix pull request issues
This commit is contained in:
@@ -10,7 +10,7 @@ import { downloadRouter } from './routers/download';
|
||||
import { mediaRequestsRouter } from './routers/media-request';
|
||||
import { mediaServerRouter } from './routers/media-server';
|
||||
import { overseerrRouter } from './routers/overseerr';
|
||||
import { usenetRouter } from './routers/usenet/route';
|
||||
import { usenetRouter } from './routers/usenet/router';
|
||||
import { calendarRouter } from './routers/calendar';
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,8 +2,9 @@ import axios from 'axios';
|
||||
import Consola from 'consola';
|
||||
import { z } from 'zod';
|
||||
import { getConfig } from '~/tools/config/getConfig';
|
||||
import { AppIntegrationType } from '~/types/app';
|
||||
import { AppIntegrationType, IntegrationType } from '~/types/app';
|
||||
import { createTRPCRouter, publicProcedure } from '../trpc';
|
||||
import { checkIntegrationsType } from '~/tools/client/app-properties';
|
||||
|
||||
export const calendarRouter = createTRPCRouter({
|
||||
medias: publicProcedure
|
||||
@@ -21,14 +22,14 @@ export const calendarRouter = createTRPCRouter({
|
||||
const { configName, month, year, options } = input;
|
||||
const config = getConfig(configName);
|
||||
|
||||
const mediaAppIntegrationTypes: AppIntegrationType['type'][] = [
|
||||
const mediaAppIntegrationTypes = [
|
||||
'sonarr',
|
||||
'radarr',
|
||||
'readarr',
|
||||
'lidarr',
|
||||
];
|
||||
const mediaApps = config.apps.filter(
|
||||
(app) => app.integration && mediaAppIntegrationTypes.includes(app.integration.type)
|
||||
] as const satisfies readonly IntegrationType[];
|
||||
const mediaApps = config.apps.filter((app) =>
|
||||
checkIntegrationsType(app.integration, mediaAppIntegrationTypes)
|
||||
);
|
||||
|
||||
const integrationTypeEndpointMap = new Map<AppIntegrationType['type'], string>([
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
import { ConfigAppType, IntegrationField } from '~/types/app';
|
||||
import { UsenetQueueItem } from '~/widgets/useNet/types';
|
||||
import { createTRPCRouter, publicProcedure } from '../trpc';
|
||||
import { findAppProperty } from '~/tools/client/app-properties';
|
||||
|
||||
export const downloadRouter = createTRPCRouter({
|
||||
get: publicProcedure
|
||||
@@ -155,8 +156,8 @@ const GetDataFromClient = async (
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port,
|
||||
login: app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash: app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
login: findAppProperty(app, 'username'),
|
||||
hash: findAppProperty(app, 'password'),
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
|
||||
@@ -4,6 +4,7 @@ import { getConfig } from '~/tools/config/getConfig';
|
||||
import { MediaRequest } from '~/widgets/media-requests/media-request-types';
|
||||
import { createTRPCRouter, publicProcedure } from '../trpc';
|
||||
import { MediaRequestListWidget } from '~/widgets/media-requests/MediaRequestListTile';
|
||||
import { checkIntegrationsType } from '~/tools/client/app-properties';
|
||||
|
||||
export const mediaRequestsRouter = createTRPCRouter({
|
||||
all: publicProcedure
|
||||
@@ -16,7 +17,7 @@ export const mediaRequestsRouter = createTRPCRouter({
|
||||
const config = getConfig(input.configName);
|
||||
|
||||
const apps = config.apps.filter((app) =>
|
||||
['overseerr', 'jellyseerr'].includes(app.integration?.type ?? '')
|
||||
checkIntegrationsType(app.integration, ['overseerr', 'jellyseerr'])
|
||||
);
|
||||
|
||||
Consola.log(`Retrieving media requests from ${apps.length} apps`);
|
||||
|
||||
@@ -11,6 +11,7 @@ import { MediaServersResponseType } from '~/types/api/media-server/response';
|
||||
import { GenericCurrentlyPlaying, GenericSessionInfo } from '~/types/api/media-server/session-info';
|
||||
import { ConfigAppType } from '~/types/app';
|
||||
import { createTRPCRouter, publicProcedure } from '../trpc';
|
||||
import { checkIntegrationsType, findAppProperty } from '~/tools/client/app-properties';
|
||||
|
||||
const jellyfin = new Jellyfin({
|
||||
clientInfo: {
|
||||
@@ -34,7 +35,7 @@ export const mediaServerRouter = createTRPCRouter({
|
||||
const config = getConfig(input.configName);
|
||||
|
||||
const apps = config.apps.filter((app) =>
|
||||
['jellyfin', 'plex'].includes(app.integration?.type ?? '')
|
||||
checkIntegrationsType(app.integration, ['jellyfin', 'plex'])
|
||||
);
|
||||
|
||||
const servers = await Promise.all(
|
||||
@@ -68,9 +69,9 @@ export const mediaServerRouter = createTRPCRouter({
|
||||
const handleServer = async (app: ConfigAppType): Promise<GenericMediaServer | undefined> => {
|
||||
switch (app.integration?.type) {
|
||||
case 'jellyfin': {
|
||||
const username = app.integration.properties.find((x) => x.field === 'username');
|
||||
const username = findAppProperty(app, 'username');
|
||||
|
||||
if (!username || !username.value) {
|
||||
if (!username) {
|
||||
return {
|
||||
appId: app.id,
|
||||
serverAddress: app.url,
|
||||
@@ -81,9 +82,9 @@ const handleServer = async (app: ConfigAppType): Promise<GenericMediaServer | un
|
||||
};
|
||||
}
|
||||
|
||||
const password = app.integration.properties.find((x) => x.field === 'password');
|
||||
const password = findAppProperty(app, 'password');
|
||||
|
||||
if (!password || !password.value) {
|
||||
if (!password) {
|
||||
return {
|
||||
appId: app.id,
|
||||
serverAddress: app.url,
|
||||
@@ -96,7 +97,7 @@ const handleServer = async (app: ConfigAppType): Promise<GenericMediaServer | un
|
||||
|
||||
const api = jellyfin.createApi(app.url);
|
||||
const infoApi = await getSystemApi(api).getPublicSystemInfo();
|
||||
await api.authenticateUserByName(username.value, password.value);
|
||||
await api.authenticateUserByName(username, password);
|
||||
const sessionApi = await getSessionApi(api);
|
||||
const sessions = await sessionApi.getSessions();
|
||||
return {
|
||||
@@ -168,9 +169,9 @@ const handleServer = async (app: ConfigAppType): Promise<GenericMediaServer | un
|
||||
};
|
||||
}
|
||||
case 'plex': {
|
||||
const apiKey = app.integration.properties.find((x) => x.field === 'apiKey');
|
||||
const apiKey = findAppProperty(app, 'apiKey');
|
||||
|
||||
if (!apiKey || !apiKey.value) {
|
||||
if (!apiKey) {
|
||||
return {
|
||||
serverAddress: app.url,
|
||||
sessions: [],
|
||||
@@ -181,7 +182,7 @@ const handleServer = async (app: ConfigAppType): Promise<GenericMediaServer | un
|
||||
};
|
||||
}
|
||||
|
||||
const plexClient = new PlexClient(app.url, apiKey.value);
|
||||
const plexClient = new PlexClient(app.url, apiKey);
|
||||
const sessions = await plexClient.getSessions();
|
||||
return {
|
||||
serverAddress: app.url,
|
||||
|
||||
@@ -11,6 +11,7 @@ import { getConfig } from '~/tools/config/getConfig';
|
||||
import { UsenetHistoryItem, UsenetQueueItem } from '~/widgets/useNet/types';
|
||||
import { createTRPCRouter, publicProcedure } from '../../trpc';
|
||||
import { NzbgetClient } from './nzbget/nzbget-client';
|
||||
import { checkIntegrationsType, findAppProperty } from '~/tools/client/app-properties';
|
||||
|
||||
export const usenetRouter = createTRPCRouter({
|
||||
info: publicProcedure
|
||||
@@ -25,20 +26,20 @@ export const usenetRouter = createTRPCRouter({
|
||||
|
||||
const app = config.apps.find((x) => x.id === input.appId);
|
||||
|
||||
if (!app || (app.integration?.type !== 'nzbGet' && app.integration?.type !== 'sabnzbd')) {
|
||||
if (!app || !checkIntegrationsType(app.integration, ['nzbGet', 'sabnzbd'])) {
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: `App with ID "${input.appId}" could not be found.`,
|
||||
});
|
||||
}
|
||||
|
||||
if (app.integration?.type === 'nzbGet') {
|
||||
if (app.integration.type === 'nzbGet') {
|
||||
const url = new URL(app.url);
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port || (url.protocol === 'https:' ? '443' : '80'),
|
||||
login: app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash: app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
login: findAppProperty(app, 'username'),
|
||||
hash: findAppProperty(app, 'password'),
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -70,7 +71,7 @@ export const usenetRouter = createTRPCRouter({
|
||||
};
|
||||
}
|
||||
|
||||
const apiKey = app.integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
const apiKey = findAppProperty(app, 'apiKey');
|
||||
if (!apiKey) {
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
@@ -110,17 +111,17 @@ export const usenetRouter = createTRPCRouter({
|
||||
|
||||
const app = config.apps.find((x) => x.id === input.appId);
|
||||
|
||||
if (!app || (app.integration?.type !== 'nzbGet' && app.integration?.type !== 'sabnzbd')) {
|
||||
if (!app || !checkIntegrationsType(app.integration, ['nzbGet', 'sabnzbd'])) {
|
||||
throw new Error(`App with ID "${input.appId}" could not be found.`);
|
||||
}
|
||||
|
||||
if (app.integration?.type === 'nzbGet') {
|
||||
if (app.integration.type === 'nzbGet') {
|
||||
const url = new URL(app.url);
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port || (url.protocol === 'https:' ? '443' : '80'),
|
||||
login: app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash: app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
login: findAppProperty(app, 'username'),
|
||||
hash: findAppProperty(app, 'password'),
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -155,7 +156,7 @@ export const usenetRouter = createTRPCRouter({
|
||||
|
||||
const { origin } = new URL(app.url);
|
||||
|
||||
const apiKey = app.integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
const apiKey = findAppProperty(app, 'apiKey');
|
||||
if (!apiKey) {
|
||||
throw new Error(`API Key for app "${app.name}" is missing`);
|
||||
}
|
||||
@@ -185,7 +186,7 @@ export const usenetRouter = createTRPCRouter({
|
||||
const config = getConfig(input.configName);
|
||||
const app = config.apps.find((x) => x.id === input.appId);
|
||||
|
||||
if (!app || (app.integration?.type !== 'nzbGet' && app.integration?.type !== 'sabnzbd')) {
|
||||
if (!app || !checkIntegrationsType(app.integration, ['nzbGet', 'sabnzbd'])) {
|
||||
throw new Error(`App with ID "${input.appId}" could not be found.`);
|
||||
}
|
||||
|
||||
@@ -194,8 +195,8 @@ export const usenetRouter = createTRPCRouter({
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port || (url.protocol === 'https:' ? '443' : '80'),
|
||||
login: app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash: app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
login: findAppProperty(app, 'username'),
|
||||
hash: findAppProperty(app, 'password'),
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -211,7 +212,7 @@ export const usenetRouter = createTRPCRouter({
|
||||
});
|
||||
}
|
||||
|
||||
const apiKey = app.integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
const apiKey = findAppProperty(app, 'apiKey');
|
||||
if (!apiKey) {
|
||||
throw new Error(`API Key for app "${app.name}" is missing`);
|
||||
}
|
||||
@@ -232,7 +233,7 @@ export const usenetRouter = createTRPCRouter({
|
||||
|
||||
const app = config.apps.find((x) => x.id === input.appId);
|
||||
|
||||
if (!app || (app.integration?.type !== 'nzbGet' && app.integration?.type !== 'sabnzbd')) {
|
||||
if (!app || !checkIntegrationsType(app.integration, ['nzbGet', 'sabnzbd'])) {
|
||||
throw new Error(`App with ID "${input.appId}" could not be found.`);
|
||||
}
|
||||
|
||||
@@ -241,8 +242,8 @@ export const usenetRouter = createTRPCRouter({
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port || (url.protocol === 'https:' ? '443' : '80'),
|
||||
login: app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash: app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
login: findAppProperty(app, 'username'),
|
||||
hash: findAppProperty(app, 'password'),
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -258,7 +259,7 @@ export const usenetRouter = createTRPCRouter({
|
||||
});
|
||||
}
|
||||
|
||||
const apiKey = app.integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
const apiKey = findAppProperty(app, 'apiKey');
|
||||
if (!apiKey) {
|
||||
throw new Error(`API Key for app "${app.name}" is missing`);
|
||||
}
|
||||
@@ -281,7 +282,7 @@ export const usenetRouter = createTRPCRouter({
|
||||
|
||||
const app = config.apps.find((x) => x.id === input.appId);
|
||||
|
||||
if (!app || (app.integration?.type !== 'nzbGet' && app.integration?.type !== 'sabnzbd')) {
|
||||
if (!app || !checkIntegrationsType(app.integration, ['nzbGet', 'sabnzbd'])) {
|
||||
throw new Error(`App with ID "${input.appId}" could not be found.`);
|
||||
}
|
||||
|
||||
@@ -290,8 +291,8 @@ export const usenetRouter = createTRPCRouter({
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port || (url.protocol === 'https:' ? '443' : '80'),
|
||||
login: app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash: app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
login: findAppProperty(app, 'username'),
|
||||
hash: findAppProperty(app, 'password'),
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -340,7 +341,7 @@ export const usenetRouter = createTRPCRouter({
|
||||
};
|
||||
}
|
||||
|
||||
const apiKey = app.integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
const apiKey = findAppProperty(app, 'apiKey');
|
||||
if (!apiKey) {
|
||||
throw new Error(`API Key for app "${app.name}" is missing`);
|
||||
}
|
||||
Reference in New Issue
Block a user