Download src/app/api/sync/push/route.ts from HonzaH/Letschat: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/HonzaH/Letschat/resolve/main/src/app/api/sync/push/route.ts
- Command line
-
hf download hf://spaces/HonzaH/Letschat/src/app/api/sync/push/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/HonzaH/Letschat/resolve/main/src/app/api/sync/push/route.ts
1.33 kB
| import { NextRequest, NextResponse } from 'next/server' | |
| import { insertMessage, updateRoom } from 'lib/persistence' | |
| import { logEvent } from 'lib/logger' | |
| export async function POST(request: NextRequest) { | |
| try { | |
| const body = await request.json() | |
| const messages = Array.isArray(body?.messages) ? body.messages : [] | |
| let inserted = 0 | |
| for (const msg of messages) { | |
| const res = await insertMessage({ | |
| id: msg.id, | |
| room_id: msg.room_id, | |
| code_id: msg.code_id, | |
| user_id: msg.user_id || null, | |
| content: msg.content, | |
| image_url: msg.image_url || null, | |
| created_at: msg.created_at || new Date().toISOString() | |
| }) | |
| if (res) { | |
| inserted++ | |
| await updateRoom(msg.room_id, { date_last_message: new Date().toISOString() }) | |
| } | |
| } | |
| if (inserted > 0) { | |
| await logEvent({ | |
| module: 'sync', | |
| operation: 'push_messages', | |
| data: { inserted }, | |
| ip: (request as any).headers?.get?.('x-forwarded-for') || null, | |
| userAgent: (request as any).headers?.get?.('user-agent') || null | |
| }) | |
| } | |
| return NextResponse.json({ success: true, inserted }) | |
| } catch (error) { | |
| console.error('Sync push error:', error) | |
| return NextResponse.json({ error: 'Vnitřní chyba serveru' }, { status: 500 }) | |
| } | |
| } | |