🎨 Rename "services" to "apps" in entire project

This commit is contained in:
Manuel Ruwe
2022-12-18 22:27:01 +01:00
parent 1e0a90f2ac
commit 661c05bc50
69 changed files with 661 additions and 495 deletions

View File

@@ -4,14 +4,12 @@ import duration from 'dayjs/plugin/duration';
import { NextApiRequest, NextApiResponse } from 'next';
import { Client } from 'sabnzbd-api';
import { getConfig } from '../../../../tools/config/getConfig';
import { getServiceById } from '../../../../tools/hooks/useGetServiceByType';
import { Config } from '../../../../tools/types';
import { NzbgetClient } from './nzbget/nzbget-client';
dayjs.extend(duration);
export interface UsenetResumeRequestParams {
serviceId: string;
appId: string;
nzbId?: string;
}
@@ -19,25 +17,25 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
try {
const configName = getCookie('config-name', { req });
const config = getConfig(configName?.toString() ?? 'default');
const { serviceId } = req.query as any as UsenetResumeRequestParams;
const { appId } = req.query as any as UsenetResumeRequestParams;
const service = config.services.find((x) => x.id === serviceId);
const app = config.apps.find((x) => x.id === appId);
if (!service) {
throw new Error(`Service with ID "${req.query.serviceId}" could not be found.`);
if (!app) {
throw new Error(`App with ID "${req.query.appId}" could not be found.`);
}
let result;
switch (service.integration?.type) {
switch (app.integration?.type) {
case 'nzbGet': {
const url = new URL(service.url);
const url = new URL(app.url);
const options = {
host: url.hostname,
port: url.port,
login:
service.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
hash:
service.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
};
const nzbGet = NzbgetClient(options);
@@ -54,18 +52,18 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
break;
}
case 'sabnzbd': {
const apiKey = service.integration.properties.find((x) => x.field === 'apiKey')?.value;
const apiKey = app.integration.properties.find((x) => x.field === 'apiKey')?.value;
if (!apiKey) {
throw new Error(`API Key for service "${service.name}" is missing`);
throw new Error(`API Key for app "${app.name}" is missing`);
}
const { origin } = new URL(service.url);
const { origin } = new URL(app.url);
result = await new Client(origin, apiKey).queueResume();
break;
}
default:
throw new Error(`Service type "${service.integration?.type}" unrecognized.`);
throw new Error(`App type "${app.integration?.type}" unrecognized.`);
}
return res.status(200).json(result);