|
|
@@ -210,43 +210,6 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- // 批量生成训练码
|
|
|
- xunlianCodesRoutes.post('/batch-generate', withAuth, async (c) => {
|
|
|
- try {
|
|
|
- const apiClient = c.get('apiClient')
|
|
|
- const body = await c.req.json()
|
|
|
-
|
|
|
- const { count, prefix } = body
|
|
|
- if (!count || count <= 0) {
|
|
|
- return c.json({ error: '无效的生成数量' }, 400)
|
|
|
- }
|
|
|
-
|
|
|
- const codes = []
|
|
|
- const now = new Date()
|
|
|
-
|
|
|
- for (let i = 0; i < count; i++) {
|
|
|
- const code = prefix ? `${prefix}-${generateRandomCode(8)}` : generateRandomCode(10)
|
|
|
- codes.push({
|
|
|
- code,
|
|
|
- status: 'active',
|
|
|
- created_at: now,
|
|
|
- updated_at: now
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- // 批量插入
|
|
|
- await apiClient.database.table('xunlian_codes').insert(codes)
|
|
|
-
|
|
|
- return c.json({
|
|
|
- message: `成功生成${count}个训练码`,
|
|
|
- count
|
|
|
- })
|
|
|
- } catch (error) {
|
|
|
- console.error('批量生成训练码失败:', error)
|
|
|
- return c.json({ error: '批量生成训练码失败' }, 500)
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
// 更新训练码状态
|
|
|
xunlianCodesRoutes.put('/:id/status', withAuth, async (c) => {
|
|
|
try {
|
|
|
@@ -292,14 +255,4 @@ export function createXunlianCodesRoutes(withAuth: WithAuth) {
|
|
|
})
|
|
|
|
|
|
return xunlianCodesRoutes
|
|
|
-}
|
|
|
-
|
|
|
-// 生成随机训练码
|
|
|
-function generateRandomCode(length: number) {
|
|
|
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
|
- let result = ''
|
|
|
- for (let i = 0; i < length; i++) {
|
|
|
- result += chars.charAt(Math.floor(Math.random() * chars.length))
|
|
|
- }
|
|
|
- return result
|
|
|
}
|