This commit is contained in:
Rene Kievits
2025-10-19 22:52:32 +02:00
commit a728add8af
64 changed files with 11693 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
import express, { Router } from 'express'
import { ApiKeyModel } from '../../../models/apikey.model.ts'
import { syncWanikaniData } from '../../../services/wanikaniService.ts'
const router = express.Router()
interface ApiKeyDocument {
apiKey?: string;
}
router.get('/sync', async (req, res) => {
try {
const apiKeyDoc = await ApiKeyModel.findOne() as ApiKeyDocument | null
const apiKey = apiKeyDoc?.apiKey
console.log(apiKey, apiKeyDoc)
if (!apiKey || apiKey.trim() === '') {
return res.status(401).json({ error: 'API Key not configured. Please sync your key first.' })
}
await syncWanikaniData(apiKey)
res.json({ success: true })
} catch (err) {
console.error(err)
res.status(500).json({ error: 'Failed to sync WaniKani data' })
}
})
export default router as Router