diff --git a/db/config.ts b/db/config.ts index 3d59bafa..43947b4c 100644 --- a/db/config.ts +++ b/db/config.ts @@ -8,6 +8,7 @@ const Guestbook = defineTable({ url: column.text({ optional: true }), timestamp: column.date({ default: NOW }), theme: column.number(), + isSpam: column.boolean({ optional: true }), }, }); diff --git a/src/pages/guestbook.astro b/src/pages/guestbook.astro index 1037feca..1b281217 100644 --- a/src/pages/guestbook.astro +++ b/src/pages/guestbook.astro @@ -1,5 +1,14 @@ --- -import { Guestbook as GuestbookDB, count, db, desc } from "astro:db"; +import { + Guestbook as GuestbookDB, + count, + db, + desc, + eq, + isNull, + or, +} from "astro:db"; + import { Icon } from "src/components/Icon/Icon"; import Center from "../components/Center.astro"; import Notecard from "../components/Notecard/Notecard.astro"; @@ -22,7 +31,10 @@ const baseEntriesPerPage = 24; const entriesPerPage = currentPage === 1 ? baseEntriesPerPage - 1 : baseEntriesPerPage; -const entryCount = await db.select({ count: count() }).from(GuestbookDB); +const entryCount = await db + .select({ count: count() }) + .from(GuestbookDB) + .where(or(eq(GuestbookDB.isSpam, false), isNull(GuestbookDB.isSpam))); const totalEntries = entryCount[0].count; // Calculate total pages accounting for one less entry on first page const remainingEntries = Math.max(0, totalEntries - 1); // Subtract one for composer @@ -57,9 +69,12 @@ if (Astro.request.method === "POST") { typeof url === "string" && typeof theme === "string" ) { + // Extremely basic spam filtering to protect against bots + const isSpam = content.includes("