Update for static file serving
This commit is contained in:
@ -139,20 +139,118 @@ export async function updatePodcastRSS(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate all category RSS files as static files
|
||||
*/
|
||||
export async function generateAllCategoryRSSFiles(): Promise<void> {
|
||||
try {
|
||||
const { getAllEpisodeCategories } = await import("./database.js");
|
||||
const categories = await getAllEpisodeCategories();
|
||||
|
||||
console.log(`🔄 Generating ${categories.length} category RSS files...`);
|
||||
|
||||
for (const category of categories) {
|
||||
try {
|
||||
await saveCategoryRSSFile(category);
|
||||
} catch (error) {
|
||||
console.error(`❌ Failed to generate RSS for category "${category}":`, error);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`✅ Generated category RSS files for ${categories.length} categories`);
|
||||
} catch (error) {
|
||||
console.error("❌ Error generating category RSS files:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate all feed RSS files as static files
|
||||
*/
|
||||
export async function generateAllFeedRSSFiles(): Promise<void> {
|
||||
try {
|
||||
const { fetchActiveFeeds } = await import("./database.js");
|
||||
const feeds = await fetchActiveFeeds();
|
||||
|
||||
console.log(`🔄 Generating ${feeds.length} feed RSS files...`);
|
||||
|
||||
for (const feed of feeds) {
|
||||
try {
|
||||
await saveFeedRSSFile(feed.id);
|
||||
} catch (error) {
|
||||
console.error(`❌ Failed to generate RSS for feed "${feed.id}":`, error);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`✅ Generated feed RSS files for ${feeds.length} feeds`);
|
||||
} catch (error) {
|
||||
console.error("❌ Error generating feed RSS files:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save category RSS as static file with URL-safe filename
|
||||
*/
|
||||
export async function saveCategoryRSSFile(category: string): Promise<void> {
|
||||
try {
|
||||
const rssXml = await generateCategoryRSS(category);
|
||||
const safeCategory = encodeURIComponent(category);
|
||||
const outputPath = path.join(
|
||||
config.paths.publicDir,
|
||||
`podcast_category_${safeCategory}.xml`,
|
||||
);
|
||||
|
||||
// Ensure directory exists
|
||||
await fs.mkdir(dirname(outputPath), { recursive: true });
|
||||
await fs.writeFile(outputPath, rssXml);
|
||||
|
||||
console.log(`📄 Category RSS saved: podcast_category_${safeCategory}.xml`);
|
||||
} catch (error) {
|
||||
console.error(`❌ Error saving category RSS for "${category}":`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save feed RSS as static file
|
||||
*/
|
||||
export async function saveFeedRSSFile(feedId: string): Promise<void> {
|
||||
try {
|
||||
const rssXml = await generateFeedRSS(feedId);
|
||||
const outputPath = path.join(
|
||||
config.paths.publicDir,
|
||||
`podcast_feed_${feedId}.xml`,
|
||||
);
|
||||
|
||||
// Ensure directory exists
|
||||
await fs.mkdir(dirname(outputPath), { recursive: true });
|
||||
await fs.writeFile(outputPath, rssXml);
|
||||
|
||||
console.log(`📄 Feed RSS saved: podcast_feed_${feedId}.xml`);
|
||||
} catch (error) {
|
||||
console.error(`❌ Error saving feed RSS for "${feedId}":`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate all static files on startup
|
||||
* This ensures that podcast.xml and other generated files are up-to-date
|
||||
*/
|
||||
export async function regenerateStartupFiles(): Promise<void> {
|
||||
try {
|
||||
console.log("🔄 Regenerating static files on startup...");
|
||||
console.log("🔄 Regenerating all static files on startup...");
|
||||
|
||||
// Regenerate main podcast.xml
|
||||
await updatePodcastRSS();
|
||||
console.log("✅ podcast.xml regenerated successfully");
|
||||
|
||||
// Note: Category and feed-specific RSS files are generated dynamically on request
|
||||
// This is more efficient and ensures they're always up-to-date with current data
|
||||
// Generate all category RSS files
|
||||
await generateAllCategoryRSSFiles();
|
||||
|
||||
// Generate all feed RSS files
|
||||
await generateAllFeedRSSFiles();
|
||||
|
||||
console.log("✅ All startup files regenerated successfully");
|
||||
} catch (error) {
|
||||
|
Reference in New Issue
Block a user