Add category deletion feature
This commit is contained in:
@ -1633,6 +1633,97 @@ export async function updateEpisodeCategory(
|
||||
}
|
||||
}
|
||||
|
||||
// Category cleanup functions
|
||||
export async function deleteFeedCategory(category: string): Promise<number> {
|
||||
try {
|
||||
const stmt = db.prepare("UPDATE feeds SET category = NULL WHERE category = ?");
|
||||
const result = stmt.run(category);
|
||||
return result.changes;
|
||||
} catch (error) {
|
||||
console.error("Error deleting feed category:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteEpisodeCategory(category: string): Promise<number> {
|
||||
try {
|
||||
const stmt = db.prepare("UPDATE episodes SET category = NULL WHERE category = ?");
|
||||
const result = stmt.run(category);
|
||||
return result.changes;
|
||||
} catch (error) {
|
||||
console.error("Error deleting episode category:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteCategoryFromBoth(category: string): Promise<{feedChanges: number, episodeChanges: number}> {
|
||||
try {
|
||||
db.exec("BEGIN TRANSACTION");
|
||||
|
||||
const feedChanges = await deleteFeedCategory(category);
|
||||
const episodeChanges = await deleteEpisodeCategory(category);
|
||||
|
||||
db.exec("COMMIT");
|
||||
|
||||
return { feedChanges, episodeChanges };
|
||||
} catch (error) {
|
||||
db.exec("ROLLBACK");
|
||||
console.error("Error deleting category from both tables:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllUsedCategories(): Promise<{feedCategories: string[], episodeCategories: string[], allCategories: string[]}> {
|
||||
try {
|
||||
// Get feed categories
|
||||
const feedCatStmt = db.prepare(
|
||||
"SELECT DISTINCT category FROM feeds WHERE category IS NOT NULL AND category != '' ORDER BY category"
|
||||
);
|
||||
const feedCatRows = feedCatStmt.all() as any[];
|
||||
const feedCategories = feedCatRows.map(row => row.category);
|
||||
|
||||
// Get episode categories
|
||||
const episodeCatStmt = db.prepare(
|
||||
"SELECT DISTINCT category FROM episodes WHERE category IS NOT NULL AND category != '' ORDER BY category"
|
||||
);
|
||||
const episodeCatRows = episodeCatStmt.all() as any[];
|
||||
const episodeCategories = episodeCatRows.map(row => row.category);
|
||||
|
||||
// Get all unique categories
|
||||
const allCategoriesSet = new Set([...feedCategories, ...episodeCategories]);
|
||||
const allCategories = Array.from(allCategoriesSet).sort();
|
||||
|
||||
return {
|
||||
feedCategories,
|
||||
episodeCategories,
|
||||
allCategories
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error getting all used categories:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCategoryCounts(category: string): Promise<{feedCount: number, episodeCount: number}> {
|
||||
try {
|
||||
// Count feeds with this category
|
||||
const feedCountStmt = db.prepare("SELECT COUNT(*) as count FROM feeds WHERE category = ?");
|
||||
const feedCountResult = feedCountStmt.get(category) as { count: number };
|
||||
|
||||
// Count episodes with this category
|
||||
const episodeCountStmt = db.prepare("SELECT COUNT(*) as count FROM episodes WHERE category = ?");
|
||||
const episodeCountResult = episodeCountStmt.get(category) as { count: number };
|
||||
|
||||
return {
|
||||
feedCount: feedCountResult.count,
|
||||
episodeCount: episodeCountResult.count
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error getting category counts:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Migration function to classify existing episodes without categories
|
||||
export async function migrateEpisodesWithCategories(): Promise<void> {
|
||||
try {
|
||||
|
@ -127,7 +127,10 @@ ${articleDetails}
|
||||
try {
|
||||
const response = await openai.chat.completions.create({
|
||||
model: config.openai.modelName,
|
||||
messages: [{ role: "system", content: prompt.trim() }, {role:"user", content: sendContent.trim()}],
|
||||
messages: [
|
||||
{ role: "system", content: prompt.trim() },
|
||||
{ role: "user", content: sendContent.trim() },
|
||||
],
|
||||
temperature: 0.6,
|
||||
});
|
||||
|
||||
@ -171,7 +174,9 @@ export async function openAI_ClassifyEpisode(
|
||||
}
|
||||
|
||||
const prompt = `
|
||||
ポッドキャストエピソードの情報を見て、適切なトピックカテゴリに分類してください。
|
||||
以下のポッドキャストエピソードの情報を見て、適切なトピックカテゴリに分類してください。
|
||||
|
||||
${textForClassification}
|
||||
|
||||
以下のカテゴリから1つを選択してください:
|
||||
- テクノロジー
|
||||
@ -191,8 +196,8 @@ export async function openAI_ClassifyEpisode(
|
||||
try {
|
||||
const response = await openai.chat.completions.create({
|
||||
model: config.openai.modelName,
|
||||
messages: [{ role: "system", content: prompt.trim() }, {role: "user", content: textForClassification.trim()}],
|
||||
temperature: 0.3,
|
||||
messages: [{ role: "user", content: prompt.trim() }],
|
||||
temperature: 0.2,
|
||||
});
|
||||
|
||||
const category = response.choices[0]?.message?.content?.trim();
|
||||
|
Reference in New Issue
Block a user