CatPtain commited on
Commit
08a9a1b
·
verified ·
1 Parent(s): dab3c13

Upload public.js

Browse files
Files changed (1) hide show
  1. backend/src/routes/public.js +54 -5
backend/src/routes/public.js CHANGED
@@ -322,34 +322,75 @@ router.post('/generate-share-link', async (req, res, next) => {
322
  return res.status(400).json({ error: 'User ID and PPT ID are required' });
323
  }
324
 
 
 
325
  // 验证PPT是否存在
326
  const fileName = `${pptId}.json`;
327
  const storageService = getStorageService();
328
  let pptExists = false;
 
 
 
329
 
330
  // 如果是GitHub服务,尝试所有仓库
331
  if (storageService === githubService && storageService.repositories) {
 
 
332
  for (let i = 0; i < storageService.repositories.length; i++) {
333
  try {
 
334
  const result = await storageService.getFile(userId, fileName, i);
335
  if (result) {
336
  pptExists = true;
 
 
337
  break;
338
  }
339
  } catch (error) {
 
340
  continue;
341
  }
342
  }
343
  } else {
344
  // 内存存储服务
345
- const result = await storageService.getFile(userId, fileName);
346
- if (result) {
347
- pptExists = true;
 
 
 
 
 
 
 
348
  }
349
  }
350
 
351
  if (!pptExists) {
352
- return res.status(404).json({ error: 'PPT not found' });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  }
354
 
355
  const baseUrl = process.env.PUBLIC_URL || req.get('host');
@@ -361,11 +402,19 @@ router.post('/generate-share-link', async (req, res, next) => {
361
  // 完整PPT分享链接
362
  pptUrl: `${protocol}://${baseUrl}/api/public/ppt/${userId}/${pptId}`,
363
  // 前端查看链接
364
- viewUrl: `${protocol}://${baseUrl}/public/${userId}/${pptId}/${slideIndex}`
 
 
 
 
 
 
365
  };
366
 
 
367
  res.json(shareLinks);
368
  } catch (error) {
 
369
  next(error);
370
  }
371
  });
 
322
  return res.status(400).json({ error: 'User ID and PPT ID are required' });
323
  }
324
 
325
+ console.log(`Generating share link for PPT: ${pptId}, User: ${userId}`);
326
+
327
  // 验证PPT是否存在
328
  const fileName = `${pptId}.json`;
329
  const storageService = getStorageService();
330
  let pptExists = false;
331
+ let pptData = null;
332
+
333
+ console.log(`Using storage service: ${storageService === githubService ? 'GitHub' : 'Memory'}`);
334
 
335
  // 如果是GitHub服务,尝试所有仓库
336
  if (storageService === githubService && storageService.repositories) {
337
+ console.log(`Checking ${storageService.repositories.length} GitHub repositories...`);
338
+
339
  for (let i = 0; i < storageService.repositories.length; i++) {
340
  try {
341
+ console.log(`Checking repository ${i}: ${storageService.repositories[i]}`);
342
  const result = await storageService.getFile(userId, fileName, i);
343
  if (result) {
344
  pptExists = true;
345
+ pptData = result.content;
346
+ console.log(`PPT found in repository ${i}`);
347
  break;
348
  }
349
  } catch (error) {
350
+ console.log(`PPT not found in repository ${i}: ${error.message}`);
351
  continue;
352
  }
353
  }
354
  } else {
355
  // 内存存储服务
356
+ console.log('Checking memory storage...');
357
+ try {
358
+ const result = await storageService.getFile(userId, fileName);
359
+ if (result) {
360
+ pptExists = true;
361
+ pptData = result.content;
362
+ console.log('PPT found in memory storage');
363
+ }
364
+ } catch (error) {
365
+ console.log(`PPT not found in memory storage: ${error.message}`);
366
  }
367
  }
368
 
369
  if (!pptExists) {
370
+ console.log('PPT not found in any storage location');
371
+
372
+ // 额外尝试:如果GitHub失败,检查memory storage作为fallback
373
+ if (storageService === githubService) {
374
+ console.log('GitHub lookup failed, trying memory storage fallback...');
375
+ try {
376
+ const memoryResult = await memoryStorageService.getFile(userId, fileName);
377
+ if (memoryResult) {
378
+ pptExists = true;
379
+ pptData = memoryResult.content;
380
+ console.log('PPT found in memory storage fallback');
381
+ }
382
+ } catch (memoryError) {
383
+ console.log(`Memory storage fallback also failed: ${memoryError.message}`);
384
+ }
385
+ }
386
+ }
387
+
388
+ if (!pptExists) {
389
+ return res.status(404).json({
390
+ error: 'PPT not found',
391
+ details: `PPT ${pptId} not found for user ${userId}`,
392
+ searchedLocations: storageService === githubService ? 'GitHub repositories and memory storage' : 'Memory storage only'
393
+ });
394
  }
395
 
396
  const baseUrl = process.env.PUBLIC_URL || req.get('host');
 
402
  // 完整PPT分享链接
403
  pptUrl: `${protocol}://${baseUrl}/api/public/ppt/${userId}/${pptId}`,
404
  // 前端查看链接
405
+ viewUrl: `${protocol}://${baseUrl}/public/${userId}/${pptId}/${slideIndex}`,
406
+ // 添加PPT信息
407
+ pptInfo: {
408
+ id: pptId,
409
+ title: pptData?.title || 'Unknown Title',
410
+ slideCount: pptData?.slides?.length || 0
411
+ }
412
  };
413
 
414
+ console.log('Share links generated successfully:', shareLinks);
415
  res.json(shareLinks);
416
  } catch (error) {
417
+ console.error('Share link generation error:', error);
418
  next(error);
419
  }
420
  });