130 }
131
132 console.log(`Weather forecast updated in the database.`);
133 return summary;
134}
125 }
126
127 console.log(`Calendar events imported into the database.`);
128 return events;
129 } catch (error) {
8
9/**
10 * Retrieves previously generated fun facts from the memories database
11 * @returns Array of previous fun facts
12 */
47
48/**
49 * Inserts a fun fact into the memories database
50 * @param date Date for the fun fact in ISO format
51 * @param factText The fun fact text
208```
209โโโ backend/
210โ โโโ database/
211โ โ โโโ migrations.ts # Schema definitions
212โ โ โโโ queries.ts # DB query functions
270- Handle API calls properly with proper error catching
271
272### Database Patterns
273- Run migrations on startup or comment out for performance
274- Change table names when modifying schemas rather than altering
6 <component name="ChangeListManager">
7 <list default="true" id="590811ff-77d1-4512-b4ce-38214d91160b" name="Changes" comment="">
8 <change beforePath="$PROJECT_DIR$/backend/database/queries.js" beforeDir="false" afterPath="$PROJECT_DIR$/backend/database/queries.js" afterDir="false" />
9 <change beforePath="$PROJECT_DIR$/backend/htmlGenerator.js" beforeDir="false" afterPath="$PROJECT_DIR$/backend/htmlGenerator.js" afterDir="false" />
10 <change beforePath="$PROJECT_DIR$/backend/huggingface.js" beforeDir="false" afterPath="$PROJECT_DIR$/backend/huggingface.js" afterDir="false" />
184 const blogId = url.pathname.split("/")[2];
185
186 // Import the database queries
187 const { getGeneratedBlog } = await import("./backend/database/queries.js");
188
189 // Get the blog from the database
190 const blog = await getGeneratedBlog(blogId);
191
214 // }
215 //
216 // // If a title was found, update the blog in the database
217 // if (extractedTitle) {
218 // console.log(`Extracted title: "${extractedTitle}" for blog ID: ${blogId}`);
219 //
220 // // Import the updateGeneratedBlog function
221 // const { updateGeneratedBlog } = await import("./backend/database/queries.js");
222 //
223 // // Update the blog_title in the database
224 // await updateGeneratedBlog(blogId, { blog_title: extractedTitle });
225 //
269 const { generateHtmlBlog } = await import("./backend/htmlGenerator.js");
270
271 // Generate the HTML blog and save it to the database
272 const blogData = await generateHtmlBlog(summary, originalUrl, ageRange, images);
273
285 else if (url.pathname === "/api/blogs" && req.method === "GET") {
286 try {
287 // Import the database queries
288 const { getAllGeneratedBlogs } = await import("./backend/database/queries.js");
289
290 // Get all blogs from the database
291 const blogs = await getAllGeneratedBlogs();
292
160 <div>
161 <h3 class="text-xl font-medium text-blue-300">4. Storage</h3>
162 <p class="mt-1">The generated blog is saved in a database so you can access it later using the same link.</p>
163 </div>
164 </div>
1import { InferenceClient } from "npm:@huggingface/inference";
2import { createBlogTable } from "./database/migrations.js";
3import { saveGeneratedBlog } from "./database/queries.js";
4import { updateGeneratedBlog } from "./database/queries.js";
5// Initialize the Hugging Face inference client
6const client = new InferenceClient(Deno.env.get("HUGGINGFACE_API_KEY"));
10
11/**
12 * Generates an HTML blog page from the summarized content and saves it to the database
13 * @param {string} summary - The summarized content
14 * @param {string} originalUrl - The original article URL
24) {
25 try {
26 // Save the generated blog to the database with images JSON
27 const blogId = await saveGeneratedBlog(
28 summary,
61 }
62
63 // Save the generated blog to the database with images JSON
64 await updateGeneratedBlog(blogId, {
65 summary,
70 });
71
72 // Log successful save to database
73 console.log(`Successfully saved blog with ID: ${blogId}`);
74
4export async function saveGeneratedBlog(summary, originalUrl, ageRange, htmlContent, images = '[]') {
5 try {
6 console.log(`Saving blog to database: ${originalUrl} for age range ${ageRange}`);
7
8 const result = await sqlite.execute(
24 console.error("Failed to verify blog was saved!");
25 } else {
26 console.log("Blog save verified in database");
27 }
28
29 return blogId;
30 } catch (error) {
31 console.error("Error saving blog to database:", error);
32 throw new Error(`Failed to save blog: ${error.message}`);
33 }
60
61/**
62 * Updates an existing blog in the database
63 * @param {number} blogId - The ID of the blog to update
64 * @param {Object} updateData - The data to update (any of: summary, original_url, age_range, html_content, images)
1// Script to set up the telegram_chats table in SQLite
2// Run this script manually to create the database table
3
4export default async function setupTelegramChatDb() {
25 `);
26
27 return "Telegram chat database table created successfully.";
28 } catch (error) {
29 console.error("Error setting up telegram_chats table:", error);