- RTL: force dir=rtl on LabelFilter, NotesViewToggle, LabelManagementDialog - i18n: add missing keys (notifications, privacy, edit/preview, AI translate/undo) - Settings pages: convert to Server Components (general, appearance) + loading skeleton - AI menu: add Translate option (10 languages) + Undo AI button in toolbar - Fix: saveInline uses REST API instead of Server Action → eliminates all implicit refreshes in list mode - Fix: NotesTabsView notes sync effect preserves selected note on content changes - Fix: auto-tag suggestions now filter already-assigned labels - Fix: color change in card view uses local state (no refresh) - Fix: nav links use <Link> for prefetching (Settings, Admin) - Fix: suppress duplicate label suggestions already on note - Route: add /api/ai/translate endpoint
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { auth } from '@/auth'
|
|
import { getTagsProvider } from '@/lib/ai/factory'
|
|
import { getSystemConfig } from '@/lib/config'
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const session = await auth()
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const { text, targetLanguage } = await request.json()
|
|
|
|
if (!text || !targetLanguage) {
|
|
return NextResponse.json({ error: 'text and targetLanguage are required' }, { status: 400 })
|
|
}
|
|
|
|
const config = await getSystemConfig()
|
|
const provider = getTagsProvider(config)
|
|
|
|
const prompt = `Translate the following text to ${targetLanguage}. Return ONLY the translated text, no explanation, no preamble, no quotes:\n\n${text}`
|
|
|
|
const translatedText = await provider.generateText(prompt)
|
|
|
|
return NextResponse.json({ translatedText: translatedText.trim() })
|
|
} catch (error: any) {
|
|
return NextResponse.json({ error: error.message || 'Translation failed' }, { status: 500 })
|
|
}
|
|
}
|