Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -417,6 +417,47 @@ app.post('/project/feedback', async (req, res) => {
|
|
| 417 |
}
|
| 418 |
});
|
| 419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
app.post('/project/ping', async (req, res) => {
|
| 421 |
const { projectId } = req.body;
|
| 422 |
// This will hydrate from DB if missing
|
|
@@ -432,6 +473,7 @@ app.post('/project/ping', async (req, res) => {
|
|
| 432 |
res.json({ action: "IDLE" });
|
| 433 |
}
|
| 434 |
});
|
|
|
|
| 435 |
|
| 436 |
app.post('/human/override', validateRequest, async (req, res) => {
|
| 437 |
const { projectId, instruction, pruneHistory } = req.body;
|
|
|
|
| 417 |
}
|
| 418 |
});
|
| 419 |
|
| 420 |
+
app.post('/project/ping', async (req, res) => {
|
| 421 |
+
// 1. Accept userId along with projectId
|
| 422 |
+
const { projectId, userId } = req.body;
|
| 423 |
+
|
| 424 |
+
if (!projectId || !userId) {
|
| 425 |
+
return res.status(400).json({ error: "Missing ID fields" });
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
// 2. Retrieve Project State (Hydrates from DB if not in memory)
|
| 429 |
+
const project = await StateManager.getProject(projectId);
|
| 430 |
+
|
| 431 |
+
if (!project) {
|
| 432 |
+
// If project doesn't exist in Memory or DB
|
| 433 |
+
return res.status(404).json({ action: "IDLE", error: "Project not found" });
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
// 3. SECURITY CHECK: Ensure the user matches the project owner
|
| 437 |
+
if (project.userId !== userId) {
|
| 438 |
+
console.warn(`[Security] Unauthorized ping for ${projectId}. Owner: ${project.userId}, Request: ${userId}`);
|
| 439 |
+
return res.status(403).json({ error: "Unauthorized: You do not own this project." });
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
// 4. Retrieve Command (Only if authorized)
|
| 443 |
+
const command = await StateManager.popCommand(projectId);
|
| 444 |
+
|
| 445 |
+
if (command) {
|
| 446 |
+
if (command.payload === "CLEAR_CONSOLE") {
|
| 447 |
+
res.json({ action: "CLEAR_LOGS" });
|
| 448 |
+
} else {
|
| 449 |
+
res.json({
|
| 450 |
+
action: command.type,
|
| 451 |
+
target: command.payload,
|
| 452 |
+
code: command.type === 'EXECUTE' ? command.payload : null
|
| 453 |
+
});
|
| 454 |
+
}
|
| 455 |
+
} else {
|
| 456 |
+
res.json({ action: "IDLE" });
|
| 457 |
+
}
|
| 458 |
+
});
|
| 459 |
+
|
| 460 |
+
/*
|
| 461 |
app.post('/project/ping', async (req, res) => {
|
| 462 |
const { projectId } = req.body;
|
| 463 |
// This will hydrate from DB if missing
|
|
|
|
| 473 |
res.json({ action: "IDLE" });
|
| 474 |
}
|
| 475 |
});
|
| 476 |
+
*/
|
| 477 |
|
| 478 |
app.post('/human/override', validateRequest, async (req, res) => {
|
| 479 |
const { projectId, instruction, pruneHistory } = req.body;
|