-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy pathtest-batch-api.html
More file actions
112 lines (96 loc) · 3.5 KB
/
test-batch-api.html
File metadata and controls
112 lines (96 loc) · 3.5 KB
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
<!DOCTYPE html>
<html>
<head>
<title>测试批量书签 API</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
.form-group { margin-bottom: 15px; }
label { display: block; margin-bottom: 5px; font-weight: bold; }
input, textarea { width: 100%; padding: 8px; box-sizing: border-box; }
button { padding: 10px 20px; background: #007bff; color: white; border: none; cursor: pointer; }
button:hover { background: #0056b3; }
#result { margin-top: 20px; padding: 15px; border: 1px solid #ddd; background: #f9f9f9; white-space: pre-wrap; }
</style>
</head>
<body>
<h1>测试批量书签 API</h1>
<div class="form-group">
<label>TMarks URL:</label>
<input type="text" id="tmarksUrl" value="https://tmarks.insightai.top" />
</div>
<div class="form-group">
<label>API Key:</label>
<input type="text" id="apiKey" placeholder="输入你的 API Key" />
</div>
<div class="form-group">
<label>测试数据(JSON):</label>
<textarea id="testData" rows="10">{
"bookmarks": [
{
"title": "测试书签1",
"url": "https://example.com/1",
"description": "测试描述1",
"tags": ["测试", "标签1"]
},
{
"title": "测试书签2",
"url": "https://example.com/2",
"description": "测试描述2",
"tags": ["测试", "标签2"]
}
]
}</textarea>
</div>
<button onclick="testAPI()">发送测试请求</button>
<div id="result"></div>
<script>
async function testAPI() {
const tmarksUrl = document.getElementById('tmarksUrl').value.trim();
const apiKey = document.getElementById('apiKey').value.trim();
const testDataStr = document.getElementById('testData').value.trim();
const resultDiv = document.getElementById('result');
if (!apiKey) {
resultDiv.textContent = '错误:请输入 API Key';
return;
}
let testData;
try {
testData = JSON.parse(testDataStr);
} catch (e) {
resultDiv.textContent = '错误:测试数据不是有效的 JSON\n' + e.message;
return;
}
resultDiv.textContent = '发送请求中...';
const apiUrl = `${tmarksUrl}/api/tab/bookmarks`;
console.log('请求 URL:', apiUrl);
console.log('请求头:', { 'Content-Type': 'application/json', 'X-API-Key': apiKey });
console.log('请求体:', JSON.stringify(testData, null, 2));
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': apiKey
},
body: JSON.stringify(testData)
});
const responseText = await response.text();
let responseData;
try {
responseData = JSON.parse(responseText);
} catch (e) {
responseData = responseText;
}
resultDiv.textContent = `状态码: ${response.status} ${response.statusText}\n\n` +
`响应头:\n${JSON.stringify(Object.fromEntries(response.headers.entries()), null, 2)}\n\n` +
`响应体:\n${JSON.stringify(responseData, null, 2)}`;
console.log('响应状态:', response.status);
console.log('响应体:', responseData);
} catch (error) {
resultDiv.textContent = '请求失败:\n' + error.message;
console.error('请求错误:', error);
}
}
</script>
</body>
</html>