From e38551dfc225c48891efb61ef70c9589147f47cd Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Fri, 20 Feb 2026 01:54:59 -0500 Subject: [PATCH] feat: Update command polling endpoint to support combined eval and legacy commands for turtles --- server/server.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/server/server.js b/server/server.js index 632123e..382824a 100644 --- a/server/server.js +++ b/server/server.js @@ -325,25 +325,32 @@ app.post('/api/turtle/update', (req, res) => { } }); -// Endpoint for turtles to poll for commands +// Endpoint for webbridge to poll for commands (includes eval + legacy) app.get('/api/turtle/:id/commands', (req, res) => { try { const turtleID = parseInt(req.params.id); + const turtle = turtles.get(turtleID); - if (turtleData.has(turtleID)) { - const turtle = turtleData.get(turtleID); - const commands = turtle.pendingCommands || []; + if (turtle) { + // Combine eval commands + legacy commands + const commands = turtle.pendingLegacyCommands || []; - // Clean up old commands (older than 30 seconds - they're probably lost) + // Clean up old commands (older than 30 seconds) const now = Date.now(); - turtle.pendingCommands = commands.filter(cmd => (now - cmd.timestamp) < 30000); + turtle.pendingLegacyCommands = commands.filter(cmd => (now - cmd.timestamp) < 30000); - if (turtle.pendingCommands.length > 0) { - console.log(`📤 Sending ${turtle.pendingCommands.length} command(s) to turtle ${turtleID}`); - turtle.pendingCommands.forEach(cmd => console.log(` - ${cmd.command}`, cmd.param ? `(${cmd.param})` : '')); + if (turtle.pendingLegacyCommands.length > 0) { + console.log(`📤 Sending ${turtle.pendingLegacyCommands.length} command(s) to turtle ${turtleID}`); + turtle.pendingLegacyCommands.forEach(cmd => { + if (cmd.type === 'eval') { + console.log(` - EVAL ${(cmd.uuid || '').substring(0, 8)}`); + } else { + console.log(` - ${cmd.command}`, cmd.param ? `(${JSON.stringify(cmd.param)})` : ''); + } + }); } - res.json({ commands: turtle.pendingCommands }); + res.json({ commands: turtle.pendingLegacyCommands }); } else { res.json({ commands: [] }); }