🎨 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

@@ -11,7 +11,7 @@ import { NzbgetQueueItem, NzbgetStatus } from './nzbget/types';
dayjs.extend(duration);
export interface UsenetQueueRequestParams {
serviceId: string;
appId: string;
offset: number;
limit: number;
}
@@ -25,25 +25,25 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
try {
const configName = getCookie('config-name', { req });
const config = getConfig(configName?.toString() ?? 'default');
const { limit, offset, serviceId } = req.query as any as UsenetQueueRequestParams;
const { limit, offset, appId } = req.query as any as UsenetQueueRequestParams;
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 response: UsenetQueueResponse;
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);
@@ -93,12 +93,12 @@ async function Get(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);
const queue = await new Client(origin, apiKey).queue(offset, limit);
const items: UsenetQueueItem[] = queue.slots.map((slot) => {
@@ -126,7 +126,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
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(response);