// GoTunnel File Manager Plugin function metadata() { return { name: "file-manager", version: "1.0.0", description: "文件管理器插件", author: "GoTunnel Official", type: "app", run_at: "client" }; } function start() { log("File Manager plugin started"); } function stop() { log("File Manager plugin stopped"); } function handleConn(conn) { http.serve(conn, handleRequest); } function handleRequest(req) { var path = req.path; var method = req.method; if (path === "/api/list") { return handleList(req); } if (path === "/api/read" && method === "POST") { return handleRead(req); } return { status: 404, body: '{"error":"not found"}' }; } function handleList(req) { var dir = config("root_path") || "."; var result = fs.readDir(dir); if (result.error) { return { status: 500, body: http.json({ error: result.error }) }; } return { status: 200, body: http.json({ entries: result.entries }) }; } function handleRead(req) { var body = JSON.parse(req.body || "{}"); var path = body.path; if (!path) { return { status: 400, body: '{"error":"path required"}' }; } var result = fs.readFile(path); if (result.error) { return { status: 500, body: http.json({ error: result.error }) }; } return { status: 200, body: http.json({ content: result.data }) }; }