--- import BaseLayout from "@/layouts/BaseLayout.astro"; import { getDatabase } from "@/db"; import { gists } from "@/db/schema/gists"; import { Code, Globe, Lock, Plus, X } from "lucide-react"; import { desc, eq } from "drizzle-orm"; import type { NodePgDatabase } from "drizzle-orm/node-postgres"; const user = Astro.locals.user; if (!user) { return Astro.redirect("/login"); } const db = getDatabase() as unknown as NodePgDatabase; // Only the caller's own gists are listed here (public + secret) let gistsList: any[] = []; try { gistsList = await db .select() .from(gists) .where(eq(gists.userId, user.id)) .orderBy(desc(gists.updatedAt)) .limit(100); } catch (e) { console.error("Failed to fetch gists:", e); } function gistTitle(gist: any): string { if (gist.description && gist.description.trim().length > 0) { return gist.description; } const first = Array.isArray(gist.files) ? gist.files[0] : null; return first?.filename || "Untitled gist"; } function fileNames(gist: any): string[] { return Array.isArray(gist.files) ? gist.files.map((f: any) => f.filename) : []; } function timeAgo(date: Date | string) { const seconds = Math.floor((Date.now() - new Date(date).getTime()) / 1000); if (seconds < 60) return "just now"; if (seconds < 3600) return Math.floor(seconds / 60) + "m ago"; if (seconds < 86400) return Math.floor(seconds / 3600) + "h ago"; if (seconds < 604800) return Math.floor(seconds / 86400) + "d ago"; return new Date(date).toLocaleDateString(); } --- Your gists Standalone code snippets, quick notes, and scripts New gist Create a new gist Description Files Add file Public gist — visible to everyone Create gist {gistsList.length === 0 ? ( No gists yet Create your first gist to share snippets and quick scripts. ) : ( {gistsList.map((gist: any) => ( {gistTitle(gist)} {timeAgo(gist.updatedAt)} {gist.public ? : } {gist.public ? "Public" : "Secret"} {Array.isArray(gist.files) ? gist.files.length : 0} file{(Array.isArray(gist.files) ? gist.files.length : 0) === 1 ? "" : "s"} {!gist.description && ( {fileNames(gist).join(", ")} )} ))} )}
Standalone code snippets, quick notes, and scripts
Create your first gist to share snippets and quick scripts.
{fileNames(gist).join(", ")}