-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
169 lines (157 loc) · 5.05 KB
/
Copy pathindex.html
File metadata and controls
169 lines (157 loc) · 5.05 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>EdgeOne Makers KV 能力测试</title>
<style>
* { box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
max-width: 900px;
margin: 0 auto;
padding: 24px;
color: #1a1a1a;
background: #fafafa;
}
h1 { font-size: 22px; }
.desc { color: #666; font-size: 14px; line-height: 1.6; }
.card {
background: #fff;
border: 1px solid #e5e5e5;
border-radius: 8px;
padding: 16px;
margin: 16px 0;
}
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
label { font-size: 13px; color: #444; width: 60px; }
input, select {
padding: 6px 10px;
border: 1px solid #ccc;
border-radius: 6px;
font-size: 14px;
flex: 1;
min-width: 120px;
}
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
button {
padding: 8px 14px;
border: none;
border-radius: 6px;
background: #2563eb;
color: #fff;
font-size: 14px;
cursor: pointer;
}
button:hover { background: #1d4ed8; }
button.secondary { background: #6b7280; }
button.secondary:hover { background: #4b5563; }
button.danger { background: #dc2626; }
button.danger:hover { background: #b91c1c; }
pre {
background: #0d1117;
color: #c9d1d9;
padding: 14px;
border-radius: 8px;
overflow: auto;
max-height: 480px;
font-size: 12.5px;
line-height: 1.5;
}
.clear { float: right; background: transparent; color: #888; padding: 2px 8px; font-size: 12px; }
.clear:hover { background: #eee; color: #333; }
</style>
</head>
<body>
<h1>EdgeOne Makers KV 能力测试</h1>
<p class="desc">
每个 KV 能力对应一个独立 Function。需在 EdgeOne Makers 控制台把 KV namespace 绑定为变量名
<code>my_kv</code>。下方逐个测试各能力,结果打到日志区。
</p>
<div class="card">
<div class="row">
<label>key</label>
<input id="key" value="hello" />
</div>
<div class="row">
<label>value</label>
<input id="value" value="world" />
</div>
<div class="row">
<label>type</label>
<select id="type">
<option value="text">text</option>
<option value="json">json</option>
</select>
<label>prefix</label>
<input id="prefix" value="" placeholder="list 前缀,空=全部" />
</div>
<div class="btns">
<button onclick="doPut()">Put</button>
<button onclick="doGet()">Get</button>
<button class="danger" onclick="doDelete()">Delete</button>
<button class="danger" onclick="doDeleteAll()">Delete All</button>
<button class="secondary" onclick="doList()">List</button>
<button class="secondary" onclick="doCounter()">Counter +1</button>
</div>
</div>
<div class="card">
<button class="clear" onclick="document.getElementById('log').textContent=''">清空日志</button>
<strong>日志</strong>
<pre id="log"></pre>
</div>
<script>
const $ = (id) => document.getElementById(id);
const logEl = $('log');
function log(title, data) {
const line = `[${new Date().toLocaleTimeString()}] ${title}\n` +
(typeof data === 'string' ? data : JSON.stringify(data, null, 2)) + '\n\n';
logEl.textContent = line + logEl.textContent;
}
async function call(title, url, options) {
try {
const res = await fetch(url, options);
const json = await res.json();
log(title, json);
return json;
} catch (e) {
log(title + ' [ERROR]', e.message);
throw e;
}
}
function doPut() {
const key = $('key').value;
let value = $('value').value;
// type=json 时把输入按 JSON 解析写入
if ($('type').value === 'json') {
try { value = JSON.parse(value); } catch (_) { /* 保持原字符串 */ }
}
return call('PUT /kv-put', '/kv-put', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ key, value }),
});
}
function doGet() {
const key = encodeURIComponent($('key').value);
const type = $('type').value;
return call('GET /kv-get', `/kv-get?key=${key}&type=${type}`);
}
function doDelete() {
const key = encodeURIComponent($('key').value);
return call('DELETE /kv-delete', `/kv-delete?key=${key}`);
}
function doDeleteAll() {
if (!confirm('确认删除全部 key?此操作不可恢复。')) return;
return call('GET /kv-delete-all', '/kv-delete-all');
}
function doList() {
const prefix = encodeURIComponent($('prefix').value);
return call('GET /kv-list', `/kv-list?prefix=${prefix}&limit=10`);
}
function doCounter() {
return call('GET /kv-counter', '/kv-counter');
}
</script>
</body>
</html>