namespace tracking and creation
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user