From 776fc1b38ef4c03e500eb71cfa6813b4956751db Mon Sep 17 00:00:00 2001 From: haetae Date: Fri, 8 Aug 2025 03:00:12 -0400 Subject: [PATCH] who needs allat. maybe i want to live simply --- astro.config.mjs | 6 -- db/config.ts | 14 +---- src/actions/comment.ts | 21 ------- src/actions/guestbook.ts | 30 ++-------- src/actions/index.ts | 2 - src/assets/styles/base.css | 46 -------------- src/assets/styles/themes.css | 50 ++++++++++++++++ src/env.d.ts | 3 - src/layouts/Layout.astro | 2 +- src/pages/guestbook/admin.astro | 103 +++++++++++++++++--------------- src/pages/guestbook/login.astro | 16 ----- src/utils/loader.ts | 2 +- 12 files changed, 113 insertions(+), 182 deletions(-) delete mode 100644 src/actions/comment.ts create mode 100644 src/assets/styles/themes.css delete mode 100644 src/env.d.ts delete mode 100644 src/pages/guestbook/login.astro diff --git a/astro.config.mjs b/astro.config.mjs index ae4b199..34eb68b 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -17,12 +17,6 @@ export default defineConfig({ adapter: node({ mode: "standalone", }), - session: { - driver: "localstorage", - options: { - base: "app:", - }, - }, experimental: { fonts: [ { diff --git a/db/config.ts b/db/config.ts index a6ef4be..7b78153 100644 --- a/db/config.ts +++ b/db/config.ts @@ -12,19 +12,7 @@ const Guestbook = defineTable({ }, }); -const Comment = defineTable({ - columns: { - id: column.number({ primaryKey: true }), - postId: column.text(), - replyId: column.number(), - username: column.text(), - website: column.text({ optional: true }), - comment: column.text({ multiline: true }), - published: column.date({ default: NOW }), - }, -}); - // https://astro.build/db/config export default defineDb({ - tables: { Guestbook, Comment }, + tables: { Guestbook }, }); diff --git a/src/actions/comment.ts b/src/actions/comment.ts deleted file mode 100644 index 4484ec9..0000000 --- a/src/actions/comment.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { defineAction } from "astro:actions"; -import { z } from "astro:content"; -import sanitize from "sanitize-html"; - -export const comments = { - addComment: defineAction({ - accept: "form", - input: z.object({ - postId: z.string(), - replyId: z.number().optional(), - name: z.string(), - website: z.string().url().optional(), - comment: z.string(), - }), - handler: async (input) => { - // sanitize but allow line breaks - sanitize(input.comment); - // post to comment server - }, - }), -}; \ No newline at end of file diff --git a/src/actions/guestbook.ts b/src/actions/guestbook.ts index e978df7..97eaf5a 100644 --- a/src/actions/guestbook.ts +++ b/src/actions/guestbook.ts @@ -1,7 +1,6 @@ import { ActionError, defineAction } from "astro:actions"; import { z } from "astro:content"; import { db, eq, Guestbook } from "astro:db"; -import bcrypt from "bcryptjs"; import sanitize from "sanitize-html"; export const guestbook = { @@ -14,6 +13,8 @@ export const guestbook = { }), handler: async ({ username, website, message }) => { // figure out how to add line breaks and THEN sanitize message + const addLine = message.replaceAll("/n", "
"); + sanitize(addLine); const entry = await db.insert(Guestbook).values({ username, @@ -31,7 +32,7 @@ export const guestbook = { reply: z.string(), }), handler: async ({ id, reply }, context) => { - if (!context.session?.get("pwd")) { + if (context.url.hostname !== "127.0.0.1" || "localhost") { throw new ActionError({ code: "UNAUTHORIZED" }); } @@ -44,32 +45,9 @@ export const guestbook = { } // sanitize reply here - + const update = await db.update(Guestbook).set({ reply }).where(eq(Guestbook.id, id)).returning(); return update[0]; }, }), - login: defineAction({ - accept: "form", - input: z.object({ - password: z.string(), - }), - handler: async ({ password }, context) => { - // find env var here - if (password !== "super secret password") { - throw new ActionError({ code: "UNAUTHORIZED" }); - } - - const hash = await bcrypt.hash(password, 10); - context.session?.set("pwd", hash); - return { code: 200, message: "set the thing" }; - } - }), - logout: defineAction({ - accept: "form", - handler: async (_input, context) => { - context.session?.destroy(); - return { code: 200, message: "set the thing" }; - } - }), }; \ No newline at end of file diff --git a/src/actions/index.ts b/src/actions/index.ts index ebb4bbf..ededb0f 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -1,9 +1,7 @@ -import { comments } from "./comment"; import { contact } from "./contact"; import { guestbook } from "./guestbook"; export const server = { - comments, contact, guestbook, }; \ No newline at end of file diff --git a/src/assets/styles/base.css b/src/assets/styles/base.css index cd07563..6e25253 100644 --- a/src/assets/styles/base.css +++ b/src/assets/styles/base.css @@ -12,34 +12,6 @@ --ko-font: GulimChe, DotumChe, Gulim, Dotum, system-ui-ko, system-ui-ja, system-ui-zh-cn, system-ui-zh-tw, system-ui-zh-hk, monospace, sans-serif; --dotum-11-font: var(--dotumche-11), var(--dotum-11), var(--ko-font); --dotum-12-font: var(--dotumche-12), var(--dotum-12), var(--ko-font); - - @media screen and (prefers-color-scheme: light) { - --bg-color: #e6f2ef; - --fg-color: #151640; - --accent-color: #f783b0; - --secondary-color: #3f6d9e; - } - - @media screen and (prefers-color-scheme: dark) { - --bg-color: #555568; - --fg-color: #f3eded; - --accent-color: #eeb9c7; - --secondary-color: #b9eedc; - } -} - -.light { - --bg-color: #e6f2ef; - --fg-color: #151640; - --accent-color: #f783b0; - --secondary-color: #3f6d9e; -} - -.dark { - --bg-color: #555568; - --fg-color: #f3eded; - --accent-color: #eeb9c7; - --secondary-color: #b9eedc; } body { @@ -124,22 +96,4 @@ button, .button { border-color: var(--bg-color); box-shadow: 0 0 0 var(--fg-color); } -} - -.dark { - button, .button { - background-color: var(--accent-color); - color: var(--bg-color); - - &:hover { - background-color: hsl(from var(--accent-color) h s calc(l - 10)); - color: var(--bg-color); - } - - &:active, &:focus { - color: var(--bg-color); - background-color: var(--secondary-color); - border-color: var(--bg-color); - } - } } \ No newline at end of file diff --git a/src/assets/styles/themes.css b/src/assets/styles/themes.css new file mode 100644 index 0000000..2fee09f --- /dev/null +++ b/src/assets/styles/themes.css @@ -0,0 +1,50 @@ +:root { + @media screen and (prefers-color-scheme: light) { + --bg-color: #e6f2ef; + --fg-color: #151640; + --accent-color: #f783b0; + --secondary-color: #3f6d9e; + } + + @media screen and (prefers-color-scheme: dark) { + --bg-color: #555568; + --fg-color: #f3eded; + --accent-color: #eeb9c7; + --secondary-color: #b9eedc; + } +} + +.light { + --bg-color: #e6f2ef; + --fg-color: #151640; + --accent-color: #f783b0; + --secondary-color: #3f6d9e; +} + +.dark { + --bg-color: #555568; + --fg-color: #f3eded; + --accent-color: #eeb9c7; + --secondary-color: #b9eedc; +} + +/* custom theme styling */ + +/* dark-specific styles */ +.dark { + button, .button { + background-color: var(--accent-color); + color: var(--bg-color); + + &:hover { + background-color: hsl(from var(--accent-color) h s calc(l - 10)); + color: var(--bg-color); + } + + &:active, &:focus { + color: var(--bg-color); + background-color: var(--secondary-color); + border-color: var(--bg-color); + } + } +} \ No newline at end of file diff --git a/src/env.d.ts b/src/env.d.ts deleted file mode 100644 index 32a0e8e..0000000 --- a/src/env.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -interface Window { - Alpine: import("alpinejs").Alpine; -} \ No newline at end of file diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 585e46f..c790ce0 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,5 +1,6 @@ --- import "$/styles/base.css"; +import "$/styles/themes.css"; import { Font } from "astro:assets"; interface Props { title?: string; } @@ -11,7 +12,6 @@ const { title = "haetae" }: Props = Astro.props; - diff --git a/src/pages/guestbook/admin.astro b/src/pages/guestbook/admin.astro index 4388172..667f635 100644 --- a/src/pages/guestbook/admin.astro +++ b/src/pages/guestbook/admin.astro @@ -3,62 +3,71 @@ export const prerender = false; import { actions } from "astro:actions"; import { db, desc, Guestbook } from "astro:db"; +import Layout from "@/layouts/Layout.astro"; +import formatDate from "@/utils/formatDate"; -const pwd = await Astro.session?.get("pwd"); - -if (!pwd) { - const fromUrl = Astro.url.pathname + Astro.url.search; - return Astro.redirect(`/guestbook/login?redirect=${fromUrl}`); +if (!import.meta.env.DEV) { + console.error("you shouldn't be here..."); + return Astro.redirect("/guestbook"); } const entries = await db.select().from(Guestbook).orderBy(desc(Guestbook.published)); --- -

entries

+ +

entries

-
- - - - - - - - - - - - - {entries.map(entry => ( - - - - - - - +
+
usernamewebsitemessagepublishedreplyedit
{entry.username}{entry.website}{entry.message}{entry.published}{entry.reply}
+ + + + + + + + - ))} - -
usernamewebsitemessagepublishedreplyedit
+ + + {entries.map(entry => ( + + {entry.username} + {entry.website} + {entry.message} + {formatDate(entry.published, false, 'MMMM D, YYYY')} + {entry.reply} + + + ))} + + - -
- -

-

-
-

- - + + + +

+

+
+

+ + - - -
-
+ + + + +
-
- -
+