This commit is contained in:
2025-06-09 08:44:59 +09:00
parent abe4f18273
commit 27004f0cef
3 changed files with 279 additions and 21 deletions

View File

@ -454,6 +454,98 @@ export async function fetchEpisodesWithFeedInfo(): Promise<
}
}
// Get episodes with feed information for enhanced display (paginated)
export async function fetchEpisodesWithFeedInfoPaginated(
page: number = 1,
limit: number = 10,
category?: string
): Promise<{ episodes: EpisodeWithFeedInfo[]; total: number; page: number; limit: number; totalPages: number }> {
try {
const offset = (page - 1) * limit;
// Build query conditions
let whereCondition = "WHERE f.active = 1";
const params: any[] = [];
if (category) {
whereCondition += " AND e.category = ?";
params.push(category);
}
// Get total count
const countStmt = db.prepare(`
SELECT COUNT(*) as count
FROM episodes e
JOIN articles a ON e.article_id = a.id
JOIN feeds f ON a.feed_id = f.id
${whereCondition}
`);
const countResult = countStmt.get(...params) as { count: number };
const total = countResult.count;
// Get paginated episodes
const episodesStmt = db.prepare(`
SELECT
e.id,
e.title,
e.description,
e.audio_path as audioPath,
e.duration,
e.file_size as fileSize,
e.category,
e.created_at as createdAt,
e.article_id as articleId,
a.title as articleTitle,
a.link as articleLink,
a.pub_date as articlePubDate,
f.id as feedId,
f.title as feedTitle,
f.url as feedUrl,
f.category as feedCategory
FROM episodes e
JOIN articles a ON e.article_id = a.id
JOIN feeds f ON a.feed_id = f.id
${whereCondition}
ORDER BY e.created_at DESC
LIMIT ? OFFSET ?
`);
const rows = episodesStmt.all(...params, limit, offset) as any[];
const episodes = rows.map((row) => ({
id: row.id,
title: row.title,
description: row.description,
audioPath: row.audioPath,
duration: row.duration,
fileSize: row.fileSize,
category: row.category,
createdAt: row.createdAt,
articleId: row.articleId,
articleTitle: row.articleTitle,
articleLink: row.articleLink,
articlePubDate: row.articlePubDate,
feedId: row.feedId,
feedTitle: row.feedTitle,
feedUrl: row.feedUrl,
feedCategory: row.feedCategory,
}));
const totalPages = Math.ceil(total / limit);
return {
episodes,
total,
page,
limit,
totalPages
};
} catch (error) {
console.error("Error fetching paginated episodes with feed info:", error);
throw error;
}
}
// Get episodes by feed ID
export async function fetchEpisodesByFeedId(
feedId: string,