File size: 2,530 Bytes
28e1dba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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 };