Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -157,6 +157,7 @@ app.post('/stream-feed', verifySupabaseUser, async (req, res) => {
|
|
| 157 |
}
|
| 158 |
});
|
| 159 |
|
|
|
|
| 160 |
app.post('/poll', async (req, res) => {
|
| 161 |
const { token } = req.body;
|
| 162 |
if (!token) return res.status(400).json({ error: 'Token required' });
|
|
@@ -171,6 +172,33 @@ app.post('/poll', async (req, res) => {
|
|
| 171 |
return res.json(response.data);
|
| 172 |
} catch (err) { return res.status(403).json({ error: 'Invalid Token' }); }
|
| 173 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
app.post('/project/delete', verifySupabaseUser, async (req, res) => {
|
| 176 |
const { projectId } = req.body;
|
|
|
|
| 157 |
}
|
| 158 |
});
|
| 159 |
|
| 160 |
+
/*
|
| 161 |
app.post('/poll', async (req, res) => {
|
| 162 |
const { token } = req.body;
|
| 163 |
if (!token) return res.status(400).json({ error: 'Token required' });
|
|
|
|
| 172 |
return res.json(response.data);
|
| 173 |
} catch (err) { return res.status(403).json({ error: 'Invalid Token' }); }
|
| 174 |
});
|
| 175 |
+
*/
|
| 176 |
+
|
| 177 |
+
app.post('/poll', async (req, res) => {
|
| 178 |
+
const { token } = req.body;
|
| 179 |
+
if (!token) return res.status(400).json({ error: 'Token required' });
|
| 180 |
+
|
| 181 |
+
const decoded = jwt.decode(token);
|
| 182 |
+
if (!decoded) return res.status(401).json({ error: 'Malformed token' });
|
| 183 |
+
|
| 184 |
+
const secret = await getSessionSecret(decoded.uid, decoded.projectId);
|
| 185 |
+
if (!secret) return res.status(404).json({ error: 'Session revoked' });
|
| 186 |
+
|
| 187 |
+
try {
|
| 188 |
+
jwt.verify(token, secret);
|
| 189 |
+
const targetUrl = EXTERNAL_SERVER_URL.replace(/\/$/, '') + '/project/ping';
|
| 190 |
+
|
| 191 |
+
// FIX: We do NOT send isFrontend: true.
|
| 192 |
+
// We act as the Plugin (Executor), but the Main Server will still give us the snapshot now.
|
| 193 |
+
const response = await axios.post(targetUrl, {
|
| 194 |
+
projectId: decoded.projectId,
|
| 195 |
+
userId: decoded.uid
|
| 196 |
+
});
|
| 197 |
+
|
| 198 |
+
return res.json(response.data);
|
| 199 |
+
} catch (err) { return res.status(403).json({ error: 'Invalid Token' }); }
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
|
| 203 |
app.post('/project/delete', verifySupabaseUser, async (req, res) => {
|
| 204 |
const { projectId } = req.body;
|