mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 15:35:55 +01:00
🐛 Fix issue with api endpoints caused by new integration format
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import axios from 'axios';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getConfig } from '../../../tools/config/getConfig';
|
||||
import { ServiceIntegrationApiKeyType, ServiceType } from '../../../types/service';
|
||||
import { ServiceIntegrationType, ServiceType } from '../../../types/service';
|
||||
|
||||
/*async function Post(req: NextApiRequest, res: NextApiResponse) {
|
||||
// Parse req.body as a ServiceItem
|
||||
@@ -114,7 +114,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const medias = await Promise.all(
|
||||
await mediaServices.map(async (service) => {
|
||||
const integration = service.integration as ServiceIntegrationApiKeyType;
|
||||
const integration = service.integration!;
|
||||
const endpoint = IntegrationTypeEndpointMap.get(integration.type);
|
||||
if (!endpoint)
|
||||
return {
|
||||
@@ -131,14 +131,11 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const start = new Date(year, month - 1, 1); // First day of month
|
||||
const end = new Date(year, month, 0); // Last day of month
|
||||
|
||||
console.log(
|
||||
`${origin}${endpoint}?apiKey=${integration.properties.apiKey}&end=${end}&start=${start}`
|
||||
);
|
||||
const apiKey = integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
if (!apiKey) return { type: integration.type, items: [] };
|
||||
return await axios
|
||||
.get(
|
||||
`${origin}${endpoint}?apiKey=${
|
||||
integration.properties.apiKey
|
||||
}&end=${end.toISOString()}&start=${start.toISOString()}`
|
||||
`${origin}${endpoint}?apiKey=${apiKey}&end=${end.toISOString()}&start=${start.toISOString()}`
|
||||
)
|
||||
.then((x) => ({ type: integration.type, items: x.data as any[] }));
|
||||
})
|
||||
@@ -160,5 +157,3 @@ const IntegrationTypeEndpointMap = new Map<ServiceIntegrationType['type'], strin
|
||||
['lidarr', '/api/v1/calendar'],
|
||||
['readarr', '/api/v1/calendar'],
|
||||
]);
|
||||
|
||||
type ServiceIntegrationType = Exclude<ServiceType['integration'], undefined>;
|
||||
|
||||
@@ -11,8 +11,6 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
timeout: 1,
|
||||
});
|
||||
|
||||
console.log(response);
|
||||
|
||||
// Return 200 if the alive property is true
|
||||
if (response.alive) {
|
||||
return res.status(200).end();
|
||||
|
||||
@@ -3,12 +3,12 @@ import dayjs from 'dayjs';
|
||||
import duration from 'dayjs/plugin/duration';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { Client } from 'sabnzbd-api';
|
||||
import { UsenetHistoryItem } from '../../../../modules';
|
||||
import { getServiceById } from '../../../../tools/hooks/useGetServiceByType';
|
||||
import { Config } from '../../../../tools/types';
|
||||
import { NzbgetHistoryItem } from './nzbget/types';
|
||||
import { NzbgetClient } from './nzbget/nzbget-client';
|
||||
import { getConfig } from '../../../../tools/config/getConfig';
|
||||
import { UsenetHistoryItem } from '../../../../components/Dashboard/Tiles/UseNet/types';
|
||||
|
||||
dayjs.extend(duration);
|
||||
|
||||
@@ -42,8 +42,10 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port,
|
||||
login: service.integration.properties.username,
|
||||
hash: service.integration.properties.password,
|
||||
login:
|
||||
service.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash:
|
||||
service.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -79,14 +81,12 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
case 'sabnzbd': {
|
||||
const { origin } = new URL(service.url);
|
||||
|
||||
if (!service.integration.properties.apiKey) {
|
||||
const apiKey = service.integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
if (!apiKey) {
|
||||
throw new Error(`API Key for service "${service.name}" is missing`);
|
||||
}
|
||||
|
||||
const history = await new Client(origin, service.integration.properties.apiKey).history(
|
||||
offset,
|
||||
limit
|
||||
);
|
||||
const history = await new Client(origin, apiKey).history(offset, limit);
|
||||
|
||||
const items: UsenetHistoryItem[] = history.slots.map((slot) => ({
|
||||
id: slot.nzo_id,
|
||||
|
||||
@@ -41,8 +41,10 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port,
|
||||
login: service.integration.properties.username,
|
||||
hash: service.integration.properties.password,
|
||||
login:
|
||||
service.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash:
|
||||
service.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -72,13 +74,14 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
break;
|
||||
}
|
||||
case 'sabnzbd': {
|
||||
if (!service.integration.properties.apiKey) {
|
||||
const apiKey = service.integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
if (!apiKey) {
|
||||
throw new Error(`API Key for service "${service.name}" is missing`);
|
||||
}
|
||||
|
||||
const { origin } = new URL(service.url);
|
||||
|
||||
const queue = await new Client(origin, service.integration.properties.apiKey).queue(0, -1);
|
||||
const queue = await new Client(origin, apiKey).queue(0, -1);
|
||||
|
||||
const [hours, minutes, seconds] = queue.timeleft.split(':');
|
||||
const eta = dayjs.duration({
|
||||
|
||||
@@ -31,8 +31,10 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port,
|
||||
login: service.integration.properties.username,
|
||||
hash: service.integration.properties.password,
|
||||
login:
|
||||
service.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash:
|
||||
service.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -49,13 +51,14 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
||||
break;
|
||||
}
|
||||
case 'sabnzbd': {
|
||||
if (!service.integration.properties.apiKey) {
|
||||
const apiKey = service.integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
if (!apiKey) {
|
||||
throw new Error(`API Key for service "${service.name}" is missing`);
|
||||
}
|
||||
|
||||
const { origin } = new URL(service.url);
|
||||
|
||||
result = await new Client(origin, service.integration.properties.apiKey).queuePause();
|
||||
result = await new Client(origin, apiKey).queuePause();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -3,7 +3,7 @@ import dayjs from 'dayjs';
|
||||
import duration from 'dayjs/plugin/duration';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { Client } from 'sabnzbd-api';
|
||||
import { UsenetQueueItem } from '../../../../modules';
|
||||
import { UsenetQueueItem } from '../../../../components/Dashboard/Tiles/UseNet/types';
|
||||
import { getConfig } from '../../../../tools/config/getConfig';
|
||||
import { NzbgetClient } from './nzbget/nzbget-client';
|
||||
import { NzbgetQueueItem, NzbgetStatus } from './nzbget/types';
|
||||
@@ -40,8 +40,10 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port,
|
||||
login: service.integration.properties.username,
|
||||
hash: service.integration.properties.password,
|
||||
login:
|
||||
service.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash:
|
||||
service.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -91,15 +93,13 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
break;
|
||||
}
|
||||
case 'sabnzbd': {
|
||||
if (!service.integration.properties.apiKey) {
|
||||
const apiKey = service.integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
if (!apiKey) {
|
||||
throw new Error(`API Key for service "${service.name}" is missing`);
|
||||
}
|
||||
|
||||
const { origin } = new URL(service.url);
|
||||
const queue = await new Client(origin, service.integration.properties.apiKey).queue(
|
||||
offset,
|
||||
limit
|
||||
);
|
||||
const queue = await new Client(origin, apiKey).queue(offset, limit);
|
||||
|
||||
const items: UsenetQueueItem[] = queue.slots.map((slot) => {
|
||||
const [hours, minutes, seconds] = slot.timeleft.split(':');
|
||||
|
||||
@@ -34,8 +34,10 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
||||
const options = {
|
||||
host: url.hostname,
|
||||
port: url.port,
|
||||
login: service.integration.properties.username,
|
||||
hash: service.integration.properties.password,
|
||||
login:
|
||||
service.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||
hash:
|
||||
service.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||
};
|
||||
|
||||
const nzbGet = NzbgetClient(options);
|
||||
@@ -52,13 +54,14 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
||||
break;
|
||||
}
|
||||
case 'sabnzbd': {
|
||||
if (!service.integration.properties.apiKey) {
|
||||
const apiKey = service.integration.properties.find((x) => x.field === 'apiKey')?.value;
|
||||
if (!apiKey) {
|
||||
throw new Error(`API Key for service "${service.name}" is missing`);
|
||||
}
|
||||
|
||||
const { origin } = new URL(service.url);
|
||||
|
||||
result = await new Client(origin, service.integration.properties.apiKey).queueResume();
|
||||
result = await new Client(origin, apiKey).queueResume();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user