web_ppt_7.7 / backend /test-frontend-export.js
CatPtain's picture
Upload 85 files
28e1dba verified
import fetch from 'node-fetch';
/**
* 测试前端导出功能复刻API
*/
async function testFrontendExportReplication() {
const baseUrl = 'http://localhost:3001';
// 测试用的认证token(需要替换为实际的token)
const authToken = 'your-auth-token-here';
// 测试数据
const testData = {
pptId: 'test-ppt-id',
slideIndex: 0,
format: 'jpeg',
quality: 0.9,
width: 1600,
height: 900,
ignoreWebfont: true,
backgroundColor: '#ffffff',
pixelRatio: 1
};
console.log('🧪 Testing Frontend Export Replication API...');
try {
// 测试单个幻灯片导出
console.log('\n1. Testing single slide export...');
const singleResponse = await fetch(`${baseUrl}/api/export/frontend-replicate-single`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
},
body: JSON.stringify(testData)
});
if (singleResponse.ok) {
const singleResult = await singleResponse.json();
console.log('✅ Single export success:', {
linkId: singleResult.linkId,
imageUrl: singleResult.imageUrl,
downloadUrl: singleResult.downloadUrl
});
} else {
const error = await singleResponse.text();
console.log('❌ Single export failed:', singleResponse.status, error);
}
// 测试批量导出
console.log('\n2. Testing batch export...');
const batchData = {
...testData,
rangeType: 'all'
};
const batchResponse = await fetch(`${baseUrl}/api/export/frontend-replicate-batch`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
},
body: JSON.stringify(batchData)
});
if (batchResponse.ok) {
const batchResult = await batchResponse.json();
console.log('✅ Batch export success:', {
totalSlides: batchResult.totalSlides,
successCount: batchResult.successCount,
errorCount: batchResult.errorCount,
resultsCount: batchResult.results?.length || 0
});
} else {
const error = await batchResponse.text();
console.log('❌ Batch export failed:', batchResponse.status, error);
}
} catch (error) {
console.error('🚨 Test failed with error:', error.message);
}
}
// 运行测试
if (import.meta.url === `file://${process.argv[1]}`) {
testFrontendExportReplication();
}
export { testFrontendExportReplication };