mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-28 01:10:54 +01:00
40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
import { getServerSettingByKeyAsync, getServerSettingsAsync, updateServerSettingByKeyAsync } from "@homarr/db/queries";
|
|
import type { ServerSettings } from "@homarr/server-settings";
|
|
import { defaultServerSettingsKeys } from "@homarr/server-settings";
|
|
import { validation, z } from "@homarr/validation";
|
|
|
|
import { createTRPCRouter, onboardingProcedure, permissionRequiredProcedure, publicProcedure } from "../trpc";
|
|
import { nextOnboardingStepAsync } from "./onboard/onboard-queries";
|
|
|
|
export const serverSettingsRouter = createTRPCRouter({
|
|
getCulture: publicProcedure.query(async ({ ctx }) => {
|
|
return await getServerSettingByKeyAsync(ctx.db, "culture");
|
|
}),
|
|
getAll: permissionRequiredProcedure.requiresPermission("admin").query(async ({ ctx }) => {
|
|
return await getServerSettingsAsync(ctx.db);
|
|
}),
|
|
saveSettings: permissionRequiredProcedure
|
|
.requiresPermission("admin")
|
|
.input(
|
|
z.object({
|
|
settingsKey: z.enum(defaultServerSettingsKeys),
|
|
value: z.record(z.string(), z.unknown()),
|
|
}),
|
|
)
|
|
.mutation(async ({ ctx, input }) => {
|
|
await updateServerSettingByKeyAsync(
|
|
ctx.db,
|
|
input.settingsKey,
|
|
input.value as ServerSettings[keyof ServerSettings],
|
|
);
|
|
}),
|
|
initSettings: onboardingProcedure
|
|
.requiresStep("settings")
|
|
.input(validation.settings.init)
|
|
.mutation(async ({ ctx, input }) => {
|
|
await updateServerSettingByKeyAsync(ctx.db, "analytics", input.analytics);
|
|
await updateServerSettingByKeyAsync(ctx.db, "crawlingAndIndexing", input.crawlingAndIndexing);
|
|
await nextOnboardingStepAsync(ctx.db, undefined);
|
|
}),
|
|
});
|