feat(i18n): implement new locale resolution logic and service layer
This commit is contained in:
+11
-3
@@ -11,11 +11,13 @@ import { DomainError } from "../domain/errors";
|
||||
|
||||
const inputSchema = z.object({
|
||||
provider: z.enum(["gemini", "openai", "groq", "ollama"]),
|
||||
model: z.string().trim().max(200).optional(),
|
||||
apiKey: z.string().trim().max(4_096).optional(),
|
||||
});
|
||||
|
||||
export type PublicAiSettings = {
|
||||
provider: AiProvider;
|
||||
model: string | null;
|
||||
hasApiKey: boolean;
|
||||
};
|
||||
|
||||
@@ -29,6 +31,7 @@ export function getPublicAiSettings(actor: DomainActor): PublicAiSettings {
|
||||
|
||||
return {
|
||||
provider: row?.provider ?? "gemini",
|
||||
model: row?.model ?? null,
|
||||
hasApiKey: Boolean(row?.encryptedApiKey),
|
||||
};
|
||||
}
|
||||
@@ -51,26 +54,31 @@ export function updateAiSettings(actor: DomainActor, input: unknown): PublicAiSe
|
||||
: parsed.data.apiKey
|
||||
? encryptSecret(parsed.data.apiKey)
|
||||
: current?.encryptedApiKey ?? null;
|
||||
const model = parsed.data.model || null;
|
||||
|
||||
db.insert(userAiSettings)
|
||||
.values({
|
||||
ownerUserId: scope.ownerUserId,
|
||||
provider: parsed.data.provider,
|
||||
model: null,
|
||||
model,
|
||||
encryptedApiKey,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: userAiSettings.ownerUserId,
|
||||
set: {
|
||||
provider: parsed.data.provider,
|
||||
model: null,
|
||||
model,
|
||||
encryptedApiKey,
|
||||
updatedAt: sqlNow(),
|
||||
},
|
||||
})
|
||||
.run();
|
||||
|
||||
return { provider: parsed.data.provider, hasApiKey: Boolean(encryptedApiKey) };
|
||||
return {
|
||||
provider: parsed.data.provider,
|
||||
model,
|
||||
hasApiKey: Boolean(encryptedApiKey),
|
||||
};
|
||||
}
|
||||
|
||||
export function getAiRuntimeSettings(actor: DomainActor): {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { eq } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import type { ColorMode } from "@/lib/color-mode";
|
||||
import { getSqliteConnection } from "@/server/db/client";
|
||||
import { userPreferences } from "@/server/db/schema";
|
||||
import { instanceLocales, userPreferences } from "@/server/db/schema";
|
||||
import { assertEnabledActor, type DomainActor } from "@/server/domain/actor";
|
||||
import { DomainError } from "@/server/domain/errors";
|
||||
|
||||
@@ -82,6 +82,18 @@ export function updateLanguagePreference(
|
||||
}
|
||||
|
||||
const { db } = getSqliteConnection();
|
||||
const locale = db
|
||||
.select({
|
||||
code: instanceLocales.code,
|
||||
status: instanceLocales.status,
|
||||
})
|
||||
.from(instanceLocales)
|
||||
.where(eq(instanceLocales.code, parsed.data.language))
|
||||
.get();
|
||||
if (!locale || locale.status !== "active") {
|
||||
throw new DomainError("VALIDATION_ERROR", "Dil tercihi aktif bir dil olmalıdır.");
|
||||
}
|
||||
|
||||
db.insert(userPreferences)
|
||||
.values({
|
||||
ownerUserId: actor.authUserId,
|
||||
|
||||
Reference in New Issue
Block a user