mirror of
https://github.com/ajnart/homarr.git
synced 2026-03-05 20:01:02 +01:00
Indexer manager (#1807)
* indexer manager widget Co-authored-by: Tagaishi <Tagaishi@hotmail.ch>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { createTRPCRouter } from '~/server/api/trpc';
|
||||
|
||||
import { appRouter } from './routers/app';
|
||||
import { boardRouter } from './routers/board';
|
||||
import { calendarRouter } from './routers/calendar';
|
||||
@@ -8,6 +9,7 @@ import { dnsHoleRouter } from './routers/dns-hole/router';
|
||||
import { dockerRouter } from './routers/docker/router';
|
||||
import { downloadRouter } from './routers/download';
|
||||
import { iconRouter } from './routers/icon';
|
||||
import { indexerManagerRouter } from './routers/indexer-manager';
|
||||
import { inviteRouter } from './routers/invite/invite-router';
|
||||
import { mediaRequestsRouter } from './routers/media-request';
|
||||
import { mediaServerRouter } from './routers/media-server';
|
||||
@@ -30,6 +32,7 @@ export const rootRouter = createTRPCRouter({
|
||||
rss: rssRouter,
|
||||
user: userRouter,
|
||||
calendar: calendarRouter,
|
||||
indexerManager: indexerManagerRouter,
|
||||
config: configRouter,
|
||||
dashDot: dashDotRouter,
|
||||
dnsHole: dnsHoleRouter,
|
||||
@@ -45,7 +48,7 @@ export const rootRouter = createTRPCRouter({
|
||||
boards: boardRouter,
|
||||
password: passwordRouter,
|
||||
notebook: notebookRouter,
|
||||
smartHomeEntityState: smartHomeEntityStateRouter
|
||||
smartHomeEntityState: smartHomeEntityStateRouter,
|
||||
});
|
||||
|
||||
// export type definition of API
|
||||
|
||||
102
src/server/api/routers/indexer-manager.ts
Normal file
102
src/server/api/routers/indexer-manager.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import axios from 'axios';
|
||||
import Consola from 'consola';
|
||||
import { z } from 'zod';
|
||||
import { checkIntegrationsType, findAppProperty } from '~/tools/client/app-properties';
|
||||
import { getConfig } from '~/tools/config/getConfig';
|
||||
import { IntegrationType } from '~/types/app';
|
||||
|
||||
import { createTRPCRouter, protectedProcedure, publicProcedure } from '../trpc';
|
||||
|
||||
export const indexerManagerRouter = createTRPCRouter({
|
||||
indexers: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
configName: z.string(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input }) => {
|
||||
const config = getConfig(input.configName);
|
||||
const indexerAppIntegrationTypes = ['prowlarr'] as const satisfies readonly IntegrationType[];
|
||||
const app = config.apps.find((app) =>
|
||||
checkIntegrationsType(app.integration, indexerAppIntegrationTypes)
|
||||
)!;
|
||||
const apiKey = findAppProperty(app, 'apiKey');
|
||||
if (!app || !apiKey) {
|
||||
Consola.error(
|
||||
`Failed to process request to indexer app (${app.id}): API key not found. Please check the configuration.`
|
||||
);
|
||||
}
|
||||
|
||||
const appUrl = new URL(app.url);
|
||||
const data = await axios
|
||||
.get(`${appUrl.origin}/api/v1/indexer`, {
|
||||
headers: {
|
||||
'X-Api-Key': apiKey,
|
||||
},
|
||||
})
|
||||
.then((res) => res.data);
|
||||
return data;
|
||||
}),
|
||||
|
||||
statuses: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
configName: z.string(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input }) => {
|
||||
const config = getConfig(input.configName);
|
||||
const indexerAppIntegrationTypes = ['prowlarr'] as const satisfies readonly IntegrationType[];
|
||||
const app = config.apps.find((app) =>
|
||||
checkIntegrationsType(app.integration, indexerAppIntegrationTypes)
|
||||
)!;
|
||||
const apiKey = findAppProperty(app, 'apiKey');
|
||||
if (!app || !apiKey) {
|
||||
Consola.error(
|
||||
`Failed to process request to indexer app (${app.id}): API key not found. Please check the configuration.`
|
||||
);
|
||||
}
|
||||
|
||||
const appUrl = new URL(app.url);
|
||||
const data = await axios
|
||||
.get(`${appUrl.origin}/api/v1/indexerstatus`, {
|
||||
headers: {
|
||||
'X-Api-Key': apiKey,
|
||||
},
|
||||
})
|
||||
.then((res) => res.data);
|
||||
return data;
|
||||
}),
|
||||
|
||||
testAllIndexers: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
configName: z.string(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
const config = getConfig(input.configName);
|
||||
const indexerAppIntegrationTypes = ['prowlarr'] as const satisfies readonly IntegrationType[];
|
||||
const app = config.apps.find((app) =>
|
||||
checkIntegrationsType(app.integration, indexerAppIntegrationTypes)
|
||||
)!;
|
||||
const apiKey = findAppProperty(app, 'apiKey');
|
||||
if (!app || !apiKey) {
|
||||
Consola.error(
|
||||
`failed to process request to app '${app?.integration}' (${app?.id}). Please check api key`
|
||||
);
|
||||
}
|
||||
|
||||
const appUrl = new URL(app.url);
|
||||
const result = await axios
|
||||
.post(`${appUrl.origin}/api/v1/indexer/testall`, null, {
|
||||
headers: {
|
||||
'X-Api-Key': apiKey,
|
||||
},
|
||||
})
|
||||
.then((res) => res.data)
|
||||
.catch((err: any) => err.response.data);
|
||||
|
||||
return result;
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user