This commit is contained in:
2025-06-08 19:32:42 +09:00
parent dc01ac4380
commit 080d47ab01

View File

@ -43,7 +43,11 @@ export async function batchProcess(abortSignal?: AbortSignal): Promise<void> {
} }
// Load feed URLs from file // Load feed URLs from file
const feedUrls = await loadFeedUrls(); const { fetchActiveFeeds } = await import("../services/database.js");
const feeds = await fetchActiveFeeds();
const feedUrls = feeds.map((feed) => feed.url).filter((url) => !!url);
if (feedUrls.length === 0) { if (feedUrls.length === 0) {
console.log(" No feed URLs found."); console.log(" No feed URLs found.");
return; return;
@ -100,25 +104,6 @@ export async function batchProcess(abortSignal?: AbortSignal): Promise<void> {
} }
} }
/**
* Load feed URLs from configuration file
*/
async function loadFeedUrls(): Promise<string[]> {
try {
const data = await fs.readFile(config.paths.feedUrlsFile, "utf-8");
return data
.split("\n")
.map((url) => url.trim())
.filter((url) => url.length > 0 && !url.startsWith("#"));
} catch (err) {
console.warn(
`⚠️ Failed to read feed URLs file: ${config.paths.feedUrlsFile}`,
);
console.warn("📝 Please create the file with one RSS URL per line.");
return [];
}
}
/** /**
* Process a single feed URL and discover new articles * Process a single feed URL and discover new articles
*/ */
@ -720,13 +705,13 @@ export async function addNewFeedUrl(feedUrl: string): Promise<void> {
// Parse RSS feed to get feed information including title // Parse RSS feed to get feed information including title
const parser = new Parser<FeedItem>(); const parser = new Parser<FeedItem>();
const feed = await parser.parseURL(feedUrl); const feed = await parser.parseURL(feedUrl);
// Extract feed title, fallback to URL if not available // Extract feed title, fallback to URL if not available
const feedTitle = feed.title || feedUrl; const feedTitle = feed.title || feedUrl;
// Classify feed category using OpenAI // Classify feed category using OpenAI
const category = await openAI_ClassifyFeed(feedTitle); const category = await openAI_ClassifyFeed(feedTitle);
// Add to feeds table with title and category // Add to feeds table with title and category
await saveFeed({ await saveFeed({
url: feedUrl, url: feedUrl,
@ -735,7 +720,9 @@ export async function addNewFeedUrl(feedUrl: string): Promise<void> {
active: true, active: true,
}); });
console.log(`✅ Feed URL added: ${feedUrl} (Title: ${feedTitle}, Category: ${category})`); console.log(
`✅ Feed URL added: ${feedUrl} (Title: ${feedTitle}, Category: ${category})`,
);
} catch (error) { } catch (error) {
console.error(`❌ Failed to add feed URL: ${feedUrl}`, error); console.error(`❌ Failed to add feed URL: ${feedUrl}`, error);
throw error; throw error;