file switching logic
This commit is contained in:
@ -28,9 +28,6 @@ const handshakeSchema = z.object({
|
||||
|
||||
io.use(async (socket, next) => {
|
||||
const q = socket.handshake.query
|
||||
|
||||
console.log("middleware")
|
||||
|
||||
const parseQuery = handshakeSchema.safeParse(q)
|
||||
|
||||
if (!parseQuery.success) {
|
||||
@ -40,12 +37,9 @@ io.use(async (socket, next) => {
|
||||
}
|
||||
|
||||
const { sandboxId, userId } = parseQuery.data
|
||||
|
||||
const dbUser = await fetch(`http://localhost:8787/api/user?id=${userId}`)
|
||||
const dbUserJSON = (await dbUser.json()) as User
|
||||
|
||||
console.log("dbUserJSON:", dbUserJSON)
|
||||
|
||||
if (!dbUserJSON) {
|
||||
console.log("DB error.")
|
||||
next(new Error("DB error."))
|
||||
@ -77,6 +71,13 @@ io.on("connection", async (socket) => {
|
||||
const sandboxFiles = await getSandboxFiles(data.id)
|
||||
|
||||
socket.emit("loaded", sandboxFiles.files)
|
||||
socket.on("getFile", (fileId: string, callback) => {
|
||||
const file = sandboxFiles.fileData.find((f) => f.id === fileId)
|
||||
if (!file) return
|
||||
|
||||
// console.log("file " + file.id + ": ", file.data)
|
||||
callback(file.data)
|
||||
})
|
||||
})
|
||||
|
||||
httpServer.listen(port, () => {
|
||||
|
Reference in New Issue
Block a user