1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { runMigrations } from "./database/migrations.ts";
4import recipesRoutes from "./routes/recipes.ts";
5import parseRoutes from "./routes/parse.ts";
12});
13
14// Initialize database on startup
15await runMigrations();
16
27app.get('/api/test-delete', async (c) => {
28 try {
29 const { createRecipe, deleteRecipe, getAllRecipes } = await import('./database/queries.ts');
30
31 // Create a test recipe
39 if (!recipeId) {
40 console.error('Failed to get recipe ID from insert result:', recipeResult);
41 throw new Error('Failed to create recipe: no ID returned from database');
42 }
43
47 if (isNaN(numericRecipeId) || numericRecipeId <= 0) {
48 console.error('Recipe ID is not a valid number:', recipeId);
49 throw new Error('Failed to create recipe: invalid ID returned from database');
50 }
51
7 updateRecipe,
8 deleteRecipe
9} from "../database/queries.ts";
10
11const app = new Hono();
5
6export async function runMigrations() {
7 console.log('Running database migrations...');
8
9 // Create recipes table
51 `);
52
53 console.log('Database migrations completed');
54}
55
21- **Frontend**: React with TypeScript, TailwindCSS
22- **Backend**: Hono API framework
23- **Database**: SQLite for recipe storage
24- **AI**: OpenAI GPT-4 for intelligent recipe parsing
25- **File Processing**: PDF parsing and image OCR capabilities
29```
30โโโ backend/
31โ โโโ database/
32โ โ โโโ migrations.ts # Database schema
33โ โ โโโ queries.ts # Database operations
34โ โโโ routes/
35โ โ โโโ recipes.ts # Recipe CRUD operations
28
29 // For now, just log the configuration
30 // In a real implementation, you might store this in a database or environment variable
31 console.log(`๐ Refresh frequency updated to: ${refreshFrequency}`);
32
8โโโ index.ts # Main HTTP entry point (Hono app)
9โโโ backend/
10โ โโโ database/
11โ โโโ cache.ts # Database cache functions
12โโโ test.html # Plant API testing interface
13โโโ admin.html # Cache admin interface
40
41### GET /admin
42Simple admin interface for viewing the cache database. Displays:
43- Total number of cached entries
44- List of all cached plants with their full JSON data
225- Built with Hono framework
226- Uses OpenAI GPT-4o-mini model
227- SQLite database for caching with automatic table creation
228- Includes input validation and error handling
229- Returns structured JSON responses
9<body class="bg-gray-50 p-4">
10 <div class="max-w-4xl mx-auto">
11 <h1 class="text-2xl font-bold mb-4">Cache Database</h1>
12 <a href="/" class="text-blue-600 hover:underline mb-4 inline-block">โ Back to Test Page</a>
13
11 clearCache,
12 type PlantInfo
13} from "./backend/database/cache.ts";
14
15const app = new Hono();
45 example: "/plant/rose",
46 testPage: "/ - Simple testing interface",
47 adminPage: "/admin - Cache database admin interface",
48 cache: {
49 totalCachedPlants: stats.totalEntries,
59});
60
61// Admin page to view cache database
62app.get("/admin", async (c) => {
63 const html = await readFile("/admin.html", import.meta.url);
178});
179
180// Test database endpoint
181app.get("/test-db", async (c) => {
182 try {
183 console.log("Testing database connection...");
184
185 // Test basic SQLite functionality
200
201 return c.json({
202 message: "Database test successful",
203 testResult,
204 selectResult
205 });
206 } catch (error) {
207 console.error("Database test failed:", error);
208 return c.json({
209 error: "Database test failed",
210 details: error instanceof Error ? error.message : "Unknown error"
211 }, 500);
2import { Client } from "npm:@notionhq/client";
3import { blobKeyForDemoCache } from "../../shared/utils/blobKeyForDemoCache.ts";
4import { getRelatedPagesFromDatabase } from "../controllers/related.pages.controller.ts";
5
6// Initialize Notion client
11export default async function (interval: Interval) {
12 // this cron runs every minute
13 // it saves a blob for every page in the "Glancer demos" database
14 // that holds the Notion data and markup needed for every demo
15 // this way, to build a demo in the browser (ie., when /demo/:id is called),
17 // this keeps the demo UX snappy
18 try {
19 const pages = await notion.databases.query({
20 database_id: Deno.env.get("GLANCE_DEMOS_DB_ID"),
21 });
22 console.log(pages);
23 // for each page in the demo database, save a blob
24 for (const page of pages.results) {
25 // remove properties that are not used in the demo and don't need to be saved to the blob
40 page.properties = scrubbed;
41
42 // get "Glancer content" database pages added to the demo page
43 const relatedPages = await getRelatedPagesFromDatabase(page.id);
44
45 // use the same blob key that /views/demo/demo.ts calls to build the page