module.exports = [
"[project]/.next-internal/server/app/api/room/add/route/actions.js [app-rsc] (server actions loader, ecmascript)", ((__turbopack_context__, module, exports) => {

}),
"[externals]/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-route-turbo.runtime.dev.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/compiled/next-server/app-route-turbo.runtime.dev.js", () => require("next/dist/compiled/next-server/app-route-turbo.runtime.dev.js"));

module.exports = mod;
}),
"[externals]/next/dist/compiled/@opentelemetry/api [external] (next/dist/compiled/@opentelemetry/api, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/compiled/@opentelemetry/api", () => require("next/dist/compiled/@opentelemetry/api"));

module.exports = mod;
}),
"[externals]/next/dist/compiled/next-server/app-page-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-page-turbo.runtime.dev.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/compiled/next-server/app-page-turbo.runtime.dev.js", () => require("next/dist/compiled/next-server/app-page-turbo.runtime.dev.js"));

module.exports = mod;
}),
"[externals]/next/dist/server/app-render/work-unit-async-storage.external.js [external] (next/dist/server/app-render/work-unit-async-storage.external.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/server/app-render/work-unit-async-storage.external.js", () => require("next/dist/server/app-render/work-unit-async-storage.external.js"));

module.exports = mod;
}),
"[externals]/next/dist/server/app-render/work-async-storage.external.js [external] (next/dist/server/app-render/work-async-storage.external.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/server/app-render/work-async-storage.external.js", () => require("next/dist/server/app-render/work-async-storage.external.js"));

module.exports = mod;
}),
"[externals]/next/dist/shared/lib/no-fallback-error.external.js [external] (next/dist/shared/lib/no-fallback-error.external.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/shared/lib/no-fallback-error.external.js", () => require("next/dist/shared/lib/no-fallback-error.external.js"));

module.exports = mod;
}),
"[externals]/next/dist/server/app-render/after-task-async-storage.external.js [external] (next/dist/server/app-render/after-task-async-storage.external.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/server/app-render/after-task-async-storage.external.js", () => require("next/dist/server/app-render/after-task-async-storage.external.js"));

module.exports = mod;
}),
"[externals]/next/dist/server/app-render/action-async-storage.external.js [external] (next/dist/server/app-render/action-async-storage.external.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/server/app-render/action-async-storage.external.js", () => require("next/dist/server/app-render/action-async-storage.external.js"));

module.exports = mod;
}),
"[externals]/path [external] (path, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("path", () => require("path"));

module.exports = mod;
}),
"[externals]/fs/promises [external] (fs/promises, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("fs/promises", () => require("fs/promises"));

module.exports = mod;
}),
"[project]/src/server/db/index.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
"use strict";

