|
|
@ -1,6 +1,7 @@
|
|
|
|
import { getRoom, updateRoom } from '@/db'
|
|
|
|
import { getRoom, updateRoom } from '@/db'
|
|
|
|
import { addRoomUpdateListener, removeRoomUpdateListener } from '@/db/events'
|
|
|
|
import { addRoomUpdateListener, removeRoomUpdateListener } from '@/db/events'
|
|
|
|
import type { RoomData } from '@/db/model'
|
|
|
|
import type { RoomData } from '@/db/model'
|
|
|
|
|
|
|
|
import { getSession } from '@/db/sessions'
|
|
|
|
import type { APIRoute } from 'astro'
|
|
|
|
import type { APIRoute } from 'astro'
|
|
|
|
|
|
|
|
|
|
|
|
function sseHandler(roomId: string) {
|
|
|
|
function sseHandler(roomId: string) {
|
|
|
@ -54,7 +55,7 @@ export const GET: APIRoute = async ({ params, url }) => {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const POST: APIRoute = async ({ params, request }) => {
|
|
|
|
export const POST: APIRoute = async ({ params, request, cookies }) => {
|
|
|
|
const { id: roomId } = params
|
|
|
|
const { id: roomId } = params
|
|
|
|
if (!roomId) {
|
|
|
|
if (!roomId) {
|
|
|
|
return new Response('Invalid room id', { status: 400 })
|
|
|
|
return new Response('Invalid room id', { status: 400 })
|
|
|
@ -65,6 +66,17 @@ export const POST: APIRoute = async ({ params, request }) => {
|
|
|
|
return new Response('Room not found', { status: 404 })
|
|
|
|
return new Response('Room not found', { status: 404 })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check auth
|
|
|
|
|
|
|
|
const sid = cookies.get('sid')
|
|
|
|
|
|
|
|
if (!sid) {
|
|
|
|
|
|
|
|
return new Response('Unauthorized', { status: 401 })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sessionRoom = getSession(sid.value)
|
|
|
|
|
|
|
|
if (sessionRoom !== roomId) {
|
|
|
|
|
|
|
|
return new Response('Unauthorized', { status: 401 })
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const newRoom = (await request.json()) as RoomData
|
|
|
|
const newRoom = (await request.json()) as RoomData
|
|
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|