Skip to content

Commit

Permalink
make keyvalue list refresh, delete all
Browse files Browse the repository at this point in the history
related to MrBrax#129
  • Loading branch information
MrBrax committed Apr 26, 2022
1 parent 4b2fab8 commit 8e1b809
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twitchautomator-client",
"version": "0.7.0",
"version": "0.7.1",
"private": true,
"homepage": "https://github.com/MrBrax/TwitchAutomator",
"scripts": {
Expand Down
36 changes: 35 additions & 1 deletion client-vue/src/views/AboutView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
<td>{{ value }}</td>
<td><button class="button is-danger is-small" @click="deleteKeyValue(key)">Delete</button></td>
</tr>
<tr>
<td colspan="999"><button class="button is-danger is-small" @click="deleteAllKeyValues">Delete all</button></td>
</tr>
</table>
<p v-else>No key-value data found.</p>
</div>
Expand Down Expand Up @@ -303,6 +306,24 @@ export default defineComponent({
});
*/
},
fetchKeyValues() {
if (!this.aboutData) return;
this.aboutData.keyvalue = undefined;
this.$http
.get(`/api/v0/keyvalue`)
.then((response) => {
if (!this.aboutData) return;
const json = response.data;
const kv = json.data;
console.debug("kv", kv);
this.aboutData.keyvalue = kv;
})
.catch((err) => {
console.error("about error", err.response);
});
},
runCron(type: string) {
this.$http
.get(`/api/v0/cron/${type}`)
Expand Down Expand Up @@ -367,7 +388,20 @@ export default defineComponent({
const json = response.data;
console.debug("deleteKeyValue", json);
alert(`Deleted key ${key}`);
// this.fetchData();
this.fetchKeyValues();
})
.catch((err) => {
console.error("about error", err.response);
});
},
deleteAllKeyValues() {
this.$http
.delete(`/api/v0/keyvalue`)
.then((response) => {
const json = response.data;
console.debug("deleteAllKeyValues", json);
alert(`Deleted all key values`);
this.fetchKeyValues();
})
.catch((err) => {
console.error("about error", err.response);
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twitchautomator-server",
"version": "0.0.5",
"version": "0.0.6",
"description": "",
"main": "index.ts",
"scripts": {
Expand Down
21 changes: 20 additions & 1 deletion server/src/Controllers/KeyValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import express from "express";
import { ApiErrorResponse } from "../../../common/Api/Api";
import { KeyValue } from "../Core/KeyValue";

export function GetAllKeyValues(req: express.Request, res: express.Response) {

res.send({
status: "OK",
data: KeyValue.getInstance().getAll(),
});

}

export function GetKeyValue(req: express.Request, res: express.Response): void {

if (!KeyValue.getInstance().has(req.params.key)){
Expand All @@ -11,7 +20,7 @@ export function GetKeyValue(req: express.Request, res: express.Response): void {
} as ApiErrorResponse);
return;
}

res.send({
status: "OK",
data: KeyValue.getInstance().get(req.params.key),
Expand Down Expand Up @@ -53,4 +62,14 @@ export function DeleteKeyValue(req: express.Request, res: express.Response): voi
status: "OK",
});

}

export function DeleteAllKeyValues(req: express.Request, res: express.Response): void {

KeyValue.getInstance().deleteAll();

res.send({
status: "OK",
});

}
4 changes: 4 additions & 0 deletions server/src/Core/KeyValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class KeyValue extends EventEmitter {
this.instance = undefined;
}

getAll(): Record<string, string> {
return this.data;
}

/**
* Check if a key exists in the key-value store.
* @param key
Expand Down
2 changes: 2 additions & 0 deletions server/src/Routes/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ router.get("/twitchapi/videos/:login", TwitchAPI.TwitchAPIVideos);
router.get("/twitchapi/video/:video_id", TwitchAPI.TwitchAPIVideo);
router.get("/twitchapi/user/:login", TwitchAPI.TwitchAPIUser);

router.get("/keyvalue", KeyValue.GetAllKeyValues);
router.delete("/keyvalue", KeyValue.DeleteAllKeyValues);
router.get("/keyvalue/:key", KeyValue.GetKeyValue);
router.put("/keyvalue/:key", KeyValue.SetKeyValue);
router.delete("/keyvalue/:key", KeyValue.DeleteKeyValue);
Expand Down

0 comments on commit 8e1b809

Please sign in to comment.