Upload public.js
Browse files- backend/src/routes/public.js +132 -0
backend/src/routes/public.js
CHANGED
|
@@ -259,6 +259,28 @@ router.get('/api-view/:userId/:pptId/:slideIndex?', async (req, res, next) => {
|
|
| 259 |
}
|
| 260 |
|
| 261 |
const slideIdx = parseInt(slideIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 263 |
return res.status(404).json({ error: 'Slide not found' });
|
| 264 |
}
|
|
@@ -421,6 +443,28 @@ router.get('/screenshot/:userId/:pptId/:slideIndex?', async (req, res, next) =>
|
|
| 421 |
}
|
| 422 |
|
| 423 |
const slideIdx = parseInt(slideIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 425 |
return res.status(404).json({ error: 'Invalid slide index' });
|
| 426 |
}
|
|
@@ -528,6 +572,28 @@ router.get('/image/:userId/:pptId/:slideIndex?', async (req, res, next) => {
|
|
| 528 |
}
|
| 529 |
|
| 530 |
const slideIdx = parseInt(slideIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 532 |
console.log(`❌ Invalid slide index: ${slideIndex}`);
|
| 533 |
|
|
@@ -670,6 +736,28 @@ router.get('/screenshot-data/:userId/:pptId/:slideIndex?', async (req, res, next
|
|
| 670 |
}
|
| 671 |
|
| 672 |
const slideIdx = parseInt(slideIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 673 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 674 |
return res.status(404).json({ error: 'Invalid slide index' });
|
| 675 |
}
|
|
@@ -775,6 +863,28 @@ router.get('/screenshot-tool/:userId/:pptId/:slideIndex?', async (req, res, next
|
|
| 775 |
}
|
| 776 |
|
| 777 |
const slideIdx = parseInt(slideIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 778 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 779 |
const errorPage = generateErrorPage('Invalid Slide', `Slide ${slideIndex} not found in PPT`);
|
| 780 |
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
@@ -955,6 +1065,28 @@ router.get('/direct-image/:userId/:pptId/:slideIndex?', async (req, res, next) =
|
|
| 955 |
}
|
| 956 |
|
| 957 |
const slideIdx = parseInt(slideIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 958 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 959 |
console.log(`❌ Invalid slide index: ${slideIndex}`);
|
| 960 |
// 返回404幻灯片SVG
|
|
|
|
| 259 |
}
|
| 260 |
|
| 261 |
const slideIdx = parseInt(slideIndex);
|
| 262 |
+
|
| 263 |
+
// 安全检查:确保 slides 数组存在
|
| 264 |
+
if (!pptData.slides || !Array.isArray(pptData.slides)) {
|
| 265 |
+
console.log(`❌ Invalid PPT data: slides array not found`);
|
| 266 |
+
|
| 267 |
+
if (format === 'svg') {
|
| 268 |
+
const invalidDataSvg = `<svg width="800" height="450" xmlns="http://www.w3.org/2000/svg">
|
| 269 |
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
| 270 |
+
<text x="400" y="200" text-anchor="middle" font-family="Arial, sans-serif" font-size="24" fill="#6c757d">Invalid PPT Data</text>
|
| 271 |
+
<text x="400" y="250" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#6c757d">Slides data not found</text>
|
| 272 |
+
<text x="400" y="300" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#999">${new Date().toISOString()}</text>
|
| 273 |
+
</svg>`;
|
| 274 |
+
|
| 275 |
+
res.setHeader('Content-Type', 'image/svg+xml; charset=utf-8');
|
| 276 |
+
return res.send(invalidDataSvg);
|
| 277 |
+
} else {
|
| 278 |
+
const errorPage = generateErrorPage('Invalid PPT Data', 'PPT slides data not found or corrupted.');
|
| 279 |
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
| 280 |
+
return res.status(400).send(errorPage);
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 285 |
return res.status(404).json({ error: 'Slide not found' });
|
| 286 |
}
|
|
|
|
| 443 |
}
|
| 444 |
|
| 445 |
const slideIdx = parseInt(slideIndex);
|
| 446 |
+
|
| 447 |
+
// 安全检查:确保 slides 数组存在
|
| 448 |
+
if (!pptData.slides || !Array.isArray(pptData.slides)) {
|
| 449 |
+
console.log(`❌ Invalid PPT data: slides array not found`);
|
| 450 |
+
|
| 451 |
+
if (format === 'svg') {
|
| 452 |
+
const invalidDataSvg = `<svg width="800" height="450" xmlns="http://www.w3.org/2000/svg">
|
| 453 |
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
| 454 |
+
<text x="400" y="200" text-anchor="middle" font-family="Arial, sans-serif" font-size="24" fill="#6c757d">Invalid PPT Data</text>
|
| 455 |
+
<text x="400" y="250" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#6c757d">Slides data not found</text>
|
| 456 |
+
<text x="400" y="300" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#999">${new Date().toISOString()}</text>
|
| 457 |
+
</svg>`;
|
| 458 |
+
|
| 459 |
+
res.setHeader('Content-Type', 'image/svg+xml; charset=utf-8');
|
| 460 |
+
return res.send(invalidDataSvg);
|
| 461 |
+
} else {
|
| 462 |
+
const errorPage = generateErrorPage('Invalid PPT Data', 'PPT slides data not found or corrupted.');
|
| 463 |
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
| 464 |
+
return res.status(400).send(errorPage);
|
| 465 |
+
}
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 469 |
return res.status(404).json({ error: 'Invalid slide index' });
|
| 470 |
}
|
|
|
|
| 572 |
}
|
| 573 |
|
| 574 |
const slideIdx = parseInt(slideIndex);
|
| 575 |
+
|
| 576 |
+
// 安全检查:确保 slides 数组存在
|
| 577 |
+
if (!pptData.slides || !Array.isArray(pptData.slides)) {
|
| 578 |
+
console.log(`❌ Invalid PPT data: slides array not found`);
|
| 579 |
+
|
| 580 |
+
if (format === 'svg') {
|
| 581 |
+
const invalidDataSvg = `<svg width="800" height="450" xmlns="http://www.w3.org/2000/svg">
|
| 582 |
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
| 583 |
+
<text x="400" y="200" text-anchor="middle" font-family="Arial, sans-serif" font-size="24" fill="#6c757d">Invalid PPT Data</text>
|
| 584 |
+
<text x="400" y="250" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#6c757d">Slides data not found</text>
|
| 585 |
+
<text x="400" y="300" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#999">${new Date().toISOString()}</text>
|
| 586 |
+
</svg>`;
|
| 587 |
+
|
| 588 |
+
res.setHeader('Content-Type', 'image/svg+xml; charset=utf-8');
|
| 589 |
+
return res.send(invalidDataSvg);
|
| 590 |
+
} else {
|
| 591 |
+
const errorPage = generateErrorPage('Invalid PPT Data', 'PPT slides data not found or corrupted.');
|
| 592 |
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
| 593 |
+
return res.status(400).send(errorPage);
|
| 594 |
+
}
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 598 |
console.log(`❌ Invalid slide index: ${slideIndex}`);
|
| 599 |
|
|
|
|
| 736 |
}
|
| 737 |
|
| 738 |
const slideIdx = parseInt(slideIndex);
|
| 739 |
+
|
| 740 |
+
// 安全检查:确保 slides 数组存在
|
| 741 |
+
if (!pptData.slides || !Array.isArray(pptData.slides)) {
|
| 742 |
+
console.log(`❌ Invalid PPT data: slides array not found`);
|
| 743 |
+
|
| 744 |
+
if (format === 'svg') {
|
| 745 |
+
const invalidDataSvg = `<svg width="800" height="450" xmlns="http://www.w3.org/2000/svg">
|
| 746 |
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
| 747 |
+
<text x="400" y="200" text-anchor="middle" font-family="Arial, sans-serif" font-size="24" fill="#6c757d">Invalid PPT Data</text>
|
| 748 |
+
<text x="400" y="250" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#6c757d">Slides data not found</text>
|
| 749 |
+
<text x="400" y="300" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#999">${new Date().toISOString()}</text>
|
| 750 |
+
</svg>`;
|
| 751 |
+
|
| 752 |
+
res.setHeader('Content-Type', 'image/svg+xml; charset=utf-8');
|
| 753 |
+
return res.send(invalidDataSvg);
|
| 754 |
+
} else {
|
| 755 |
+
const errorPage = generateErrorPage('Invalid PPT Data', 'PPT slides data not found or corrupted.');
|
| 756 |
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
| 757 |
+
return res.status(400).send(errorPage);
|
| 758 |
+
}
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 762 |
return res.status(404).json({ error: 'Invalid slide index' });
|
| 763 |
}
|
|
|
|
| 863 |
}
|
| 864 |
|
| 865 |
const slideIdx = parseInt(slideIndex);
|
| 866 |
+
|
| 867 |
+
// 安全检查:确保 slides 数组存在
|
| 868 |
+
if (!pptData.slides || !Array.isArray(pptData.slides)) {
|
| 869 |
+
console.log(`❌ Invalid PPT data: slides array not found`);
|
| 870 |
+
|
| 871 |
+
if (format === 'svg') {
|
| 872 |
+
const invalidDataSvg = `<svg width="800" height="450" xmlns="http://www.w3.org/2000/svg">
|
| 873 |
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
| 874 |
+
<text x="400" y="200" text-anchor="middle" font-family="Arial, sans-serif" font-size="24" fill="#6c757d">Invalid PPT Data</text>
|
| 875 |
+
<text x="400" y="250" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#6c757d">Slides data not found</text>
|
| 876 |
+
<text x="400" y="300" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#999">${new Date().toISOString()}</text>
|
| 877 |
+
</svg>`;
|
| 878 |
+
|
| 879 |
+
res.setHeader('Content-Type', 'image/svg+xml; charset=utf-8');
|
| 880 |
+
return res.send(invalidDataSvg);
|
| 881 |
+
} else {
|
| 882 |
+
const errorPage = generateErrorPage('Invalid PPT Data', 'PPT slides data not found or corrupted.');
|
| 883 |
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
| 884 |
+
return res.status(400).send(errorPage);
|
| 885 |
+
}
|
| 886 |
+
}
|
| 887 |
+
|
| 888 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 889 |
const errorPage = generateErrorPage('Invalid Slide', `Slide ${slideIndex} not found in PPT`);
|
| 890 |
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
|
|
| 1065 |
}
|
| 1066 |
|
| 1067 |
const slideIdx = parseInt(slideIndex);
|
| 1068 |
+
|
| 1069 |
+
// 安全检查:确保 slides 数组存在
|
| 1070 |
+
if (!pptData.slides || !Array.isArray(pptData.slides)) {
|
| 1071 |
+
console.log(`❌ Invalid PPT data: slides array not found`);
|
| 1072 |
+
|
| 1073 |
+
if (format === 'svg') {
|
| 1074 |
+
const invalidDataSvg = `<svg width="800" height="450" xmlns="http://www.w3.org/2000/svg">
|
| 1075 |
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
| 1076 |
+
<text x="400" y="200" text-anchor="middle" font-family="Arial, sans-serif" font-size="24" fill="#6c757d">Invalid PPT Data</text>
|
| 1077 |
+
<text x="400" y="250" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#6c757d">Slides data not found</text>
|
| 1078 |
+
<text x="400" y="300" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#999">${new Date().toISOString()}</text>
|
| 1079 |
+
</svg>`;
|
| 1080 |
+
|
| 1081 |
+
res.setHeader('Content-Type', 'image/svg+xml; charset=utf-8');
|
| 1082 |
+
return res.send(invalidDataSvg);
|
| 1083 |
+
} else {
|
| 1084 |
+
const errorPage = generateErrorPage('Invalid PPT Data', 'PPT slides data not found or corrupted.');
|
| 1085 |
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
| 1086 |
+
return res.status(400).send(errorPage);
|
| 1087 |
+
}
|
| 1088 |
+
}
|
| 1089 |
+
|
| 1090 |
if (slideIdx >= pptData.slides.length || slideIdx < 0) {
|
| 1091 |
console.log(`❌ Invalid slide index: ${slideIndex}`);
|
| 1092 |
// 返回404幻灯片SVG
|