You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

23 lines
763 B

/**
* POST /api/chat/send — send a message to the chat room (auth required)
*/
import { sendMessage } from "#server/service/chat"
import { getCurrentUser } from "#server/utils/context"
export default defineEventHandler(async (event) => {
const body = await readBody<{ content: string; nickname?: string; clientId?: string }>(event)
const ip = getRequestIP(event, { xForwardedFor: true }) ?? '127.0.0.1'
const user = await getCurrentUser(event)
const isAuthor = user?.role === 'admin'
const userId = user?.id
const defaultNick = user?.nickname || user?.username || undefined
const msg = await sendMessage(body?.content ?? '', ip, body?.nickname || defaultNick, body?.clientId, isAuthor, userId)
return {
code: 0,
data: msg,
}
})