ERPTurbo_Poster/tests/test_html_poster.js
shenyifei dc940d2598 feat(api): 添加海报和PDF生成功能
- 新增海报生成接口,支持从网页URL或HTML内容生成海报图像
- 新增PDF生成接口,支持从网页URL或HTML内容生成PDF文档
- 添加Swagger API文档注释,完善接口描述和参数说明
- 实现HTML内容参数支持,允许直接传入HTML结构生成海报/PDF
- 添加输入验证和标准化响应格式
- 引入DOMPurify库对HTML内容进行安全过滤
- 更新环境变量配置,支持API密钥认证和CORS设置
- 优化上传逻辑,统一返回标准响应结构
- 添加构建脚本支持Docker镜像打包和推送
2025-11-20 17:51:35 +08:00

37 lines
992 B
JavaScript

import fetch from 'node-fetch';
// 测试从HTML内容生成海报
async function testHtmlPoster() {
const testData = {
html: '<!DOCTYPE html><html><head><title>Test Poster</title></head><body><h1>Test HTML Content</h1><p>This is a test of HTML poster generation.</p></body></html>',
width: 800,
height: 600,
type: 'png',
device: 1
};
try {
console.log('Sending request to generate poster from HTML...');
const response = await fetch('http://localhost:3000/api/v1/poster', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer abc123'
},
body: JSON.stringify(testData)
});
if (response.ok) {
const result = await response.json();
console.log('Success:', result);
} else {
console.error('Error:', response.status, await response.text());
}
} catch (error) {
console.error('Request failed:', error);
}
}
// 执行测试
testHtmlPoster();