Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 5cb4457

Browse files
committed
feat: add settings table
1 parent f8eb9c6 commit 5cb4457

File tree

6 files changed

+105
-0
lines changed

6 files changed

+105
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"express": "^4.18.2",
5959
"framer-motion": "^7.6.1",
6060
"mantine-datatable": "^1.7.9",
61+
"nanoid": "v3",
6162
"next": "12.3.1",
6263
"node-telegram-bot-api": "^0.59.0",
6364
"pino": "^8.6.1",

pnpm-lock.yaml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-- CreateTable
2+
CREATE TABLE "Settings" (
3+
"id" SERIAL NOT NULL,
4+
"telegramEnabled" BOOLEAN NOT NULL DEFAULT false,
5+
"telegramToken" TEXT,
6+
"telegramChatId" TEXT,
7+
"telegramSendSilently" BOOLEAN NOT NULL DEFAULT false,
8+
"appriseEnabled" BOOLEAN NOT NULL DEFAULT false,
9+
"appriseHost" TEXT,
10+
"appriseUrls" TEXT [] DEFAULT ARRAY [] :: TEXT [],
11+
"komgaEnabled" BOOLEAN NOT NULL DEFAULT false,
12+
"komgaHost" TEXT,
13+
"komgaUser" TEXT,
14+
"komgaPassword" TEXT,
15+
CONSTRAINT "Settings_pkey" PRIMARY KEY ("id")
16+
);
17+
18+
INSERT INTO
19+
"Settings" (
20+
id,
21+
"telegramEnabled",
22+
"telegramToken",
23+
"telegramChatId",
24+
"telegramSendSilently",
25+
"appriseEnabled",
26+
"appriseHost",
27+
"appriseUrls",
28+
"komgaEnabled",
29+
"komgaHost",
30+
"komgaUser",
31+
"komgaPassword"
32+
)
33+
VALUES
34+
(
35+
1,
36+
false,
37+
null,
38+
null,
39+
false,
40+
false,
41+
null,
42+
'{}',
43+
false,
44+
null,
45+
null,
46+
null
47+
);

prisma/schema.prisma

+15
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,18 @@ model Metadata {
5757
synonyms String[] @default([])
5858
urls String[] @default([])
5959
}
60+
61+
model Settings {
62+
id Int @id @default(autoincrement())
63+
telegramEnabled Boolean @default(false)
64+
telegramToken String?
65+
telegramChatId String?
66+
telegramSendSilently Boolean @default(false)
67+
appriseEnabled Boolean @default(false)
68+
appriseHost String?
69+
appriseUrls String[] @default([])
70+
komgaEnabled Boolean @default(false)
71+
komgaHost String?
72+
komgaUser String?
73+
komgaPassword String?
74+
}

src/server/trpc/router/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { t } from '../trpc';
22

33
import { libraryRouter } from './library';
44
import { mangaRouter } from './manga';
5+
import { settingsRouter } from './settings';
56

67
export const appRouter = t.router({
78
library: libraryRouter,
89
manga: mangaRouter,
10+
settings: settingsRouter,
911
});
1012

1113
// export type definition of API

src/server/trpc/router/settings.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { z } from 'zod';
2+
import { getMangalConfig, setMangalConfig } from '../../utils/mangal';
3+
import { t } from '../trpc';
4+
5+
export const settingsRouter = t.router({
6+
query: t.procedure.query(async ({ ctx }) => {
7+
const mangalConfig = (await getMangalConfig()).sort((a, b) => a.key.localeCompare(b.key));
8+
const appConfig = await ctx.prisma.settings.findFirstOrThrow();
9+
return {
10+
mangalConfig,
11+
appConfig,
12+
};
13+
}),
14+
update: t.procedure
15+
.input(
16+
z.object({
17+
key: z.string().min(1),
18+
value: z.string().or(z.boolean()).or(z.number()).or(z.string().array()),
19+
updateType: z.literal('mangal').or(z.literal('app')),
20+
}),
21+
)
22+
.mutation(async ({ ctx, input }) => {
23+
const { key, value, updateType } = input;
24+
if (updateType === 'mangal') {
25+
await setMangalConfig(key, value);
26+
} else if (updateType === 'app') {
27+
const appConfig = await ctx.prisma.settings.findFirstOrThrow();
28+
await ctx.prisma.settings.update({
29+
where: {
30+
id: appConfig.id,
31+
},
32+
data: {
33+
[key]: value,
34+
},
35+
});
36+
}
37+
}),
38+
});

0 commit comments

Comments
 (0)