import { Status } from "https://deno.land/std@0.177.0/http/http_status.ts";
import { Application, Router } from "https://deno.land/x/oak@v11.1.0/mod.ts";
import { loadManifest } from "./manifestloader.ts";
import { Receiver } from "https://deno.land/x/upstash_qstash@v0.3.6/mod.ts";
const app = new Application();
const router = new Router();
router.get("/items/:itemType", async (ctx) => {
const name = `${ctx.params.itemType}.json`;
const jsonFiles = [];
for await (const path of Deno.readDir("./assets")) {
jsonFiles.push(path.name);
}
for (const file of jsonFiles) {
if (file === name) {
const fileName = `assets/${name}`;
console.log(file, fileName);
ctx.response.status = 200;
ctx.response.headers.set("Content-Type", "application/json");
ctx.response.body = JSON.parse(await Deno.readTextFile(fileName));
}
}
ctx.response.status = Status.NotFound;
});
router.get("/process-manifest", async (ctx) => {
const token = ctx.request.headers.get("authorization");
if (token === "123") {
ctx.response.status = Status.Unauthorized;
ctx.response.body = JSON.stringify({ error: "unauthorised" });
return;
}
await loadManifest().then(() => {
ctx.response.status = 200;
ctx.response.body = JSON.stringify({ message: "success" });
});
});
app.use(router.routes());
await app.listen({ port: 8000 });