mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-13 06:32:03 +00:00
Switch defaultLocale from "de" to "en" and make English the code-level language throughout. All ~145 hardcoded German strings translated: - API error messages (52 routes) now return English - Zod validation messages in English - Classification/analytics functions return English categories - Notification type labels in English - Component strings use i18n t() calls (heatmap, mood chart, medication form, intake history, password strength, insights card) - ~50 new i18n keys in both de.json and en.json Route migration: - /stimmung → /mood, /zielwerte → /targets (new pages) - 301 redirects in proxy.ts for legacy URLs - Sidebar + bottom nav updated Bump version to 1.0.1.
93 lines
2.3 KiB
TypeScript
93 lines
2.3 KiB
TypeScript
import { prisma } from "@/lib/db";
|
|
import { apiSuccess, apiError, safeJson } from "@/lib/api-response";
|
|
import { ntfySettingsSchema } from "@/lib/validations/notifications";
|
|
import { encrypt, decrypt } from "@/lib/crypto";
|
|
import { NextRequest } from "next/server";
|
|
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
|
import { annotate } from "@/lib/logging/context";
|
|
|
|
/**
|
|
* GET: Return current ntfy config (without auth token).
|
|
* PUT: Update ntfy config.
|
|
*/
|
|
export const GET = apiHandler(async () => {
|
|
const { user } = await requireAuth();
|
|
|
|
const channel = await prisma.notificationChannel.findUnique({
|
|
where: {
|
|
userId_type: { userId: user.id, type: "NTFY" },
|
|
},
|
|
});
|
|
|
|
if (!channel) {
|
|
return apiSuccess({
|
|
enabled: false,
|
|
serverUrl: "https://ntfy.sh",
|
|
topic: "",
|
|
hasAuthToken: false,
|
|
});
|
|
}
|
|
|
|
const config = JSON.parse(decrypt(channel.config)) as {
|
|
serverUrl: string;
|
|
topic: string;
|
|
authToken?: string;
|
|
};
|
|
|
|
annotate({ action: { name: "settings.ntfy.get" } });
|
|
|
|
return apiSuccess({
|
|
enabled: channel.enabled,
|
|
serverUrl: config.serverUrl,
|
|
topic: config.topic,
|
|
hasAuthToken: !!config.authToken,
|
|
});
|
|
});
|
|
|
|
export const PUT = apiHandler(async (request: NextRequest) => {
|
|
const { user } = await requireAuth();
|
|
|
|
const { data: body, error: jsonError } = await safeJson(request);
|
|
|
|
if (jsonError) return jsonError;
|
|
const parsed = ntfySettingsSchema.safeParse(body);
|
|
if (!parsed.success) return apiError("Invalid data", 422);
|
|
|
|
const { serverUrl, topic, authToken, enabled } = parsed.data;
|
|
|
|
if (enabled && (!serverUrl || !topic)) {
|
|
return apiError(
|
|
"Server URL and topic are required when ntfy is enabled",
|
|
422,
|
|
);
|
|
}
|
|
|
|
const config = JSON.stringify({
|
|
serverUrl: serverUrl || "https://ntfy.sh",
|
|
topic: topic || "",
|
|
...(authToken ? { authToken } : {}),
|
|
});
|
|
|
|
const encryptedConfig = encrypt(config);
|
|
|
|
await prisma.notificationChannel.upsert({
|
|
where: {
|
|
userId_type: { userId: user.id, type: "NTFY" },
|
|
},
|
|
create: {
|
|
userId: user.id,
|
|
type: "NTFY",
|
|
enabled,
|
|
config: encryptedConfig,
|
|
},
|
|
update: {
|
|
enabled,
|
|
config: encryptedConfig,
|
|
},
|
|
});
|
|
|
|
annotate({ action: { name: "settings.ntfy.update" }, meta: { enabled } });
|
|
|
|
return apiSuccess({ saved: true });
|
|
});
|