-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
prisma/migrations/20221103223653_add_settings_schema/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
-- CreateTable | ||
CREATE TABLE "Settings" ( | ||
"id" SERIAL NOT NULL, | ||
"telegramEnabled" BOOLEAN NOT NULL DEFAULT false, | ||
"telegramToken" TEXT, | ||
"telegramChatId" TEXT, | ||
"telegramSendSilently" BOOLEAN NOT NULL DEFAULT false, | ||
"appriseEnabled" BOOLEAN NOT NULL DEFAULT false, | ||
"appriseHost" TEXT, | ||
"appriseUrls" TEXT [] DEFAULT ARRAY [] :: TEXT [], | ||
"komgaEnabled" BOOLEAN NOT NULL DEFAULT false, | ||
"komgaHost" TEXT, | ||
"komgaUser" TEXT, | ||
"komgaPassword" TEXT, | ||
CONSTRAINT "Settings_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
INSERT INTO | ||
"Settings" ( | ||
id, | ||
"telegramEnabled", | ||
"telegramToken", | ||
"telegramChatId", | ||
"telegramSendSilently", | ||
"appriseEnabled", | ||
"appriseHost", | ||
"appriseUrls", | ||
"komgaEnabled", | ||
"komgaHost", | ||
"komgaUser", | ||
"komgaPassword" | ||
) | ||
VALUES | ||
( | ||
1, | ||
false, | ||
null, | ||
null, | ||
false, | ||
false, | ||
null, | ||
'{}', | ||
false, | ||
null, | ||
null, | ||
null | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { z } from 'zod'; | ||
import { getMangalConfig, setMangalConfig } from '../../utils/mangal'; | ||
import { t } from '../trpc'; | ||
|
||
export const settingsRouter = t.router({ | ||
query: t.procedure.query(async ({ ctx }) => { | ||
const mangalConfig = (await getMangalConfig()).sort((a, b) => a.key.localeCompare(b.key)); | ||
const appConfig = await ctx.prisma.settings.findFirstOrThrow(); | ||
return { | ||
mangalConfig, | ||
appConfig, | ||
}; | ||
}), | ||
update: t.procedure | ||
.input( | ||
z.object({ | ||
key: z.string().min(1), | ||
value: z.string().or(z.boolean()).or(z.number()).or(z.string().array()), | ||
updateType: z.literal('mangal').or(z.literal('app')), | ||
}), | ||
) | ||
.mutation(async ({ ctx, input }) => { | ||
const { key, value, updateType } = input; | ||
if (updateType === 'mangal') { | ||
await setMangalConfig(key, value); | ||
} else if (updateType === 'app') { | ||
const appConfig = await ctx.prisma.settings.findFirstOrThrow(); | ||
await ctx.prisma.settings.update({ | ||
where: { | ||
id: appConfig.id, | ||
}, | ||
data: { | ||
[key]: value, | ||
}, | ||
}); | ||
} | ||
}), | ||
}); |