everydaycats commited on
Commit
6033be3
·
verified ·
1 Parent(s): 00303c4

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +2 -36
app.js CHANGED
@@ -23,7 +23,7 @@ const {
23
  SUPABASE_URL,
24
  SUPABASE_SERVICE_ROLE_KEY,
25
  EXTERNAL_SERVER_URL = 'http://localhost:7860',
26
- STORAGE_BUCKET = 'project-assets', // Default bucket name
27
  PORT = 7860
28
  } = process.env;
29
 
@@ -223,6 +223,7 @@ app.post('/feedback', async (req, res) => {
223
  ...pluginPayload
224
  });
225
 
 
226
  return res.json({ success: true, externalResponse: response.data });
227
 
228
  } catch (err) {
@@ -234,32 +235,6 @@ app.post('/feedback', async (req, res) => {
234
  }
235
  });
236
 
237
- app.post('/feedback2', verifySupabaseUser, async (req, res) => {
238
- const { projectId, prompt, images, ...otherPayload } = req.body;
239
- const userId = req.user.id;
240
-
241
- if (!projectId || !prompt) {
242
- return res.status(400).json({ error: 'Missing projectId or prompt' });
243
- }
244
-
245
- const targetUrl = EXTERNAL_SERVER_URL.replace(/\/$/, '') + '/project/feedback';
246
-
247
- try {
248
- const response = await axios.post(targetUrl, {
249
- userId: userId,
250
- projectId: projectId,
251
- prompt: prompt,
252
- images: images || [],
253
- ...otherPayload
254
- });
255
-
256
- return res.json({ success: true, externalResponse: response.data });
257
- } catch (err) {
258
- console.error("Forward Error:", err.message);
259
- return res.status(502).json({ error: 'Failed to forward' });
260
- }
261
- });
262
-
263
  app.post('/poll', async (req, res) => {
264
  const { token } = req.body;
265
 
@@ -313,7 +288,6 @@ app.post('/project/delete', verifySupabaseUser, async (req, res) => {
313
  console.log(`🗑️ Deleting Project: ${projectId} requested by ${userId}`);
314
 
315
  try {
316
- // 1. Verify Ownership
317
  const { data: project, error: fetchError } = await supabase
318
  .from('projects')
319
  .select('user_id')
@@ -324,8 +298,6 @@ app.post('/project/delete', verifySupabaseUser, async (req, res) => {
324
  return res.status(403).json({ error: "Unauthorized" });
325
  }
326
 
327
- // 2. Explicitly Delete Message Chunks
328
- // Safe to run even if ON DELETE CASCADE exists
329
  const { error: chunkError } = await supabase
330
  .from('message_chunks')
331
  .delete()
@@ -333,10 +305,8 @@ app.post('/project/delete', verifySupabaseUser, async (req, res) => {
333
 
334
  if (chunkError) {
335
  console.warn(`Warning: Failed to delete message chunks: ${chunkError.message}`);
336
- // We continue, hoping foreign key cascade picks it up, or it might be partial delete
337
  }
338
 
339
- // 3. Delete Project
340
  const { error: dbError } = await supabase
341
  .from('projects')
342
  .delete()
@@ -344,18 +314,14 @@ app.post('/project/delete', verifySupabaseUser, async (req, res) => {
344
 
345
  if (dbError) throw dbError;
346
 
347
- // 4. Delete from Supabase Storage
348
- // Supabase storage doesn't have a "delete folder" command, so we list -> delete files
349
  if (STORAGE_BUCKET) {
350
  const { data: files } = await supabase.storage.from(STORAGE_BUCKET).list(projectId);
351
-
352
  if (files && files.length > 0) {
353
  const filesToRemove = files.map(f => `${projectId}/${f.name}`);
354
  await supabase.storage.from(STORAGE_BUCKET).remove(filesToRemove);
355
  }
356
  }
357
 
358
- // 5. Clear from Memory
359
  activeSessions.delete(`${userId}:${projectId}`);
360
  for (const [key, val] of tempKeys.entries()) {
361
  if (val.projectId === projectId) tempKeys.delete(key);
 
23
  SUPABASE_URL,
24
  SUPABASE_SERVICE_ROLE_KEY,
25
  EXTERNAL_SERVER_URL = 'http://localhost:7860',
26
+ STORAGE_BUCKET = 'project-assets',
27
  PORT = 7860
28
  } = process.env;
29
 
 
223
  ...pluginPayload
224
  });
225
 
226
+ // We expect the AI Server to return success immediately while working in background
227
  return res.json({ success: true, externalResponse: response.data });
228
 
229
  } catch (err) {
 
235
  }
236
  });
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  app.post('/poll', async (req, res) => {
239
  const { token } = req.body;
240
 
 
288
  console.log(`🗑️ Deleting Project: ${projectId} requested by ${userId}`);
289
 
290
  try {
 
291
  const { data: project, error: fetchError } = await supabase
292
  .from('projects')
293
  .select('user_id')
 
298
  return res.status(403).json({ error: "Unauthorized" });
299
  }
300
 
 
 
301
  const { error: chunkError } = await supabase
302
  .from('message_chunks')
303
  .delete()
 
305
 
306
  if (chunkError) {
307
  console.warn(`Warning: Failed to delete message chunks: ${chunkError.message}`);
 
308
  }
309
 
 
310
  const { error: dbError } = await supabase
311
  .from('projects')
312
  .delete()
 
314
 
315
  if (dbError) throw dbError;
316
 
 
 
317
  if (STORAGE_BUCKET) {
318
  const { data: files } = await supabase.storage.from(STORAGE_BUCKET).list(projectId);
 
319
  if (files && files.length > 0) {
320
  const filesToRemove = files.map(f => `${projectId}/${f.name}`);
321
  await supabase.storage.from(STORAGE_BUCKET).remove(filesToRemove);
322
  }
323
  }
324
 
 
325
  activeSessions.delete(`${userId}:${projectId}`);
326
  for (const [key, val] of tempKeys.entries()) {
327
  if (val.projectId === projectId) tempKeys.delete(key);