File size: 13,006 Bytes
d6d7385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>🖼️ 直接图片URL测试</title>
    <style>

        body {

            font-family: 'Microsoft YaHei', sans-serif;

            max-width: 1200px;

            margin: 0 auto;

            padding: 20px;

            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

            min-height: 100vh;

            color: #333;

        }

        .container {

            background: white;

            border-radius: 15px;

            padding: 30px;

            box-shadow: 0 20px 40px rgba(0,0,0,0.1);

        }

        .header {

            text-align: center;

            margin-bottom: 30px;

            padding: 20px;

            background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);

            color: white;

            border-radius: 10px;

        }

        .test-section {

            margin: 30px 0;

            padding: 20px;

            border: 2px solid #e0e0e0;

            border-radius: 10px;

        }

        .test-button {

            background: #4CAF50;

            color: white;

            border: none;

            padding: 12px 24px;

            border-radius: 5px;

            cursor: pointer;

            margin: 10px;

            font-size: 16px;

            font-weight: bold;

        }

        .test-button:hover { background: #45a049; }

        .result-box {

            margin: 15px 0;

            padding: 15px;

            border-radius: 5px;

            font-family: monospace;

            white-space: pre-wrap;

            max-height: 400px;

            overflow-y: auto;

        }

        .result-box.success { background: #e8f5e8; color: #2e7d32; border: 1px solid #4caf50; }

        .result-box.error { background: #fdeaea; color: #c62828; border: 1px solid #f44336; }

        .result-box.info { background: #e3f2fd; color: #1565c0; border: 1px solid #2196f3; }

        .image-preview {

            max-width: 100%;

            border: 2px solid #ddd;

            border-radius: 8px;

            margin: 15px 0;

        }

        .url-display {

            background: #f5f5f5;

            padding: 10px;

            border-radius: 5px;

            font-family: monospace;

            word-break: break-all;

            margin: 10px 0;

        }

    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🖼️ 直接图片URL测试</h1>
            <p>测试后端生成的直接图片链接是否可以被其他网站引用</p>
        </div>

        <!-- 测试表单 -->
        <div class="test-section">
            <h3>📝 测试参数</h3>
            <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0;">
                <div>
                    <label>用户ID: <input type="text" id="userId" value="PS01" style="width: 100%; padding: 8px;"></label>
                </div>
                <div>
                    <label>PPT ID: <input type="text" id="pptId" placeholder="输入PPT ID" style="width: 100%; padding: 8px;"></label>
                </div>
                <div>
                    <label>幻灯片索引: <input type="number" id="slideIndex" value="0" style="width: 100%; padding: 8px;"></label>
                </div>
                <div>
                    <label>格式: 
                        <select id="format" style="width: 100%; padding: 8px;">
                            <option value="svg">SVG</option>
                            <option value="jpeg">JPEG</option>
                            <option value="png">PNG</option>
                        </select>
                    </label>
                </div>
            </div>
            
            <button class="test-button" onclick="testDirectImage()">🖼️ 测试直接图片URL</button>
            <button class="test-button" onclick="testImageInIframe()">🌐 测试在iframe中引用</button>
            <button class="test-button" onclick="testImageTag()">📷 测试作为img标签</button>
        </div>

        <!-- URL显示区域 -->
        <div class="test-section">
            <h3>🔗 生成的图片URL</h3>
            <div id="urlDisplay" class="url-display">
                点击测试按钮生成URL...
            </div>
            <button class="test-button" onclick="copyURL()" id="copyBtn" style="display: none;">📋 复制URL</button>
        </div>

        <!-- 图片预览区域 -->
        <div class="test-section">
            <h3>📸 图片预览</h3>
            <div id="imagePreview" style="text-align: center;">
                <p>图片将在这里显示...</p>
            </div>
        </div>

        <!-- 测试结果 -->
        <div class="test-section">
            <h3>📊 测试结果</h3>
            <div id="testResults" class="result-box info" style="display: none;"></div>
        </div>

        <!-- 外部引用测试 -->
        <div class="test-section">
            <h3>🌍 外部引用测试</h3>
            <p>以下测试模拟其他网站引用我们的图片URL:</p>
            
            <h4>1. 作为IMG标签引用</h4>
            <div id="imgTagTest" style="border: 1px solid #ddd; padding: 20px; margin: 10px 0; background: #f9f9f9;">
                <p>IMG标签测试区域</p>
            </div>
            
            <h4>2. 作为CSS背景图片</h4>
            <div id="cssBackgroundTest" style="width: 100%; height: 200px; border: 1px solid #ddd; margin: 10px 0; background: #f9f9f9;">
                <p style="text-align: center; line-height: 200px;">CSS背景图片测试区域</p>
            </div>
            
            <h4>3. 在iframe中显示</h4>
            <div id="iframeTest" style="border: 1px solid #ddd; margin: 10px 0;">
                <p>iframe测试区域</p>
            </div>
        </div>
    </div>

    <script>

        let currentImageURL = '';



        function showResult(message, type = 'info') {

            const resultsDiv = document.getElementById('testResults');

            resultsDiv.textContent = message;

            resultsDiv.className = `result-box ${type}`;

            resultsDiv.style.display = 'block';

        }



        function generateImageURL() {

            const userId = document.getElementById('userId').value || 'PS01';

            const pptId = document.getElementById('pptId').value;

            const slideIndex = document.getElementById('slideIndex').value || '0';

            const format = document.getElementById('format').value || 'svg';



            if (!pptId) {

                alert('请输入PPT ID!');

                return null;

            }



            // 构建URL

            const baseURL = window.location.origin;

            currentImageURL = `${baseURL}/api/public/direct-image/${userId}/${pptId}/${slideIndex}?format=${format}`;

            

            // 显示URL

            document.getElementById('urlDisplay').textContent = currentImageURL;

            document.getElementById('copyBtn').style.display = 'inline-block';

            

            return currentImageURL;

        }



        async function testDirectImage() {

            const url = generateImageURL();

            if (!url) return;



            showResult('🚀 正在测试直接图片URL...', 'info');



            try {

                const startTime = performance.now();

                const response = await fetch(url);

                const endTime = performance.now();

                

                const contentType = response.headers.get('Content-Type');

                const contentLength = response.headers.get('Content-Length');

                const cacheControl = response.headers.get('Cache-Control');

                const generation = response.headers.get('X-Generation-Time');

                

                if (response.ok) {

                    const responseTime = Math.round(endTime - startTime);

                    

                    let resultText = `✅ 图片URL测试成功!\n\n`;

                    resultText += `📊 响应信息:\n`;

                    resultText += `  - 状态码: ${response.status}\n`;

                    resultText += `  - 内容类型: ${contentType}\n`;

                    resultText += `  - 响应时间: ${responseTime}ms\n`;

                    resultText += `  - 生成时间: ${generation || 'N/A'}\n`;

                    resultText += `  - 缓存策略: ${cacheControl || 'N/A'}\n`;

                    if (contentLength) resultText += `  - 文件大小: ${contentLength} bytes\n`;

                    

                    resultText += `\n🔗 URL测试:\n`;

                    resultText += `  - 可以直接访问: ✅\n`;

                    resultText += `  - 返回图片数据: ✅\n`;

                    resultText += `  - 支持跨域: ${response.headers.get('Access-Control-Allow-Origin') ? '✅' : '❌'}\n`;

                    

                    showResult(resultText, 'success');

                    

                    // 显示图片预览

                    updateImagePreview(url);

                    

                } else {

                    showResult(`❌ 图片URL测试失败!\n状态码: ${response.status}\n错误: ${await response.text()}`, 'error');

                }

                

            } catch (error) {

                showResult(`❌ 网络请求失败: ${error.message}`, 'error');

            }

        }



        function updateImagePreview(url) {

            const previewDiv = document.getElementById('imagePreview');

            previewDiv.innerHTML = `

                <img src="${url}" alt="PPT页面预览" class="image-preview" 

                     onload="showResult(document.getElementById('testResults').textContent + '\\n\\n📸 图片加载成功!可以正常显示。', 'success')"

                     onerror="showResult(document.getElementById('testResults').textContent + '\\n\\n❌ 图片加载失败!', 'error')">

            `;

        }



        function testImageTag() {

            const url = generateImageURL();

            if (!url) return;



            const imgTagDiv = document.getElementById('imgTagTest');

            imgTagDiv.innerHTML = `

                <h5>IMG标签引用测试:</h5>

                <img src="${url}" alt="PPT页面" style="max-width: 100%; border: 1px solid #ccc;"

                     onload="console.log('IMG标签加载成功'); this.nextSibling.textContent = '✅ IMG标签引用成功!'"

                     onerror="console.log('IMG标签加载失败'); this.nextSibling.textContent = '❌ IMG标签引用失败!'">

                <p style="color: #666;">加载中...</p>

            `;

            

            showResult(`🖼️ 正在测试IMG标签引用...\nURL: ${url}`, 'info');

        }



        function testImageInIframe() {

            const url = generateImageURL();

            if (!url) return;



            const iframeDiv = document.getElementById('iframeTest');

            iframeDiv.innerHTML = `

                <h5>iframe引用测试:</h5>

                <iframe src="${url}" style="width: 100%; height: 400px; border: 1px solid #ccc;"

                        onload="console.log('iframe加载成功')"

                        onerror="console.log('iframe加载失败')"></iframe>

            `;

            

            showResult(`🌐 正在测试iframe引用...\nURL: ${url}`, 'info');

        }



        function copyURL() {

            if (currentImageURL) {

                navigator.clipboard.writeText(currentImageURL).then(() => {

                    alert('URL已复制到剪贴板!');

                }).catch(() => {

                    // 备用复制方法

                    const textArea = document.createElement('textarea');

                    textArea.value = currentImageURL;

                    document.body.appendChild(textArea);

                    textArea.select();

                    document.execCommand('copy');

                    document.body.removeChild(textArea);

                    alert('URL已复制到剪贴板!');

                });

            }

        }



        // 页面加载完成后的说明

        window.addEventListener('load', function() {

            console.log('🖼️ 直接图片URL测试页面加载完成');

            

            // 如果URL中有参数,自动填充

            const urlParams = new URLSearchParams(window.location.search);

            const pptId = urlParams.get('pptId');

            if (pptId) {

                document.getElementById('pptId').value = pptId;

            }

        });

    </script>
</body>
</html>