Update app.js
Browse files
app.js
CHANGED
|
@@ -559,6 +559,7 @@ app.post('/project/feedback', async (req, res) => {
|
|
| 559 |
}
|
| 560 |
});
|
| 561 |
|
|
|
|
| 562 |
app.post('/project/ping', async (req, res) => {
|
| 563 |
const { projectId, userId, isFrontend } = req.body;
|
| 564 |
if (!projectId || !userId) return res.status(400).json({ error: "Missing IDs" });
|
|
@@ -590,6 +591,32 @@ app.post('/project/ping', async (req, res) => {
|
|
| 590 |
|
| 591 |
res.json(response);
|
| 592 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 593 |
|
| 594 |
app.post('/human/override', validateRequest, async (req, res) => {
|
| 595 |
const { projectId, instruction, userId } = req.body;
|
|
|
|
| 559 |
}
|
| 560 |
});
|
| 561 |
|
| 562 |
+
/*
|
| 563 |
app.post('/project/ping', async (req, res) => {
|
| 564 |
const { projectId, userId, isFrontend } = req.body;
|
| 565 |
if (!projectId || !userId) return res.status(400).json({ error: "Missing IDs" });
|
|
|
|
| 591 |
|
| 592 |
res.json(response);
|
| 593 |
});
|
| 594 |
+
*/
|
| 595 |
+
|
| 596 |
+
app.post('/poll', async (req, res) => {
|
| 597 |
+
const { token } = req.body;
|
| 598 |
+
if (!token) return res.status(400).json({ error: 'Token required' });
|
| 599 |
+
|
| 600 |
+
const decoded = jwt.decode(token);
|
| 601 |
+
if (!decoded) return res.status(401).json({ error: 'Malformed token' });
|
| 602 |
+
|
| 603 |
+
const secret = await getSessionSecret(decoded.uid, decoded.projectId);
|
| 604 |
+
if (!secret) return res.status(404).json({ error: 'Session revoked' });
|
| 605 |
+
|
| 606 |
+
try {
|
| 607 |
+
jwt.verify(token, secret);
|
| 608 |
+
const targetUrl = EXTERNAL_SERVER_URL.replace(/\/$/, '') + '/project/ping';
|
| 609 |
+
|
| 610 |
+
// UPDATE: Send isFrontend: true so we get the text snapshot for the plugin UI
|
| 611 |
+
const response = await axios.post(targetUrl, {
|
| 612 |
+
projectId: decoded.projectId,
|
| 613 |
+
userId: decoded.uid,
|
| 614 |
+
isFrontend: true
|
| 615 |
+
});
|
| 616 |
+
|
| 617 |
+
return res.json(response.data);
|
| 618 |
+
} catch (err) { return res.status(403).json({ error: 'Invalid Token' }); }
|
| 619 |
+
});
|
| 620 |
|
| 621 |
app.post('/human/override', validateRequest, async (req, res) => {
|
| 622 |
const { projectId, instruction, userId } = req.body;
|