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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>PPTist Huggingface - API 测试页面</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
margin: 0;
|
| 10 |
+
padding: 0;
|
| 11 |
+
box-sizing: border-box;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
body {
|
| 15 |
+
font-family: 'Microsoft YaHei', Arial, sans-serif;
|
| 16 |
+
background: #f5f5f5;
|
| 17 |
+
padding: 20px;
|
| 18 |
+
line-height: 1.6;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.container {
|
| 22 |
+
max-width: 1200px;
|
| 23 |
+
margin: 0 auto;
|
| 24 |
+
background: white;
|
| 25 |
+
padding: 30px;
|
| 26 |
+
border-radius: 10px;
|
| 27 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
h1 {
|
| 31 |
+
color: #333;
|
| 32 |
+
text-align: center;
|
| 33 |
+
margin-bottom: 30px;
|
| 34 |
+
padding-bottom: 15px;
|
| 35 |
+
border-bottom: 3px solid #5b9bd5;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
.section {
|
| 39 |
+
margin-bottom: 30px;
|
| 40 |
+
padding: 20px;
|
| 41 |
+
border: 1px solid #ddd;
|
| 42 |
+
border-radius: 8px;
|
| 43 |
+
background: #fafafa;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
.section h2 {
|
| 47 |
+
color: #5b9bd5;
|
| 48 |
+
margin-bottom: 15px;
|
| 49 |
+
font-size: 1.4em;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.test-group {
|
| 53 |
+
margin-bottom: 20px;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.test-item {
|
| 57 |
+
display: flex;
|
| 58 |
+
align-items: center;
|
| 59 |
+
margin: 10px 0;
|
| 60 |
+
gap: 15px;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.test-button {
|
| 64 |
+
background: #5b9bd5;
|
| 65 |
+
color: white;
|
| 66 |
+
border: none;
|
| 67 |
+
padding: 8px 16px;
|
| 68 |
+
border-radius: 5px;
|
| 69 |
+
cursor: pointer;
|
| 70 |
+
min-width: 120px;
|
| 71 |
+
font-size: 14px;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
.test-button:hover {
|
| 75 |
+
background: #4a8bc2;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.test-button:disabled {
|
| 79 |
+
background: #ccc;
|
| 80 |
+
cursor: not-allowed;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
.endpoint-url {
|
| 84 |
+
font-family: 'Courier New', monospace;
|
| 85 |
+
background: #e8e8e8;
|
| 86 |
+
padding: 5px 8px;
|
| 87 |
+
border-radius: 3px;
|
| 88 |
+
font-size: 12px;
|
| 89 |
+
color: #666;
|
| 90 |
+
flex: 1;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.status {
|
| 94 |
+
padding: 4px 8px;
|
| 95 |
+
border-radius: 3px;
|
| 96 |
+
font-size: 12px;
|
| 97 |
+
font-weight: bold;
|
| 98 |
+
min-width: 80px;
|
| 99 |
+
text-align: center;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.status.success {
|
| 103 |
+
background: #d4edda;
|
| 104 |
+
color: #155724;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.status.error {
|
| 108 |
+
background: #f8d7da;
|
| 109 |
+
color: #721c24;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.status.loading {
|
| 113 |
+
background: #fff3cd;
|
| 114 |
+
color: #856404;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
.result-area {
|
| 118 |
+
margin-top: 20px;
|
| 119 |
+
background: white;
|
| 120 |
+
border: 1px solid #ddd;
|
| 121 |
+
border-radius: 5px;
|
| 122 |
+
max-height: 300px;
|
| 123 |
+
overflow-y: auto;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.result-content {
|
| 127 |
+
padding: 15px;
|
| 128 |
+
font-family: 'Courier New', monospace;
|
| 129 |
+
font-size: 12px;
|
| 130 |
+
white-space: pre-wrap;
|
| 131 |
+
word-break: break-all;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.auth-section {
|
| 135 |
+
background: #e3f2fd;
|
| 136 |
+
border-color: #1976d2;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.github-section {
|
| 140 |
+
background: #f3e5f5;
|
| 141 |
+
border-color: #7b1fa2;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
.ppt-section {
|
| 145 |
+
background: #e8f5e8;
|
| 146 |
+
border-color: #388e3c;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
.public-section {
|
| 150 |
+
background: #fff3e0;
|
| 151 |
+
border-color: #f57c00;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.login-form {
|
| 155 |
+
display: flex;
|
| 156 |
+
gap: 10px;
|
| 157 |
+
margin-bottom: 15px;
|
| 158 |
+
align-items: center;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
.login-form input {
|
| 162 |
+
padding: 8px 12px;
|
| 163 |
+
border: 1px solid #ddd;
|
| 164 |
+
border-radius: 4px;
|
| 165 |
+
font-size: 14px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.token-display {
|
| 169 |
+
font-family: 'Courier New', monospace;
|
| 170 |
+
background: #f0f0f0;
|
| 171 |
+
padding: 8px;
|
| 172 |
+
border-radius: 4px;
|
| 173 |
+
font-size: 12px;
|
| 174 |
+
margin: 10px 0;
|
| 175 |
+
word-break: break-all;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
.clear-button {
|
| 179 |
+
background: #dc3545;
|
| 180 |
+
margin-left: 10px;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.clear-button:hover {
|
| 184 |
+
background: #c82333;
|
| 185 |
+
}
|
| 186 |
+
</style>
|
| 187 |
+
</head>
|
| 188 |
+
<body>
|
| 189 |
+
<div class="container">
|
| 190 |
+
<h1>🚀 PPTist Huggingface Space - API 测试控制台</h1>
|
| 191 |
+
|
| 192 |
+
<!-- GitHub 连接测试 -->
|
| 193 |
+
<div class="section github-section">
|
| 194 |
+
<h2>���� GitHub 仓库连接测试</h2>
|
| 195 |
+
<div class="test-group">
|
| 196 |
+
<div class="test-item">
|
| 197 |
+
<button class="test-button" onclick="testEndpoint('/api/health', 'GET')">健康检查</button>
|
| 198 |
+
<span class="endpoint-url">GET /api/health</span>
|
| 199 |
+
<span id="health-status" class="status">未测试</span>
|
| 200 |
+
</div>
|
| 201 |
+
<div class="test-item">
|
| 202 |
+
<button class="test-button" onclick="testEndpoint('/api/github/status', 'GET')">GitHub 状态</button>
|
| 203 |
+
<span class="endpoint-url">GET /api/github/status</span>
|
| 204 |
+
<span id="github-status-status" class="status">未测试</span>
|
| 205 |
+
</div>
|
| 206 |
+
<div class="test-item">
|
| 207 |
+
<button class="test-button" onclick="testEndpoint('/api/github/test', 'GET')">GitHub 连接测试</button>
|
| 208 |
+
<span class="endpoint-url">GET /api/github/test</span>
|
| 209 |
+
<span id="github-test-status" class="status">未测试</span>
|
| 210 |
+
</div>
|
| 211 |
+
</div>
|
| 212 |
+
</div>
|
| 213 |
+
|
| 214 |
+
<!-- 认证测试 -->
|
| 215 |
+
<div class="section auth-section">
|
| 216 |
+
<h2>🔐 用户认证测试</h2>
|
| 217 |
+
<div class="login-form">
|
| 218 |
+
<input type="text" id="username" placeholder="用户名" value="PS01">
|
| 219 |
+
<input type="password" id="password" placeholder="密码" value="admin_cybercity2025">
|
| 220 |
+
<button class="test-button" onclick="testLogin()">登录测试</button>
|
| 221 |
+
<button class="test-button clear-button" onclick="clearToken()">清除Token</button>
|
| 222 |
+
</div>
|
| 223 |
+
<div class="token-display" id="token-display">当前Token: 未登录</div>
|
| 224 |
+
|
| 225 |
+
<div class="test-group">
|
| 226 |
+
<div class="test-item">
|
| 227 |
+
<button class="test-button" onclick="testEndpoint('/api/auth/verify', 'GET', true)">验证Token</button>
|
| 228 |
+
<span class="endpoint-url">GET /api/auth/verify</span>
|
| 229 |
+
<span id="auth-verify-status" class="status">未测试</span>
|
| 230 |
+
</div>
|
| 231 |
+
<div class="test-item">
|
| 232 |
+
<button class="test-button" onclick="testEndpoint('/api/auth/user', 'GET', true)">获取用户信息</button>
|
| 233 |
+
<span class="endpoint-url">GET /api/auth/user</span>
|
| 234 |
+
<span id="auth-user-status" class="status">未测试</span>
|
| 235 |
+
</div>
|
| 236 |
+
</div>
|
| 237 |
+
</div>
|
| 238 |
+
|
| 239 |
+
<!-- PPT 管理测试 -->
|
| 240 |
+
<div class="section ppt-section">
|
| 241 |
+
<h2>📄 PPT 管理测试</h2>
|
| 242 |
+
<div class="test-group">
|
| 243 |
+
<div class="test-item">
|
| 244 |
+
<button class="test-button" onclick="testEndpoint('/api/ppt/test', 'GET')">PPT 路由测试</button>
|
| 245 |
+
<span class="endpoint-url">GET /api/ppt/test</span>
|
| 246 |
+
<span id="ppt-test-status" class="status">未测试</span>
|
| 247 |
+
</div>
|
| 248 |
+
<div class="test-item">
|
| 249 |
+
<button class="test-button" onclick="testEndpoint('/api/ppt/list', 'GET', true)">获取PPT列表</button>
|
| 250 |
+
<span class="endpoint-url">GET /api/ppt/list</span>
|
| 251 |
+
<span id="ppt-list-status" class="status">未测试</span>
|
| 252 |
+
</div>
|
| 253 |
+
<div class="test-item">
|
| 254 |
+
<button class="test-button" onclick="testCreatePPT()">创建PPT</button>
|
| 255 |
+
<span class="endpoint-url">POST /api/ppt/create</span>
|
| 256 |
+
<span id="ppt-create-status" class="status">未测试</span>
|
| 257 |
+
</div>
|
| 258 |
+
<div class="test-item">
|
| 259 |
+
<button class="test-button" onclick="testSavePPT()">保存PPT</button>
|
| 260 |
+
<span class="endpoint-url">POST /api/ppt/save</span>
|
| 261 |
+
<span id="ppt-save-status" class="status">未测试</span>
|
| 262 |
+
</div>
|
| 263 |
+
</div>
|
| 264 |
+
</div>
|
| 265 |
+
|
| 266 |
+
<!-- 公共分享测试 -->
|
| 267 |
+
<div class="section public-section">
|
| 268 |
+
<h2>🌐 公共分享测试</h2>
|
| 269 |
+
<div class="test-group">
|
| 270 |
+
<div class="test-item">
|
| 271 |
+
<button class="test-button" onclick="testGenerateShareLink()">生成分享链接</button>
|
| 272 |
+
<span class="endpoint-url">POST /api/public/generate-share-link</span>
|
| 273 |
+
<span id="public-generate-status" class="status">未测试</span>
|
| 274 |
+
</div>
|
| 275 |
+
<div class="test-item">
|
| 276 |
+
<button class="test-button" onclick="testEndpoint('/api/public/ppt/PS01/test-ppt-id', 'GET')">获取公共PPT</button>
|
| 277 |
+
<span class="endpoint-url">GET /api/public/ppt/:userId/:pptId</span>
|
| 278 |
+
<span id="public-ppt-status" class="status">未测试</span>
|
| 279 |
+
</div>
|
| 280 |
+
<div class="test-item">
|
| 281 |
+
<button class="test-button" onclick="testEndpoint('/api/public/view/PS01/test-ppt-id/0', 'GET')">公开查看页面</button>
|
| 282 |
+
<span class="endpoint-url">GET /api/public/view/:userId/:pptId/:slideIndex</span>
|
| 283 |
+
<span id="public-view-status" class="status">未测试</span>
|
| 284 |
+
</div>
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
|
| 288 |
+
<!-- 结果显示区域 -->
|
| 289 |
+
<div class="section">
|
| 290 |
+
<h2>📋 测试结果</h2>
|
| 291 |
+
<div class="result-area">
|
| 292 |
+
<div class="result-content" id="result-content">点击上方按钮开始测试...</div>
|
| 293 |
+
</div>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
|
| 297 |
+
<script>
|
| 298 |
+
let currentToken = localStorage.getItem('test_token') || '';
|
| 299 |
+
let testPptId = '';
|
| 300 |
+
|
| 301 |
+
// 更新Token显示
|
| 302 |
+
function updateTokenDisplay() {
|
| 303 |
+
const display = document.getElementById('token-display');
|
| 304 |
+
if (currentToken) {
|
| 305 |
+
display.textContent = `当前Token: ${currentToken.substring(0, 20)}...`;
|
| 306 |
+
} else {
|
| 307 |
+
display.textContent = '当前Token: 未登录';
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
// 清除Token
|
| 312 |
+
function clearToken() {
|
| 313 |
+
currentToken = '';
|
| 314 |
+
localStorage.removeItem('test_token');
|
| 315 |
+
updateTokenDisplay();
|
| 316 |
+
logResult('Token已清除');
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
// 初始化显示
|
| 320 |
+
updateTokenDisplay();
|
| 321 |
+
|
| 322 |
+
// 记录结果
|
| 323 |
+
function logResult(message) {
|
| 324 |
+
const resultContent = document.getElementById('result-content');
|
| 325 |
+
const timestamp = new Date().toLocaleTimeString();
|
| 326 |
+
resultContent.textContent += `[${timestamp}] ${message}\n`;
|
| 327 |
+
resultContent.scrollTop = resultContent.scrollHeight;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
// 更新状态
|
| 331 |
+
function updateStatus(elementId, status, message = '') {
|
| 332 |
+
const element = document.getElementById(elementId);
|
| 333 |
+
element.className = `status ${status}`;
|
| 334 |
+
element.textContent = status === 'success' ? '成功' : status === 'error' ? '失败' : status === 'loading' ? '测试中...' : '未测试';
|
| 335 |
+
if (message) {
|
| 336 |
+
logResult(`${elementId}: ${message}`);
|
| 337 |
+
}
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
// 登录测试
|
| 341 |
+
async function testLogin() {
|
| 342 |
+
const username = document.getElementById('username').value;
|
| 343 |
+
const password = document.getElementById('password').value;
|
| 344 |
+
|
| 345 |
+
if (!username || !password) {
|
| 346 |
+
alert('请输入用户名和密码');
|
| 347 |
+
return;
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
try {
|
| 351 |
+
logResult(`尝试登录用户: ${username}`);
|
| 352 |
+
|
| 353 |
+
const response = await fetch('/api/auth/login', {
|
| 354 |
+
method: 'POST',
|
| 355 |
+
headers: {
|
| 356 |
+
'Content-Type': 'application/json',
|
| 357 |
+
},
|
| 358 |
+
body: JSON.stringify({ username, password }),
|
| 359 |
+
});
|
| 360 |
+
|
| 361 |
+
const data = await response.json();
|
| 362 |
+
|
| 363 |
+
if (response.ok && data.token) {
|
| 364 |
+
currentToken = data.token;
|
| 365 |
+
localStorage.setItem('test_token', currentToken);
|
| 366 |
+
updateTokenDisplay();
|
| 367 |
+
logResult(`登录成功! 用户: ${data.user.username}, 角色: ${data.user.role}`);
|
| 368 |
+
updateStatus('login-status', 'success');
|
| 369 |
+
} else {
|
| 370 |
+
logResult(`登录失败: ${data.error || '未知错误'}`);
|
| 371 |
+
updateStatus('login-status', 'error');
|
| 372 |
+
}
|
| 373 |
+
} catch (error) {
|
| 374 |
+
logResult(`登录请求失败: ${error.message}`);
|
| 375 |
+
updateStatus('login-status', 'error');
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
// 通用测试端点
|
| 380 |
+
async function testEndpoint(url, method = 'GET', requireAuth = false, body = null) {
|
| 381 |
+
const statusId = url.replace(/[^a-zA-Z0-9]/g, '-') + '-status';
|
| 382 |
+
|
| 383 |
+
try {
|
| 384 |
+
updateStatus(statusId, 'loading');
|
| 385 |
+
logResult(`测试端点: ${method} ${url}`);
|
| 386 |
+
|
| 387 |
+
const headers = {
|
| 388 |
+
'Content-Type': 'application/json',
|
| 389 |
+
};
|
| 390 |
+
|
| 391 |
+
if (requireAuth && currentToken) {
|
| 392 |
+
headers.Authorization = `Bearer ${currentToken}`;
|
| 393 |
+
} else if (requireAuth && !currentToken) {
|
| 394 |
+
logResult(`错误: 需要登录才能访问 ${url}`);
|
| 395 |
+
updateStatus(statusId, 'error');
|
| 396 |
+
return;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
const options = {
|
| 400 |
+
method,
|
| 401 |
+
headers,
|
| 402 |
+
};
|
| 403 |
+
|
| 404 |
+
if (body) {
|
| 405 |
+
options.body = JSON.stringify(body);
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
const response = await fetch(url, options);
|
| 409 |
+
const data = await response.text();
|
| 410 |
+
|
| 411 |
+
let jsonData;
|
| 412 |
+
try {
|
| 413 |
+
jsonData = JSON.parse(data);
|
| 414 |
+
} catch {
|
| 415 |
+
jsonData = data;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
if (response.ok) {
|
| 419 |
+
logResult(`✅ ${method} ${url} - 状态: ${response.status}`);
|
| 420 |
+
logResult(`响应: ${JSON.stringify(jsonData, null, 2)}`);
|
| 421 |
+
updateStatus(statusId, 'success');
|
| 422 |
+
return jsonData;
|
| 423 |
+
} else {
|
| 424 |
+
logResult(`❌ ${method} ${url} - 状态: ${response.status}`);
|
| 425 |
+
logResult(`错误: ${JSON.stringify(jsonData, null, 2)}`);
|
| 426 |
+
updateStatus(statusId, 'error');
|
| 427 |
+
}
|
| 428 |
+
} catch (error) {
|
| 429 |
+
logResult(`❌ ${method} ${url} - 网络错误: ${error.message}`);
|
| 430 |
+
updateStatus(statusId, 'error');
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
// 创建PPT测试
|
| 435 |
+
async function testCreatePPT() {
|
| 436 |
+
if (!currentToken) {
|
| 437 |
+
alert('请先登录');
|
| 438 |
+
return;
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
const title = `测试PPT - ${new Date().toLocaleString()}`;
|
| 442 |
+
const body = { title };
|
| 443 |
+
|
| 444 |
+
try {
|
| 445 |
+
updateStatus('ppt-create-status', 'loading');
|
| 446 |
+
logResult(`创建PPT: ${title}`);
|
| 447 |
+
|
| 448 |
+
const response = await fetch('/api/ppt/create', {
|
| 449 |
+
method: 'POST',
|
| 450 |
+
headers: {
|
| 451 |
+
'Content-Type': 'application/json',
|
| 452 |
+
'Authorization': `Bearer ${currentToken}`,
|
| 453 |
+
},
|
| 454 |
+
body: JSON.stringify(body),
|
| 455 |
+
});
|
| 456 |
+
|
| 457 |
+
const data = await response.json();
|
| 458 |
+
|
| 459 |
+
if (response.ok && data.pptId) {
|
| 460 |
+
testPptId = data.pptId;
|
| 461 |
+
logResult(`✅ PPT创建成功! ID: ${testPptId}`);
|
| 462 |
+
logResult(`PPT数据: ${JSON.stringify(data, null, 2)}`);
|
| 463 |
+
updateStatus('ppt-create-status', 'success');
|
| 464 |
+
} else {
|
| 465 |
+
logResult(`❌ PPT创建失败: ${data.error || '未知错误'}`);
|
| 466 |
+
updateStatus('ppt-create-status', 'error');
|
| 467 |
+
}
|
| 468 |
+
} catch (error) {
|
| 469 |
+
logResult(`❌ PPT创建请求失败: ${error.message}`);
|
| 470 |
+
updateStatus('ppt-create-status', 'error');
|
| 471 |
+
}
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
// 保存PPT测试
|
| 475 |
+
async function testSavePPT() {
|
| 476 |
+
if (!currentToken) {
|
| 477 |
+
alert('请先登录');
|
| 478 |
+
return;
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
if (!testPptId) {
|
| 482 |
+
alert('请先创建一个PPT');
|
| 483 |
+
return;
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
const pptData = {
|
| 487 |
+
pptId: testPptId,
|
| 488 |
+
title: '测试PPT - 已保存',
|
| 489 |
+
slides: [
|
| 490 |
+
{
|
| 491 |
+
id: 'slide-1',
|
| 492 |
+
elements: [
|
| 493 |
+
{
|
| 494 |
+
type: 'text',
|
| 495 |
+
id: 'text-1',
|
| 496 |
+
left: 100,
|
| 497 |
+
top: 100,
|
| 498 |
+
width: 300,
|
| 499 |
+
height: 50,
|
| 500 |
+
content: '这是一个测试文本',
|
| 501 |
+
fontSize: 24,
|
| 502 |
+
defaultColor: '#333333'
|
| 503 |
+
}
|
| 504 |
+
],
|
| 505 |
+
background: { type: 'solid', color: '#ffffff' }
|
| 506 |
+
}
|
| 507 |
+
],
|
| 508 |
+
theme: {
|
| 509 |
+
backgroundColor: '#ffffff',
|
| 510 |
+
themeColor: '#5b9bd5'
|
| 511 |
+
}
|
| 512 |
+
};
|
| 513 |
+
|
| 514 |
+
try {
|
| 515 |
+
updateStatus('ppt-save-status', 'loading');
|
| 516 |
+
logResult(`保存PPT: ${testPptId}`);
|
| 517 |
+
|
| 518 |
+
const response = await fetch('/api/ppt/save', {
|
| 519 |
+
method: 'POST',
|
| 520 |
+
headers: {
|
| 521 |
+
'Content-Type': 'application/json',
|
| 522 |
+
'Authorization': `Bearer ${currentToken}`,
|
| 523 |
+
},
|
| 524 |
+
body: JSON.stringify(pptData),
|
| 525 |
+
});
|
| 526 |
+
|
| 527 |
+
const data = await response.json();
|
| 528 |
+
|
| 529 |
+
if (response.ok) {
|
| 530 |
+
logResult(`✅ PPT保存成功!`);
|
| 531 |
+
logResult(`响应: ${JSON.stringify(data, null, 2)}`);
|
| 532 |
+
updateStatus('ppt-save-status', 'success');
|
| 533 |
+
} else {
|
| 534 |
+
logResult(`❌ PPT保存失败: ${data.error || '未知错误'}`);
|
| 535 |
+
updateStatus('ppt-save-status', 'error');
|
| 536 |
+
}
|
| 537 |
+
} catch (error) {
|
| 538 |
+
logResult(`❌ PPT保存请求失败: ${error.message}`);
|
| 539 |
+
updateStatus('ppt-save-status', 'error');
|
| 540 |
+
}
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
// 生成分享链接测试
|
| 544 |
+
async function testGenerateShareLink() {
|
| 545 |
+
if (!testPptId) {
|
| 546 |
+
alert('请先创建并保存一个PPT');
|
| 547 |
+
return;
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
const body = {
|
| 551 |
+
userId: 'PS01',
|
| 552 |
+
pptId: testPptId,
|
| 553 |
+
slideIndex: 0
|
| 554 |
+
};
|
| 555 |
+
|
| 556 |
+
try {
|
| 557 |
+
updateStatus('public-generate-status', 'loading');
|
| 558 |
+
logResult(`生成分享链接 - PPT ID: ${testPptId}`);
|
| 559 |
+
|
| 560 |
+
const response = await fetch('/api/public/generate-share-link', {
|
| 561 |
+
method: 'POST',
|
| 562 |
+
headers: {
|
| 563 |
+
'Content-Type': 'application/json',
|
| 564 |
+
},
|
| 565 |
+
body: JSON.stringify(body),
|
| 566 |
+
});
|
| 567 |
+
|
| 568 |
+
const data = await response.json();
|
| 569 |
+
|
| 570 |
+
if (response.ok) {
|
| 571 |
+
logResult(`✅ 分享链接生成成功!`);
|
| 572 |
+
logResult(`单页链接: ${data.slideUrl}`);
|
| 573 |
+
logResult(`完整PPT链接: ${data.pptUrl}`);
|
| 574 |
+
logResult(`前端查看链接: ${data.viewUrl}`);
|
| 575 |
+
updateStatus('public-generate-status', 'success');
|
| 576 |
+
} else {
|
| 577 |
+
logResult(`❌ 分享链接生成失败: ${data.error || '未知错误'}`);
|
| 578 |
+
updateStatus('public-generate-status', 'error');
|
| 579 |
+
}
|
| 580 |
+
} catch (error) {
|
| 581 |
+
logResult(`❌ 分享链接生成请求失败: ${error.message}`);
|
| 582 |
+
updateStatus('public-generate-status', 'error');
|
| 583 |
+
}
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
// 页面加载时运行初始测试
|
| 587 |
+
window.addEventListener('load', () => {
|
| 588 |
+
logResult('🚀 PPTist API 测试控制台已就绪');
|
| 589 |
+
logResult('📌 建议测试顺序:');
|
| 590 |
+
logResult(' 1. 先测试健康检查和GitHub连接');
|
| 591 |
+
logResult(' 2. 进行用户登录测试');
|
| 592 |
+
logResult(' 3. 测试PPT管理功能');
|
| 593 |
+
logResult(' 4. 测试公共分享功能');
|
| 594 |
+
logResult('');
|
| 595 |
+
});
|
| 596 |
+
</script>
|
| 597 |
+
</body>
|
| 598 |
+
</html>
|