namespace tracking and creation

This commit is contained in:
2024-10-19 12:40:53 -06:00
parent 0941690f91
commit 0517e7c2e2
9 changed files with 141 additions and 4 deletions

View File

@@ -120,6 +120,33 @@ router.route("/api/pack")
return new Response(JSON.stringify({ packName }), { status: 200 });
});
router.route("/api/pack/namespaces")
.get(async () => {
using store = new BearMetalStore();
const namespaces = Array.from(Deno.readDirSync(store.get("packlocation")))
.filter((dir) => dir.isDirectory).map((dir) => dir.name);
return new Response(JSON.stringify(namespaces), { status: 200 });
})
.post(async (req) => {
using store = new BearMetalStore();
const namespace = await req.text();
if (!namespace) {
return new Response("Namespace is required", { status: 400 });
}
const namespaceRx = /^[a-zA-Z0-9_\-]+$/;
if (!namespaceRx.test(namespace)) {
return new Response(
"Namespace must only contain letters, numbers, underscores, and dashes",
{ status: 400 },
);
}
await ensureDir(store.get("packlocation") + "/" + namespace);
return new Response(null, { status: 200 });
});
router.route("/api/packs")
.get(async () => {
using store = new BearMetalStore();