♻️ board procedure

This commit is contained in:
Manuel
2023-08-01 12:58:32 +02:00
parent ccbf208ff0
commit bb0bcabb2e
3 changed files with 66 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ import { rssRouter } from './routers/rss';
import { usenetRouter } from './routers/usenet/router';
import { userRouter } from './routers/user';
import { weatherRouter } from './routers/weather';
import { boardRouter } from './routers/board';
/**
* This is the primary router for your server.
@@ -39,6 +40,7 @@ export const rootRouter = createTRPCRouter({
calendar: calendarRouter,
weather: weatherRouter,
invites: inviteRouter,
boards: boardRouter
});
// export type definition of API

View File

@@ -0,0 +1,25 @@
import fs from 'fs';
import { getFrontendConfig } from '~/tools/config/getFrontendConfig';
import { createTRPCRouter, publicProcedure } from '../trpc';
export const boardRouter = createTRPCRouter({
all: publicProcedure.query(async ({ ctx }) => {
const files = fs.readdirSync('./data/configs').filter((file) => file.endsWith('.json'));
return await Promise.all(
files.map(async (file) => {
const name = file.replace('.json', '');
const config = await getFrontendConfig(name);
const countApps = config.apps.length;
return {
name: name,
countApps: countApps,
countWidgets: config.widgets.length,
countCategories: config.categories.length
};
})
);
}),
});