| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>API 测试</title>
- <style>
- body {
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
- max-width: 900px;
- margin: 50px auto;
- padding: 20px;
- background: #f5f5f5;
- }
- .container {
- background: white;
- padding: 30px;
- border-radius: 8px;
- box-shadow: 0 2px 8px rgba(0,0,0,0.1);
- }
- button {
- background: #1890ff;
- color: white;
- border: none;
- padding: 10px 20px;
- border-radius: 4px;
- cursor: pointer;
- font-size: 14px;
- margin-right: 10px;
- }
- button:hover {
- background: #40a9ff;
- }
- .result {
- margin-top: 20px;
- padding: 15px;
- background: #f0f0f0;
- border-radius: 4px;
- white-space: pre-wrap;
- font-family: 'Courier New', monospace;
- font-size: 12px;
- max-height: 500px;
- overflow: auto;
- }
- .error {
- color: #ff4d4f;
- background: #fff2f0;
- border: 1px solid #ffccc7;
- }
- .success {
- color: #52c41a;
- background: #f6ffed;
- border: 1px solid #b7eb8f;
- }
- input {
- padding: 8px;
- border: 1px solid #d9d9d9;
- border-radius: 4px;
- width: 300px;
- font-size: 14px;
- }
- .input-group {
- margin: 15px 0;
- }
- label {
- display: inline-block;
- width: 120px;
- font-weight: 500;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>📡 Document Content API 测试</h1>
-
- <div class="input-group">
- <label>API Base URL:</label>
- <input type="text" id="baseUrl" value="http://192.168.0.195:8000" />
- </div>
-
- <div class="input-group">
- <label>Record ID:</label>
- <input type="text" id="recordId" value="rec-48d00cf5664a" />
- </div>
-
- <div class="input-group">
- <label>User ID:</label>
- <input type="text" id="userId" value="default-user" />
- </div>
-
- <div>
- <button onclick="testListRecords()">测试列表 API</button>
- <button onclick="testContentAPI()">测试内容 API</button>
- <button onclick="clearResult()">清空结果</button>
- </div>
-
- <div id="result" class="result"></div>
- </div>
- <script>
- function getBaseUrl() {
- return document.getElementById('baseUrl').value;
- }
-
- function getRecordId() {
- return document.getElementById('recordId').value;
- }
-
- function getUserId() {
- return document.getElementById('userId').value;
- }
-
- function showResult(data, isError = false) {
- const resultDiv = document.getElementById('result');
- resultDiv.className = 'result ' + (isError ? 'error' : 'success');
- resultDiv.textContent = JSON.stringify(data, null, 2);
- }
-
- function clearResult() {
- document.getElementById('result').textContent = '';
- document.getElementById('result').className = 'result';
- }
-
- async function testListRecords() {
- try {
- const baseUrl = getBaseUrl();
- const userId = getUserId();
- const url = `${baseUrl}/api/v1/export/records?userId=${userId}&page=1&pageSize=5`;
-
- console.log('Fetching:', url);
- const response = await fetch(url);
-
- if (!response.ok) {
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
- }
-
- const data = await response.json();
- console.log('Response:', data);
-
- showResult({
- status: '✅ SUCCESS',
- code: data.code,
- records: data.data.records.length,
- data: data
- });
- } catch (error) {
- console.error('Error:', error);
- showResult({
- status: '❌ ERROR',
- message: error.message,
- error: error
- }, true);
- }
- }
-
- async function testContentAPI() {
- try {
- const baseUrl = getBaseUrl();
- const recordId = getRecordId();
- const userId = getUserId();
- const url = `${baseUrl}/api/v1/export/records/${recordId}/content?userId=${userId}`;
-
- console.log('Fetching:', url);
- const response = await fetch(url);
-
- if (!response.ok) {
- const text = await response.text();
- throw new Error(`HTTP ${response.status}: ${response.statusText}\n${text}`);
- }
-
- const data = await response.json();
- console.log('Response:', data);
-
- showResult({
- status: '✅ SUCCESS',
- code: data.code,
- fileName: data.data.fileName,
- outlineItems: data.data.outline.length,
- contentBlocks: data.data.content.length,
- outline: data.data.outline,
- sample_content: data.data.content.slice(0, 3)
- });
- } catch (error) {
- console.error('Error:', error);
- showResult({
- status: '❌ ERROR',
- message: error.message,
- error: error.toString()
- }, true);
- }
- }
-
- // Auto-test on load
- window.addEventListener('load', () => {
- console.log('Page loaded, ready to test');
- });
- </script>
- </body>
- </html>
|