// server/db/index.ts
__turbopack_context__.s([
    "addMessage",
    ()=>addMessage,
    "addRoom",
    ()=>addRoom,
    "deleteRoom",
    ()=>deleteRoom,
    "getRoomMessages",
    ()=>getRoomMessages,
    "getUpdatedMessages",
    ()=>getUpdatedMessages,
    "listRoom",
    ()=>listRoom,
    "loadDatabase",
    ()=>loadDatabase,
    "saveDatabase",
    ()=>saveDatabase
]);
var __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/path [external] (path, cjs)");
var __TURBOPACK__imported__module__$5b$externals$5d2f$fs$2f$promises__$5b$external$5d$__$28$fs$2f$promises$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/fs/promises [external] (fs/promises, cjs)");
;
;
// 数据库文件路径
const DB_PATH = __TURBOPACK__imported__module__$5b$externals$5d2f$path__$5b$external$5d$__$28$path$2c$__cjs$29$__["default"].join(process.cwd(), 'temp-db.json');
// 初始化数据库
let db = {
    rooms: [],
    messages: {},
    nextRoomId: 1,
    nextMessageId: 1
};
const loadDatabase = async ()=>{
    try {
        const data = await __TURBOPACK__imported__module__$5b$externals$5d2f$fs$2f$promises__$5b$external$5d$__$28$fs$2f$promises$2c$__cjs$29$__["default"].readFile(DB_PATH, 'utf-8');
        db = JSON.parse(data);
        console.log("数据库已加载");
    } catch (error) {
        console.log("创建新数据库");
        await saveDatabase();
    }
};
const saveDatabase = async ()=>{
    await __TURBOPACK__imported__module__$5b$externals$5d2f$fs$2f$promises__$5b$external$5d$__$28$fs$2f$promises$2c$__cjs$29$__["default"].writeFile(DB_PATH, JSON.stringify(db, null, 2));
};
const addRoom = async (roomName, user)=>{
    const roomId = db.nextRoomId++;
    const newRoom = {
        roomId,
        roomName,
        lastMessage: null,
        creater: user
    };
    db.rooms.push(newRoom);
    db.messages[roomId] = [];
    await saveDatabase();
    console.log("房间添加成功:");
    return roomId;
};
const listRoom = ()=>{
    return db.rooms.map((room)=>{
        const roomMessages = db.messages[room.roomId] || [];
        const lastMessage = roomMessages.length > 0 ? roomMessages[roomMessages.length - 1] : null;
        return {
            roomId: room.roomId,
            roomName: room.roomName,
            lastMessage: lastMessage
        };
    });
};
const deleteRoom = async (roomId, user)=>{
    try {
        console.log(`尝试删除房间 ${roomId}，操作用户: ${user}`);
        // 查找房间
        const roomIndex = db.rooms.findIndex((room)=>room.roomId === roomId);
        if (roomIndex === -1) {
            throw new Error(`房间 ${roomId} 不存在`);
        }
        const room = db.rooms[roomIndex];
        // 验证用户权限 - 只有创建者可以删除房间
        if (room.creater !== user) {
            throw new Error(`用户 ${user} 无权删除房间 ${roomId}`);
        }
        // 删除房间
        db.rooms.splice(roomIndex, 1);
        // 删除相关消息
        if (db.messages[roomId]) {
            delete db.messages[roomId];
        }
        // 保存数据库
        await saveDatabase();
        console.log(`房间 ${roomId} 删除成功`);
    } catch (error) {
        console.error(`删除房间 ${roomId} 失败:`, error);
        throw error; // 重新抛出错误供API层处理
    }
};
const getRoomMessages = (roomId)=>{
    // 验证房间是否存在
    const roomExists = db.rooms.some((room)=>room.roomId === roomId);
    if (!roomExists) {
        throw new Error(`房间 ${roomId} 不存在`);
    }
    // 返回该房间的消息数组，如果不存在则返回空数组
    return db.messages[roomId] || [];
};
const addMessage = async (roomId, content, sender)=>{
    try {
        console.log(`添加消息到房间 ${roomId}，发送者: ${sender}`);
        // 验证房间是否存在
        const room = db.rooms.find((r)=>r.roomId === roomId);
        if (!room) {
            throw new Error(`房间 ${roomId} 不存在`);
        }
        // 创建消息对象
        const messageId = db.nextMessageId++;
        const timestamp = Date.now();
        const newMessage = {
            messageId,
            roomId,
            sender,
            content,
            time: timestamp
        };
        // 添加到消息列表
        if (!db.messages[roomId]) {
            db.messages[roomId] = [];
        }
        db.messages[roomId].push(newMessage);
        // 保存数据库
        await saveDatabase();
        console.log(`消息添加成功: ${content.substring(0, 20)}...`);
        return newMessage;
    } catch (error) {
        console.error(`添加消息失败:`, error);
        throw error;
    }
};
const getUpdatedMessages = async (roomId, sinceMessageId)=>{
    try {
        console.log(`获取房间 ${roomId} 的消息更新，起始消息ID: ${sinceMessageId}`);
        // 验证房间是否存在
        const roomExists = db.rooms.some((room)=>room.roomId === roomId);
        if (!roomExists) {
            throw new Error(`房间 ${roomId} 不存在`);
        }
        // 获取该房间的所有消息
        const roomMessages = db.messages[roomId] || [];
        // 过滤出比 sinceMessageId 新的消息
        const updatedMessages = roomMessages.filter((message)=>message.messageId > sinceMessageId);
        // 按时间排序（从旧到新）
        updatedMessages.sort((a, b)=>a.messageId - b.messageId);
        console.log(`找到 ${updatedMessages.length} 条新消息`);
        return updatedMessages;
    } catch (error) {
        console.error(`获取消息更新失败:`, error);
        throw error;
    }
};
// 初始化数据库加载
loadDatabase();
}),
"[project]/src/app/api/room/add/route.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__turbopack_context__.s([
    "DELETE",
    ()=>DELETE,
    "GET",
    ()=>GET,
    "POST",
    ()=>POST,
    "PUT",
    ()=>PUT
]);
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$next$40$15$2e$5$2e$0_react$2d$dom$40$19$2e$1$2e$0_react$40$19$2e$1$2e$0_$5f$react$40$19$2e$1$2e$0$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/node_modules/.pnpm/next@15.5.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/server.js [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$server$2f$db$2f$index$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/src/server/db/index.ts [app-route] (ecmascript)");
;
;
async function POST(request) {
    try {
        // 解析请求体
        const body = await request.json();
        const { user, roomName } = body;
        // 验证参数
        if (!user || !roomName) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$next$40$15$2e$5$2e$0_react$2d$dom$40$19$2e$1$2e$0_react$40$19$2e$1$2e$0_$5f$react$40$19$2e$1$2e$0$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                code: 2,
                message: 'Missing parameters: user and roomName are required'
            }, {
                status: 400
            });
        }
        // 添加房间 - 添加 await 关键字
        const roomId = await (0, __TURBOPACK__imported__module__$5b$project$5d2f$src$2f$server$2f$db$2f$index$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["addRoom"])(roomName, user);
        // 返回成功响应
        return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$next$40$15$2e$5$2e$0_react$2d$dom$40$19$2e$1$2e$0_react$40$19$2e$1$2e$0_$5f$react$40$19$2e$1$2e$0$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
            code: 0,
            data: {
                roomId
            }
        }, {
            status: 200
        });
    } catch (error) {
        console.error('添加房间失败:', error);
        return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$next$40$15$2e$5$2e$0_react$2d$dom$40$19$2e$1$2e$0_react$40$19$2e$1$2e$0_$5f$react$40$19$2e$1$2e$0$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
            code: 3,
            message: 'Internal server error'
        }, {
            status: 500
        });
    }
}
async function GET() {
    return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$next$40$15$2e$5$2e$0_react$2d$dom$40$19$2e$1$2e$0_react$40$19$2e$1$2e$0_$5f$react$40$19$2e$1$2e$0$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
        code: 1,
        message: 'Method not allowed. Use POST instead'
    }, {
        status: 405
    });
}
async function PUT() {
    return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$next$40$15$2e$5$2e$0_react$2d$dom$40$19$2e$1$2e$0_react$40$19$2e$1$2e$0_$5f$react$40$19$2e$1$2e$0$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
        code: 1,
        message: 'Method not allowed'
    }, {
        status: 405
    });
}
async function DELETE() {
    return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f2e$pnpm$2f$next$40$15$2e$5$2e$0_react$2d$dom$40$19$2e$1$2e$0_react$40$19$2e$1$2e$0_$5f$react$40$19$2e$1$2e$0$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
        code: 1,
        message: 'Method not allowed'
    }, {
        status: 405
    });
}
}),
];

//# sourceMappingURL=%5Broot-of-the-server%5D__c240adb6._.js.map