CatPtain commited on
Commit
7363663
·
verified ·
1 Parent(s): 0afb612

Upload public.js

Browse files
Files changed (1) hide show
  1. backend/src/routes/public.js +117 -1
backend/src/routes/public.js CHANGED
@@ -2,7 +2,7 @@ import express from 'express';
2
  import githubService from '../services/githubService.js';
3
  import screenshotService from '../services/screenshotService.js';
4
  // 修正导入路径:从 backend/src 向上两级到 app,再进入 shared
5
- import { generateSlideHTML, generateExportPage } from '../../../shared/export-utils.js';
6
 
7
  const router = express.Router();
8
 
@@ -506,4 +506,120 @@ router.get('/screenshot-health', async (req, res, next) => {
506
  }
507
  });
508
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
  export default router;
 
2
  import githubService from '../services/githubService.js';
3
  import screenshotService from '../services/screenshotService.js';
4
  // 修正导入路径:从 backend/src 向上两级到 app,再进入 shared
5
+ import { generateSlideHTML, generateExportPage, exportPPTToJSON, generateHTMLPresentation } from '../../../shared/export-utils.js';
6
 
7
  const router = express.Router();
8
 
 
506
  }
507
  });
508
 
509
+ // 新增:PPT JSON导出端点
510
+ router.get('/export-json/:userId/:pptId', async (req, res, next) => {
511
+ try {
512
+ const { userId, pptId } = req.params;
513
+ const fileName = `${pptId}.json`;
514
+
515
+ let pptData = null;
516
+
517
+ // Try all GitHub repositories
518
+ for (let i = 0; i < githubService.repositories.length; i++) {
519
+ try {
520
+ const result = await githubService.getFile(userId, fileName, i);
521
+ if (result) {
522
+ pptData = result.content;
523
+ break;
524
+ }
525
+ } catch (error) {
526
+ continue;
527
+ }
528
+ }
529
+
530
+ if (!pptData) {
531
+ return res.status(404).json({ error: 'PPT not found' });
532
+ }
533
+
534
+ // 使用共享模块导出JSON
535
+ const jsonData = exportPPTToJSON(pptData);
536
+
537
+ res.setHeader('Content-Type', 'application/json; charset=utf-8');
538
+ res.setHeader('Content-Disposition', `attachment; filename="${pptData.title || 'presentation'}.json"`);
539
+ res.json(jsonData);
540
+ } catch (error) {
541
+ next(error);
542
+ }
543
+ });
544
+
545
+ // 新增:PPT HTML演示文稿导出端点
546
+ router.get('/export-html/:userId/:pptId', async (req, res, next) => {
547
+ try {
548
+ const { userId, pptId } = req.params;
549
+ const { interactive = 'true', standalone = 'true', css = 'true' } = req.query;
550
+ const fileName = `${pptId}.json`;
551
+
552
+ let pptData = null;
553
+
554
+ // Try all GitHub repositories
555
+ for (let i = 0; i < githubService.repositories.length; i++) {
556
+ try {
557
+ const result = await githubService.getFile(userId, fileName, i);
558
+ if (result) {
559
+ pptData = result.content;
560
+ break;
561
+ }
562
+ } catch (error) {
563
+ continue;
564
+ }
565
+ }
566
+
567
+ if (!pptData) {
568
+ return res.status(404).json({ error: 'PPT not found' });
569
+ }
570
+
571
+ // 使用共享模块生成完整HTML演示文稿
572
+ const htmlContent = generateHTMLPresentation(pptData, {
573
+ includeInteractivity: interactive === 'true',
574
+ standalone: standalone === 'true',
575
+ includeCSS: css === 'true'
576
+ });
577
+
578
+ res.setHeader('Content-Type', 'text/html; charset=utf-8');
579
+ res.setHeader('Content-Disposition', `attachment; filename="${pptData.title || 'presentation'}.html"`);
580
+ res.send(htmlContent);
581
+ } catch (error) {
582
+ next(error);
583
+ }
584
+ });
585
+
586
+ // 新增:PPT完整演示文稿查看端点(在线查看,非下载)
587
+ router.get('/presentation/:userId/:pptId', async (req, res, next) => {
588
+ try {
589
+ const { userId, pptId } = req.params;
590
+ const fileName = `${pptId}.json`;
591
+
592
+ let pptData = null;
593
+
594
+ // Try all GitHub repositories
595
+ for (let i = 0; i < githubService.repositories.length; i++) {
596
+ try {
597
+ const result = await githubService.getFile(userId, fileName, i);
598
+ if (result) {
599
+ pptData = result.content;
600
+ break;
601
+ }
602
+ } catch (error) {
603
+ continue;
604
+ }
605
+ }
606
+
607
+ if (!pptData) {
608
+ return res.status(404).send(generateErrorPage('PPT Not Found', 'The presentation you are looking for does not exist.'));
609
+ }
610
+
611
+ // 使用共享模块生成完整HTML演示文稿用于在线查看
612
+ const htmlContent = generateHTMLPresentation(pptData, {
613
+ includeInteractivity: true,
614
+ standalone: true,
615
+ includeCSS: true
616
+ });
617
+
618
+ res.setHeader('Content-Type', 'text/html; charset=utf-8');
619
+ res.send(htmlContent);
620
+ } catch (error) {
621
+ next(error);
622
+ }
623
+ });
624
+
625
  export default router;