CatPtain commited on
Commit
d6d7385
·
verified ·
1 Parent(s): b7bb7d4

Upload test-direct-image.html

Browse files
Files changed (1) hide show
  1. test-direct-image.html +307 -0
test-direct-image.html ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>🖼️ 直接图片URL测试</title>
7
+ <style>
8
+ body {
9
+ font-family: 'Microsoft YaHei', sans-serif;
10
+ max-width: 1200px;
11
+ margin: 0 auto;
12
+ padding: 20px;
13
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
14
+ min-height: 100vh;
15
+ color: #333;
16
+ }
17
+ .container {
18
+ background: white;
19
+ border-radius: 15px;
20
+ padding: 30px;
21
+ box-shadow: 0 20px 40px rgba(0,0,0,0.1);
22
+ }
23
+ .header {
24
+ text-align: center;
25
+ margin-bottom: 30px;
26
+ padding: 20px;
27
+ background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
28
+ color: white;
29
+ border-radius: 10px;
30
+ }
31
+ .test-section {
32
+ margin: 30px 0;
33
+ padding: 20px;
34
+ border: 2px solid #e0e0e0;
35
+ border-radius: 10px;
36
+ }
37
+ .test-button {
38
+ background: #4CAF50;
39
+ color: white;
40
+ border: none;
41
+ padding: 12px 24px;
42
+ border-radius: 5px;
43
+ cursor: pointer;
44
+ margin: 10px;
45
+ font-size: 16px;
46
+ font-weight: bold;
47
+ }
48
+ .test-button:hover { background: #45a049; }
49
+ .result-box {
50
+ margin: 15px 0;
51
+ padding: 15px;
52
+ border-radius: 5px;
53
+ font-family: monospace;
54
+ white-space: pre-wrap;
55
+ max-height: 400px;
56
+ overflow-y: auto;
57
+ }
58
+ .result-box.success { background: #e8f5e8; color: #2e7d32; border: 1px solid #4caf50; }
59
+ .result-box.error { background: #fdeaea; color: #c62828; border: 1px solid #f44336; }
60
+ .result-box.info { background: #e3f2fd; color: #1565c0; border: 1px solid #2196f3; }
61
+ .image-preview {
62
+ max-width: 100%;
63
+ border: 2px solid #ddd;
64
+ border-radius: 8px;
65
+ margin: 15px 0;
66
+ }
67
+ .url-display {
68
+ background: #f5f5f5;
69
+ padding: 10px;
70
+ border-radius: 5px;
71
+ font-family: monospace;
72
+ word-break: break-all;
73
+ margin: 10px 0;
74
+ }
75
+ </style>
76
+ </head>
77
+ <body>
78
+ <div class="container">
79
+ <div class="header">
80
+ <h1>🖼️ 直接图片URL测试</h1>
81
+ <p>测试后端生成的直接图片链接是否可以被其他网站引用</p>
82
+ </div>
83
+
84
+ <!-- 测试表单 -->
85
+ <div class="test-section">
86
+ <h3>📝 测试参数</h3>
87
+ <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0;">
88
+ <div>
89
+ <label>用户ID: <input type="text" id="userId" value="PS01" style="width: 100%; padding: 8px;"></label>
90
+ </div>
91
+ <div>
92
+ <label>PPT ID: <input type="text" id="pptId" placeholder="输入PPT ID" style="width: 100%; padding: 8px;"></label>
93
+ </div>
94
+ <div>
95
+ <label>幻灯片索引: <input type="number" id="slideIndex" value="0" style="width: 100%; padding: 8px;"></label>
96
+ </div>
97
+ <div>
98
+ <label>格式:
99
+ <select id="format" style="width: 100%; padding: 8px;">
100
+ <option value="svg">SVG</option>
101
+ <option value="jpeg">JPEG</option>
102
+ <option value="png">PNG</option>
103
+ </select>
104
+ </label>
105
+ </div>
106
+ </div>
107
+
108
+ <button class="test-button" onclick="testDirectImage()">🖼️ 测试直接图片URL</button>
109
+ <button class="test-button" onclick="testImageInIframe()">🌐 测试在iframe中引用</button>
110
+ <button class="test-button" onclick="testImageTag()">📷 测试作为img标签</button>
111
+ </div>
112
+
113
+ <!-- URL显示区域 -->
114
+ <div class="test-section">
115
+ <h3>🔗 生成的图片URL</h3>
116
+ <div id="urlDisplay" class="url-display">
117
+ 点击测试按钮生成URL...
118
+ </div>
119
+ <button class="test-button" onclick="copyURL()" id="copyBtn" style="display: none;">📋 复制URL</button>
120
+ </div>
121
+
122
+ <!-- 图片预览区域 -->
123
+ <div class="test-section">
124
+ <h3>📸 图片预览</h3>
125
+ <div id="imagePreview" style="text-align: center;">
126
+ <p>图片将在这里显示...</p>
127
+ </div>
128
+ </div>
129
+
130
+ <!-- 测试结果 -->
131
+ <div class="test-section">
132
+ <h3>📊 测试结���</h3>
133
+ <div id="testResults" class="result-box info" style="display: none;"></div>
134
+ </div>
135
+
136
+ <!-- 外部引用测试 -->
137
+ <div class="test-section">
138
+ <h3>🌍 外部引用测试</h3>
139
+ <p>以下测试模拟其他网站引用我们的图片URL:</p>
140
+
141
+ <h4>1. 作为IMG标签引用</h4>
142
+ <div id="imgTagTest" style="border: 1px solid #ddd; padding: 20px; margin: 10px 0; background: #f9f9f9;">
143
+ <p>IMG标签测试区域</p>
144
+ </div>
145
+
146
+ <h4>2. 作为CSS背景图片</h4>
147
+ <div id="cssBackgroundTest" style="width: 100%; height: 200px; border: 1px solid #ddd; margin: 10px 0; background: #f9f9f9;">
148
+ <p style="text-align: center; line-height: 200px;">CSS背景图片测试区域</p>
149
+ </div>
150
+
151
+ <h4>3. 在iframe中显示</h4>
152
+ <div id="iframeTest" style="border: 1px solid #ddd; margin: 10px 0;">
153
+ <p>iframe测试区域</p>
154
+ </div>
155
+ </div>
156
+ </div>
157
+
158
+ <script>
159
+ let currentImageURL = '';
160
+
161
+ function showResult(message, type = 'info') {
162
+ const resultsDiv = document.getElementById('testResults');
163
+ resultsDiv.textContent = message;
164
+ resultsDiv.className = `result-box ${type}`;
165
+ resultsDiv.style.display = 'block';
166
+ }
167
+
168
+ function generateImageURL() {
169
+ const userId = document.getElementById('userId').value || 'PS01';
170
+ const pptId = document.getElementById('pptId').value;
171
+ const slideIndex = document.getElementById('slideIndex').value || '0';
172
+ const format = document.getElementById('format').value || 'svg';
173
+
174
+ if (!pptId) {
175
+ alert('请输入PPT ID!');
176
+ return null;
177
+ }
178
+
179
+ // 构建URL
180
+ const baseURL = window.location.origin;
181
+ currentImageURL = `${baseURL}/api/public/direct-image/${userId}/${pptId}/${slideIndex}?format=${format}`;
182
+
183
+ // 显示URL
184
+ document.getElementById('urlDisplay').textContent = currentImageURL;
185
+ document.getElementById('copyBtn').style.display = 'inline-block';
186
+
187
+ return currentImageURL;
188
+ }
189
+
190
+ async function testDirectImage() {
191
+ const url = generateImageURL();
192
+ if (!url) return;
193
+
194
+ showResult('🚀 正在测试直接图片URL...', 'info');
195
+
196
+ try {
197
+ const startTime = performance.now();
198
+ const response = await fetch(url);
199
+ const endTime = performance.now();
200
+
201
+ const contentType = response.headers.get('Content-Type');
202
+ const contentLength = response.headers.get('Content-Length');
203
+ const cacheControl = response.headers.get('Cache-Control');
204
+ const generation = response.headers.get('X-Generation-Time');
205
+
206
+ if (response.ok) {
207
+ const responseTime = Math.round(endTime - startTime);
208
+
209
+ let resultText = `✅ 图片URL测试成功!\n\n`;
210
+ resultText += `📊 响应信息:\n`;
211
+ resultText += ` - 状态码: ${response.status}\n`;
212
+ resultText += ` - 内容类型: ${contentType}\n`;
213
+ resultText += ` - 响应时间: ${responseTime}ms\n`;
214
+ resultText += ` - 生成时间: ${generation || 'N/A'}\n`;
215
+ resultText += ` - 缓存策略: ${cacheControl || 'N/A'}\n`;
216
+ if (contentLength) resultText += ` - 文件大小: ${contentLength} bytes\n`;
217
+
218
+ resultText += `\n🔗 URL测试:\n`;
219
+ resultText += ` - 可以直接访问: ✅\n`;
220
+ resultText += ` - 返回图片数据: ✅\n`;
221
+ resultText += ` - 支持跨域: ${response.headers.get('Access-Control-Allow-Origin') ? '✅' : '❌'}\n`;
222
+
223
+ showResult(resultText, 'success');
224
+
225
+ // 显示图片预览
226
+ updateImagePreview(url);
227
+
228
+ } else {
229
+ showResult(`❌ 图片URL测试失败!\n状态码: ${response.status}\n错误: ${await response.text()}`, 'error');
230
+ }
231
+
232
+ } catch (error) {
233
+ showResult(`❌ 网络请求失败: ${error.message}`, 'error');
234
+ }
235
+ }
236
+
237
+ function updateImagePreview(url) {
238
+ const previewDiv = document.getElementById('imagePreview');
239
+ previewDiv.innerHTML = `
240
+ <img src="${url}" alt="PPT页面预览" class="image-preview"
241
+ onload="showResult(document.getElementById('testResults').textContent + '\\n\\n📸 图片加载成功!可以正常显示。', 'success')"
242
+ onerror="showResult(document.getElementById('testResults').textContent + '\\n\\n❌ 图片加载失败!', 'error')">
243
+ `;
244
+ }
245
+
246
+ function testImageTag() {
247
+ const url = generateImageURL();
248
+ if (!url) return;
249
+
250
+ const imgTagDiv = document.getElementById('imgTagTest');
251
+ imgTagDiv.innerHTML = `
252
+ <h5>IMG标签引用测试:</h5>
253
+ <img src="${url}" alt="PPT页面" style="max-width: 100%; border: 1px solid #ccc;"
254
+ onload="console.log('IMG标签加载成功'); this.nextSibling.textContent = '✅ IMG标签引用成功!'"
255
+ onerror="console.log('IMG标签加载失败'); this.nextSibling.textContent = '❌ IMG标签引用失败!'">
256
+ <p style="color: #666;">加载中...</p>
257
+ `;
258
+
259
+ showResult(`🖼️ 正在测试IMG标签引用...\nURL: ${url}`, 'info');
260
+ }
261
+
262
+ function testImageInIframe() {
263
+ const url = generateImageURL();
264
+ if (!url) return;
265
+
266
+ const iframeDiv = document.getElementById('iframeTest');
267
+ iframeDiv.innerHTML = `
268
+ <h5>iframe引用测试:</h5>
269
+ <iframe src="${url}" style="width: 100%; height: 400px; border: 1px solid #ccc;"
270
+ onload="console.log('iframe加载成功')"
271
+ onerror="console.log('iframe加载失败')"></iframe>
272
+ `;
273
+
274
+ showResult(`🌐 正在测试iframe引用...\nURL: ${url}`, 'info');
275
+ }
276
+
277
+ function copyURL() {
278
+ if (currentImageURL) {
279
+ navigator.clipboard.writeText(currentImageURL).then(() => {
280
+ alert('URL已复制到剪贴板!');
281
+ }).catch(() => {
282
+ // 备用复制方法
283
+ const textArea = document.createElement('textarea');
284
+ textArea.value = currentImageURL;
285
+ document.body.appendChild(textArea);
286
+ textArea.select();
287
+ document.execCommand('copy');
288
+ document.body.removeChild(textArea);
289
+ alert('URL已复制到剪贴板!');
290
+ });
291
+ }
292
+ }
293
+
294
+ // 页面加载完成后的说明
295
+ window.addEventListener('load', function() {
296
+ console.log('🖼️ 直接图片URL测试页面加载完成');
297
+
298
+ // 如果URL中有参数,自动填充
299
+ const urlParams = new URLSearchParams(window.location.search);
300
+ const pptId = urlParams.get('pptId');
301
+ if (pptId) {
302
+ document.getElementById('pptId').value = pptId;
303
+ }
304
+ });
305
+ </script>
306
+ </body>
307
+ </html>