summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.ts14
-rw-r--r--src/index.ts13
2 files changed, 15 insertions, 12 deletions
diff --git a/build.ts b/build.ts
index 47b13f7..4937cf3 100644
--- a/build.ts
+++ b/build.ts
@@ -4,20 +4,22 @@ import { constants, copyFile, mkdir, readdir, rm } from "node:fs/promises";
import { join } from "node:path";
const distDir = "dist";
+const contentDir = join(distDir, "static");
const teawieArchiveDir = "Teawie-Archive/teawie-media/Original Teawies";
const checkAndCreate = async (dir: string) => {
if (!existsSync(dir)) {
await mkdir(dir, { recursive: true });
+ } else {
+ for (const f of await readdir(dir)) {
+ await rm(join(dir, f), { recursive: true, force: true });
+ }
}
};
await checkAndCreate(distDir);
-for (const f of await readdir(distDir)) {
- await rm(join(distDir, f), { recursive: true, force: true });
-}
-
-await checkAndCreate(join(distDir, "static/teawie"));
+await checkAndCreate(contentDir);
+await checkAndCreate(join(contentDir, "teawie"));
const wies = (await readdir(teawieArchiveDir)).filter((wie) => {
const fileExt = wie.split(".").pop();
@@ -25,7 +27,7 @@ const wies = (await readdir(teawieArchiveDir)).filter((wie) => {
});
for (const f of wies) {
- await copyFile(join(teawieArchiveDir, f), join(distDir, "static/teawie", f), constants.COPYFILE_FICLONE);
+ await copyFile(join(teawieArchiveDir, f), join(contentDir, "teawie", f), constants.COPYFILE_FICLONE);
}
const define = {
diff --git a/src/index.ts b/src/index.ts
index 55bd92a..da1fa4a 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,14 +1,12 @@
import { Hono } from "hono";
import { logger } from "hono/logger";
import { prettyJSON } from "hono/pretty-json";
-import { secureHeaders } from "hono/secure-headers";
import { zValidator } from "@hono/zod-validator";
import { list } from "./schemas";
import { Bindings, Variables } from "./env";
const app = new Hono<{ Bindings: Bindings; Variables: Variables }>();
-app.use("*", secureHeaders());
app.use("*", logger());
app.use("*", prettyJSON());
@@ -16,7 +14,7 @@ app.get("/", (c) => {
return c.redirect(c.env.REDIRECT_ROOT ?? "https://github.com/getchoo/teawieAPI");
});
-app.get("/static/teawie/*", async (c) => {
+app.get("/static/*", async (c) => {
return await c.env.ASSETS.fetch(c.req.raw);
});
@@ -32,13 +30,16 @@ app.get("/list_teawies", zValidator("query", list), async (c) => {
);
});
-app.get("/random_teawie", async (c) => {
- const wies = WIES;
- const wie = wies[Math.floor(Math.random() * wies.length)];
+app.get("/random_teawie", (c) => {
+ const wie = WIES[Math.floor(Math.random() * WIES.length)];
return c.json({
url: `${c.env.URL ?? "https://api.mydadleft.me"}/static/${wie}`,
});
});
+app.get("/get_random_teawie", (c) => {
+ return c.redirect(`${c.env.URL ?? "https://api.mydadleft.me"}/random_teawie`);
+});
+
export default app;