Upload public.js
Browse files- backend/src/routes/public.js +21 -0
backend/src/routes/public.js
CHANGED
@@ -262,6 +262,27 @@ router.get('/api-view/:userId/:pptId/:slideIndex?', async (req, res, next) => {
|
|
262 |
|
263 |
const slideIdx = parseInt(slideIndex);
|
264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
// 安全检查:确保 slides 数组存在
|
266 |
if (!pptData.slides || !Array.isArray(pptData.slides)) {
|
267 |
console.log(`❌ Invalid PPT data: slides array not found`);
|
|
|
262 |
|
263 |
const slideIdx = parseInt(slideIndex);
|
264 |
|
265 |
+
// 验证 slideIndex 是否为有效数字
|
266 |
+
if (isNaN(slideIdx)) {
|
267 |
+
console.log(`❌ Invalid slide index format: ${slideIndex}`);
|
268 |
+
|
269 |
+
if (format === 'svg') {
|
270 |
+
const invalidIndexSvg = `<svg width="800" height="450" xmlns="http://www.w3.org/2000/svg">
|
271 |
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
272 |
+
<text x="400" y="200" text-anchor="middle" font-family="Arial, sans-serif" font-size="24" fill="#6c757d">Invalid Slide Index</text>
|
273 |
+
<text x="400" y="250" text-anchor="middle" font-family="Arial, sans-serif" font-size="16" fill="#6c757d">Slide index "${slideIndex}" is not a valid number</text>
|
274 |
+
<text x="400" y="300" text-anchor="middle" font-family="Arial, sans-serif" font-size="12" fill="#999">${new Date().toISOString()}</text>
|
275 |
+
</svg>`;
|
276 |
+
|
277 |
+
res.setHeader('Content-Type', 'image/svg+xml; charset=utf-8');
|
278 |
+
return res.send(invalidIndexSvg);
|
279 |
+
} else {
|
280 |
+
const errorPage = generateErrorPage('Invalid Slide Index', `Slide index "${slideIndex}" is not a valid number.`);
|
281 |
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
282 |
+
return res.status(400).send(errorPage);
|
283 |
+
}
|
284 |
+
}
|
285 |
+
|
286 |
// 安全检查:确保 slides 数组存在
|
287 |
if (!pptData.slides || !Array.isArray(pptData.slides)) {
|
288 |
console.log(`❌ Invalid PPT data: slides array not found`);
|