This repository has been archived by the owner on Sep 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ctl for getting and putting KV settings
This commit adds three commands to clankctl: * clankctl get-tag, to get the value of a tag. * clankctl put-tag, to set the value of a tag. * clankctl delete-tag, to delete the value of a tag. They are designed to be used through the command line in case something has to be debugged ever and the value of a specific key has to manually change, overriding any kind of abstraction built on top of the setting provider. Using this endpoint it is possible to get the specific value of a tag, no matter the preffix it is ussing. It is also possible to change manually the value of a tag, and to delete it. It avoids having to rely on manually touching the SQLite, given that the tags are stored as a big JSON blob anyway.
- Loading branch information
Showing
4 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import express from "express"; | ||
|
||
import Makibot from "../../../Makibot"; | ||
import { MiddlewareLocals as GuildMiddlewareLocals } from "./guild"; | ||
|
||
type RouterRequest<ReqBody = unknown, ResBody = unknown> = express.Request< | ||
{ | ||
tag: string; | ||
}, | ||
ResBody, | ||
ReqBody, | ||
unknown, | ||
GuildMiddlewareLocals | ||
>; | ||
|
||
export default function providerMiddleware(makibot: Makibot): express.Router { | ||
const router = express.Router({ mergeParams: true }); | ||
|
||
router.get("/", (req: RouterRequest, res) => { | ||
const value = makibot.provider.get(res.locals.guild.id, req.params.tag, undefined); | ||
if (typeof value === "undefined") { | ||
res.status(404).contentType("text/plain").send("tag not found"); | ||
} else { | ||
res.status(200).contentType("application/json").json(value); | ||
} | ||
}); | ||
|
||
router.put("/", async (req: RouterRequest<{ value: unknown }>, res) => { | ||
if (req.body.value) { | ||
await makibot.provider.set(res.locals.guild.id, req.params.tag, req.body.value); | ||
return res.status(204).contentType("text/plain").send(); | ||
} else { | ||
return res.status(400).contentType("text/plain").send("invalid body"); | ||
} | ||
}); | ||
|
||
router.delete("/", async (req: RouterRequest, res) => { | ||
await makibot.provider.remove(res.locals.guild.id, req.params.tag); | ||
return res.status(204).contentType("text/plain").send(); | ||
}); | ||
|
||
return router; | ||
} |