33 <div class =" grid gap-4 md:grid-cols-2" >
44 <section class =" rounded-xl border border-slate-200 bg-slate-50 p-4" >
55 <div class =" mb-3 text-xs font-semibold uppercase tracking-wider text-slate-500" >
6- LevelDB
6+ Key/Value
77 </div >
88 <div class =" flex flex-col gap-3" >
99 <div class =" flex w-full gap-3" >
10- <Input class="w-full" v-model =" levelDbKey " placeholder="LevelDB key " />
11- <Input class="w-full" v-model =" levelDbValue " placeholder="LevelDB value " />
10+ <Input class="w-full" v-model =" kvKey " placeholder="Key " />
11+ <Input class="w-full" v-model =" kvValue " placeholder="Value " />
1212 </div >
13- <Button class="w-full" @click =" addLevelDbKeyValue " >
14- Add level DB key/value
13+ <Button class="w-full" @click =" setKeyValue " >
14+ Set key/value
1515 </Button >
16- <Input class="w-full" v-model =" levelDbPrefix " placeholder="LevelDB prefix" />
17- <Button class="w-full" @click =" getLevelDbKeys " >
18- Get level db keys
16+ <Button class="w-full" @click =" getKey " >
17+ Get key
18+ </Button >
19+ <Button class="w-full" @click =" deleteKey " >
20+ Delete key
21+ </Button >
22+ <Input class="w-full" v-model =" kvPrefix " placeholder="Prefix" />
23+ <Button class="w-full" @click =" listKeys " >
24+ List keys by prefix
1925 </Button >
2026 </div >
2127 </section >
@@ -95,9 +101,9 @@ import { useTwoFactorsAuth } from '@/custom/plugins/TwoFactorsAuthPlugin/use2faA
95101
96102 const { get2FaConfirmationResult } = useTwoFactorsAuth ();
97103const valueStart = ref ()
98- const levelDbKey = ref (' ' );
99- const levelDbValue = ref (' ' );
100- const levelDbPrefix = ref (' ' );
104+ const kvKey = ref (' ' );
105+ const kvValue = ref (' ' );
106+ const kvPrefix = ref (' ' );
101107const lastApiOutput = ref (' No output yet. Click a button to run an action.' );
102108
103109function setLastApiOutput(actionName : string , data : unknown , isError = false ) {
@@ -113,32 +119,54 @@ watch(valueStart, (newVal) => {
113119 console .log (' New start value:' , newVal );
114120});
115121
116- async function addLevelDbKeyValue () {
122+ async function setKeyValue () {
117123 try {
118124 const response = await callApi ({
119- path: ' /api/addLevelDbKey /' ,
125+ path: ' /api/keyValue/set /' ,
120126 method: ' POST' ,
121127 body: {
122- key: levelDbKey .value ,
123- value: levelDbValue .value ,
128+ key: kvKey .value ,
129+ value: kvValue .value ,
124130 },
125131 });
126- console .log (' LevelDB key/value added:' , response );
127- setLastApiOutput (' Add level DB key/value' , response );
132+ console .log (' Key/value set:' , response );
133+ setLastApiOutput (' Set key/value' , response );
134+ } catch (error ) {
135+ console .error (' Error setting key/value:' , error );
136+ setLastApiOutput (' Set key/value' , String (error ), true );
137+ }
138+ }
139+
140+ async function getKey() {
141+ try {
142+ const response = await callApi ({ path: ' /api/keyValue/get/' , method: ' POST' , body: { key: kvKey .value } });
143+ console .log (' Key value:' , response );
144+ setLastApiOutput (' Get key' , response );
145+ } catch (error ) {
146+ console .error (' Error getting key:' , error );
147+ setLastApiOutput (' Get key' , String (error ), true );
148+ }
149+ }
150+
151+ async function deleteKey() {
152+ try {
153+ const response = await callApi ({ path: ' /api/keyValue/delete/' , method: ' POST' , body: { key: kvKey .value } });
154+ console .log (' Key deleted:' , response );
155+ setLastApiOutput (' Delete key' , response );
128156 } catch (error ) {
129- console .error (' Error adding LevelDB key/value :' , error );
130- setLastApiOutput (' Add level DB key/value ' , String (error ), true );
157+ console .error (' Error deleting key:' , error );
158+ setLastApiOutput (' Delete key' , String (error ), true );
131159 }
132160}
133161
134- async function getLevelDbKeys () {
162+ async function listKeys () {
135163 try {
136- const response = await callApi ({ path: ' /api/getLevelDbKeys/ ' , method: ' POST' , body: { prefix: levelDbPrefix .value } });
137- console .log (' LevelDB keys :' , response );
138- setLastApiOutput (' Get level db keys ' , response );
164+ const response = await callApi ({ path: ' /api/keyValue/list/ ' , method: ' POST' , body: { prefix: kvPrefix .value } });
165+ console .log (' Keys :' , response );
166+ setLastApiOutput (' List keys by prefix ' , response );
139167 } catch (error ) {
140- console .error (' Error getting LevelDB keys:' , error );
141- setLastApiOutput (' Get level db keys ' , String (error ), true );
168+ console .error (' Error listing keys:' , error );
169+ setLastApiOutput (' List keys by prefix ' , String (error ), true );
142170 }
143171}
144172
0 commit comments