test-api.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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>API 测试</title>
  7. <style>
  8. body {
  9. font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  10. max-width: 900px;
  11. margin: 50px auto;
  12. padding: 20px;
  13. background: #f5f5f5;
  14. }
  15. .container {
  16. background: white;
  17. padding: 30px;
  18. border-radius: 8px;
  19. box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  20. }
  21. button {
  22. background: #1890ff;
  23. color: white;
  24. border: none;
  25. padding: 10px 20px;
  26. border-radius: 4px;
  27. cursor: pointer;
  28. font-size: 14px;
  29. margin-right: 10px;
  30. }
  31. button:hover {
  32. background: #40a9ff;
  33. }
  34. .result {
  35. margin-top: 20px;
  36. padding: 15px;
  37. background: #f0f0f0;
  38. border-radius: 4px;
  39. white-space: pre-wrap;
  40. font-family: 'Courier New', monospace;
  41. font-size: 12px;
  42. max-height: 500px;
  43. overflow: auto;
  44. }
  45. .error {
  46. color: #ff4d4f;
  47. background: #fff2f0;
  48. border: 1px solid #ffccc7;
  49. }
  50. .success {
  51. color: #52c41a;
  52. background: #f6ffed;
  53. border: 1px solid #b7eb8f;
  54. }
  55. input {
  56. padding: 8px;
  57. border: 1px solid #d9d9d9;
  58. border-radius: 4px;
  59. width: 300px;
  60. font-size: 14px;
  61. }
  62. .input-group {
  63. margin: 15px 0;
  64. }
  65. label {
  66. display: inline-block;
  67. width: 120px;
  68. font-weight: 500;
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <div class="container">
  74. <h1>📡 Document Content API 测试</h1>
  75. <div class="input-group">
  76. <label>API Base URL:</label>
  77. <input type="text" id="baseUrl" value="http://192.168.0.195:8000" />
  78. </div>
  79. <div class="input-group">
  80. <label>Record ID:</label>
  81. <input type="text" id="recordId" value="rec-48d00cf5664a" />
  82. </div>
  83. <div class="input-group">
  84. <label>User ID:</label>
  85. <input type="text" id="userId" value="default-user" />
  86. </div>
  87. <div>
  88. <button onclick="testListRecords()">测试列表 API</button>
  89. <button onclick="testContentAPI()">测试内容 API</button>
  90. <button onclick="clearResult()">清空结果</button>
  91. </div>
  92. <div id="result" class="result"></div>
  93. </div>
  94. <script>
  95. function getBaseUrl() {
  96. return document.getElementById('baseUrl').value;
  97. }
  98. function getRecordId() {
  99. return document.getElementById('recordId').value;
  100. }
  101. function getUserId() {
  102. return document.getElementById('userId').value;
  103. }
  104. function showResult(data, isError = false) {
  105. const resultDiv = document.getElementById('result');
  106. resultDiv.className = 'result ' + (isError ? 'error' : 'success');
  107. resultDiv.textContent = JSON.stringify(data, null, 2);
  108. }
  109. function clearResult() {
  110. document.getElementById('result').textContent = '';
  111. document.getElementById('result').className = 'result';
  112. }
  113. async function testListRecords() {
  114. try {
  115. const baseUrl = getBaseUrl();
  116. const userId = getUserId();
  117. const url = `${baseUrl}/api/v1/export/records?userId=${userId}&page=1&pageSize=5`;
  118. console.log('Fetching:', url);
  119. const response = await fetch(url);
  120. if (!response.ok) {
  121. throw new Error(`HTTP ${response.status}: ${response.statusText}`);
  122. }
  123. const data = await response.json();
  124. console.log('Response:', data);
  125. showResult({
  126. status: '✅ SUCCESS',
  127. code: data.code,
  128. records: data.data.records.length,
  129. data: data
  130. });
  131. } catch (error) {
  132. console.error('Error:', error);
  133. showResult({
  134. status: '❌ ERROR',
  135. message: error.message,
  136. error: error
  137. }, true);
  138. }
  139. }
  140. async function testContentAPI() {
  141. try {
  142. const baseUrl = getBaseUrl();
  143. const recordId = getRecordId();
  144. const userId = getUserId();
  145. const url = `${baseUrl}/api/v1/export/records/${recordId}/content?userId=${userId}`;
  146. console.log('Fetching:', url);
  147. const response = await fetch(url);
  148. if (!response.ok) {
  149. const text = await response.text();
  150. throw new Error(`HTTP ${response.status}: ${response.statusText}\n${text}`);
  151. }
  152. const data = await response.json();
  153. console.log('Response:', data);
  154. showResult({
  155. status: '✅ SUCCESS',
  156. code: data.code,
  157. fileName: data.data.fileName,
  158. outlineItems: data.data.outline.length,
  159. contentBlocks: data.data.content.length,
  160. outline: data.data.outline,
  161. sample_content: data.data.content.slice(0, 3)
  162. });
  163. } catch (error) {
  164. console.error('Error:', error);
  165. showResult({
  166. status: '❌ ERROR',
  167. message: error.message,
  168. error: error.toString()
  169. }, true);
  170. }
  171. }
  172. // Auto-test on load
  173. window.addEventListener('load', () => {
  174. console.log('Page loaded, ready to test');
  175. });
  176. </script>
  177. </body>
  178. </html>