Fix database
This commit is contained in:
		@@ -272,24 +272,42 @@ export interface EpisodeWithFeedInfo {
 | 
				
			|||||||
export async function saveFeed(
 | 
					export async function saveFeed(
 | 
				
			||||||
  feed: Omit<Feed, "id" | "createdAt">,
 | 
					  feed: Omit<Feed, "id" | "createdAt">,
 | 
				
			||||||
): Promise<string> {
 | 
					): Promise<string> {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    // Check if feed already exists
 | 
				
			||||||
 | 
					    const existingFeed = await getFeedByUrl(feed.url);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (existingFeed) {
 | 
				
			||||||
 | 
					      // Update existing feed
 | 
				
			||||||
 | 
					      const updateStmt = db.prepare(
 | 
				
			||||||
 | 
					        "UPDATE feeds SET title = ?, description = ?, last_updated = ?, active = ? WHERE url = ?",
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      updateStmt.run(
 | 
				
			||||||
 | 
					        feed.title || null,
 | 
				
			||||||
 | 
					        feed.description || null,
 | 
				
			||||||
 | 
					        feed.lastUpdated || null,
 | 
				
			||||||
 | 
					        feed.active !== undefined ? (feed.active ? 1 : 0) : 1,
 | 
				
			||||||
 | 
					        feed.url,
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      return existingFeed.id;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      // Create new feed
 | 
				
			||||||
      const id = crypto.randomUUID();
 | 
					      const id = crypto.randomUUID();
 | 
				
			||||||
      const createdAt = new Date().toISOString();
 | 
					      const createdAt = new Date().toISOString();
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
  try {
 | 
					      const insertStmt = db.prepare(
 | 
				
			||||||
    const stmt = db.prepare(
 | 
					        "INSERT INTO feeds (id, url, title, description, last_updated, created_at, active) VALUES (?, ?, ?, ?, ?, ?, ?)",
 | 
				
			||||||
      "INSERT OR REPLACE INTO feeds (id, url, title, description, last_updated, created_at, active) VALUES (?, ?, ?, ?, ?, ?, ?)",
 | 
					 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    stmt.run(
 | 
					      insertStmt.run(
 | 
				
			||||||
        id,
 | 
					        id,
 | 
				
			||||||
        feed.url,
 | 
					        feed.url,
 | 
				
			||||||
        feed.title || null,
 | 
					        feed.title || null,
 | 
				
			||||||
        feed.description || null,
 | 
					        feed.description || null,
 | 
				
			||||||
        feed.lastUpdated || null,
 | 
					        feed.lastUpdated || null,
 | 
				
			||||||
        createdAt,
 | 
					        createdAt,
 | 
				
			||||||
      feed.active !== undefined ? (feed.active ? 1 : 0) : 1, // Default to active=1 if not specified
 | 
					        feed.active !== undefined ? (feed.active ? 1 : 0) : 1,
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					 | 
				
			||||||
      return id;
 | 
					      return id;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  } catch (error) {
 | 
					  } catch (error) {
 | 
				
			||||||
    console.error("Error saving feed:", error);
 | 
					    console.error("Error saving feed:", error);
 | 
				
			||||||
    throw error;
 | 
					    throw error;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user