ssscQuizadmin.http.ts8 matches
12const TABLE_NAME = 'sssc_quiz_submissions_v1'; // Must match the table name in index.http.ts
13
14// Database initialization - ensure table exists
15async function initDatabase() {
16await sqlite.execute(`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
17id INTEGER PRIMARY KEY AUTOINCREMENT,
33}
34
35// Initialize database on startup
36await initDatabase();
37
38// Main admin dashboard route
94<body>
95<div style="padding: 2rem; text-align: center;">
96<h1>⚠️ Database Error</h1>
97<p>Unable to load dashboard data. Please check if the database is initialized.</p>
98<a href="/" style="color: #4361ee;">← Back to Quiz</a>
99</div>
204});
205
206// Debug endpoint to check database contents
207app.get("/api/debug", async c => {
208try {
527<p>Total Submissions: <strong>${total}</strong></p>
528<p style="font-size: 0.9rem; opacity: 0.8;">
529<a href="/api/debug" style="color: rgba(255,255,255,0.8); text-decoration: none;">🔍 Debug Database</a>
530</p>
531</div>
10- **Personality Analysis**: Advanced algorithm determining primary social archetype
11- **Email Delivery**: Automated email with detailed results and insights
12- **Data Persistence**: All submissions stored in SQLite database
13
14### Enhanced Features
61- **Backend**: Hono web framework on Deno
62- **Frontend**: React 18 with TypeScript
63- **Database**: Val Town SQLite
64- **Email**: Val Town email service
65- **Styling**: CSS with custom properties and responsive design
91- Primary HTTP val that users visit
92- Hono web server with comprehensive error handling
93- SQLite database with optimized schema and indexing
94- Enhanced email system with HTML/text templates
95- API endpoints for quiz submission and analytics
107### Backend (Hono)
108- RESTful API with proper error handling
109- SQLite database with structured schema and indexes
110- Email automation with professional HTML templates
111- Admin analytics with real-time data
120- Progressive enhancement
121
122### Database Schema
123```sql
124CREATE TABLE sssc_quiz_submissions (
180
181- **Email Validation**: Client and server-side validation
182- **Data Sanitization**: All inputs sanitized before database storage
183- **Privacy Focused**: No tracking beyond essential quiz functionality
184- **Secure Storage**: Encrypted database storage through Val Town
185
186## 🚀 Deployment
1901. **Main Application**: `index.http.ts` - Primary entry point users visit
1912. **Admin Dashboard**: `admin.http.ts` - Analytics and data management
1923. **Database**: Automatic SQLite initialization with proper indexing
1934. **Email**: Enhanced email service with HTML templates following Val Town standards
1945. **Frontend**: Served as static files with mobile-responsive design
254- **Efficient Rendering**: Optimized React components
255- **CSS Optimization**: Custom properties and efficient selectors
256- **Database Queries**: Indexed and optimized queries
257
258
ssscQuizindex.http.ts9 matches
13});
14
15// Database setup following Val Town standards
16const TABLE_NAME = 'sssc_quiz_submissions_v1'; // Must match admin.http.ts table name
17
18// Initialize database with Val Town best practices
19async function initDatabase() {
20await sqlite.execute(`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
21id INTEGER PRIMARY KEY AUTOINCREMENT,
37}
38
39// Initialize database on startup
40await initDatabase();
41
42// Serve static files
86const ipHash = forwarded ? await hashIP(forwarded.split(',')[0].trim()) : '';
87
88console.log("Storing in database...");
89console.log("Table name:", TABLE_NAME);
90console.log("Data to insert:", {
96});
97
98// Store in database following Val Town patterns
99const insertResult = await sqlite.execute(
100`INSERT INTO ${TABLE_NAME} (
113]
114);
115console.log("Database insert successful, result:", insertResult);
116
117// Verify the insert worked
200app.get("/api/test-insert", async c => {
201try {
202console.log("Testing database insert...");
203
204const testEmail = `test${Date.now()}@example.com`;
37},
38
39// Database configuration
40database: {
41tableName: "sssc_quiz_submissions_v1",
42enableIndexes: true
11});
1213app.get("/clear-databases", async (c) => {
14return c.html(`
15<h1>Clear Databases</h1>
16<p>This will clear the databases for the bot.</p>
17<form method="post" action="/clear-databases">
18<input type="text" name="token" placeholder="Token" />
19<button type="submit">Clear Databases</button>
20</form>
21<p>The password is ${Deno.env.get("ADMIN_TOKEN")}</p>
23});
2425// Clear databases endpoint
26app.post("/clear-databases", async (c) => {
27const body = await c.req.parseBody();
28const token = body["token"];
32}
3334// clear the databases
35await sqlite.execute(`DELETE FROM ${LangChainTables.checkpoints}`);
36await sqlite.execute(`DELETE FROM ${LangChainTables.checkpoint_writes}`);
3738return c.json({ message: "Databases cleared" });
39});
40
40await ctx.reply(`✅ Successfully joined room with secret: ${roomSecret}`);
41} catch (dbError) {
42console.error("Database error in join command:", dbError);
43await ctx.reply("❌ Error joining room. Please try again.");
44}
74await ctx.reply(`✅ Successfully left room with secret: ${roomSecret}`);
75} catch (dbError) {
76console.error("Database error in leave command:", dbError);
77await ctx.reply("❌ Error leaving room. Please try again.");
78}
45await new Promise(res => setTimeout(res, getRandomInt(200, 400)));
46const possibleLogs = [
47`ERROR: Connection to database 'pg-primary-01' on host ${serviceName}-db-host timed out.`,
48`WARN: High memory pressure detected on service '${serviceName}'. Throttling new connections.`,
49`ERROR: Failed to acquire lock 'payment_processing_lock' for service ${serviceName}.`,
170async function safetyCheckerAgent(acp: ACP): Promise<ACP> {
171const { remediation_plan } = acp.payload.content;
172const dangerousCommands = ["reboot", "rm -rf", "shutdown", "DROP DATABASE", "DELETE FROM"];
173174const unsafeStep = remediation_plan.find(step =>
16- Supports both general attendee registration and speaker applications
17- Collects attendee interests and preferences for event content
18- SQLite database storage for all submissions
19- Email notifications for new submissions
20- Mobile-responsive design
69- Copy the entire list to clipboard with one click
7071## Database Schema
7273```sql
MiniAppStarterApp.tsx5 matches
16{ name: "Farcaster SDK", path: "/" },
17{ name: "Haptics", path: "/haptics" },
18{ name: "Database", path: "/db" },
19{ name: "About", path: "/about" },
20];
39<Route path="/" element={<FarcasterMiniApp />} />
40<Route path="/haptics" element={<CustomHaptics />} />
41<Route path="/db" element={<Database />} />
42<Route path="/about" element={<About />} />
43<Route path="/neynar" element={<Neynar />} />
55<div className="">✷ Hono + React + Tailwind</div>
56<div className="">✷ React Router + React Query</div>
57<div className="">✷ Built-in database (blob storage)</div>
58<div className="">✷ Farcaster mini app manifest + webhook + embed metadata</div>
59<div className="">✷ Farcaster notifications (storing tokens, sending recurring notifications, ...)</div>
71}
7273function Database() {
74const queryFn = () => fetch("/api/counter/get").then((r) => r.json());
75const { data, refetch } = useQuery({ queryKey: ["counter"], queryFn });
76return (
77<Section className="flex flex-col items-start gap-3 m-5">
78{/* <h2 className="font-semibold">Database Example</h2> */}
79<div className="">Counter value: {data}</div>
80<Button variant="outline" onClick={() => fetch("/api/counter/increment").then(refetch)}>
reactHonoExampleREADME.md2 matches
45* `index.ts` - this is the **entrypoint** for this whole project
6* `database/` - this contains the code for interfacing with the app's SQLite database table
78## Hono
26## CRUD API Routes
2728This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
2930## Errors