- Remove BMAD framework, IDE configs, dev screenshots, test files, internal docs, and backup files - Rename keep-notes/ to memento-note/ - Update all references from keep-notes to memento-note - Add Apache 2.0 license with Commons Clause (non-commercial restriction) - Add clean .gitignore and .env.docker.example
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 })
|
|
}
|
|
}
|