mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-14 05:06:16 -08:00
Merge pull request #724 from 4gray/refactor/store-refactoring
refactor/store-refactoring
This commit is contained in:
44 files changed
+3287
-1070
No files matched your search
@@ -129,8 +129,19 @@ contextBridge.exposeInMainWorld('electron', {
|
||||
ipcRenderer.invoke('DB_HAS_CATEGORIES', playlistId, type),
|
||||
dbGetCategories: (playlistId: string, type: string) =>
|
||||
ipcRenderer.invoke('DB_GET_CATEGORIES', playlistId, type),
|
||||
dbSaveCategories: (playlistId: string, categories: any[], type: string) =>
|
||||
ipcRenderer.invoke('DB_SAVE_CATEGORIES', playlistId, categories, type),
|
||||
dbSaveCategories: (
|
||||
playlistId: string,
|
||||
categories: any[],
|
||||
type: string,
|
||||
hiddenCategoryXtreamIds?: number[]
|
||||
) =>
|
||||
ipcRenderer.invoke(
|
||||
'DB_SAVE_CATEGORIES',
|
||||
playlistId,
|
||||
categories,
|
||||
type,
|
||||
hiddenCategoryXtreamIds
|
||||
),
|
||||
dbGetAllCategories: (playlistId: string, type: string) =>
|
||||
ipcRenderer.invoke('DB_GET_ALL_CATEGORIES', playlistId, type),
|
||||
dbUpdateCategoryVisibility: (categoryIds: number[], hidden: boolean) =>
|
||||
|
||||
@@ -62,6 +62,7 @@ ipcMain.handle(
|
||||
|
||||
/**
|
||||
* Save categories in bulk
|
||||
* Optionally accepts hidden category data to restore visibility preferences
|
||||
*/
|
||||
ipcMain.handle(
|
||||
'DB_SAVE_CATEGORIES',
|
||||
@@ -72,7 +73,8 @@ ipcMain.handle(
|
||||
category_name: string;
|
||||
category_id: number;
|
||||
}>,
|
||||
type: 'live' | 'movies' | 'series'
|
||||
type: 'live' | 'movies' | 'series',
|
||||
hiddenCategoryXtreamIds?: number[]
|
||||
) => {
|
||||
try {
|
||||
// Skip if no categories to save
|
||||
@@ -81,11 +83,17 @@ ipcMain.handle(
|
||||
}
|
||||
|
||||
const db = await getDatabase();
|
||||
|
||||
// Create a Set of hidden xtreamIds for efficient lookup
|
||||
const hiddenSet = new Set(hiddenCategoryXtreamIds || []);
|
||||
|
||||
const values = categories.map((cat) => ({
|
||||
playlistId,
|
||||
name: cat.category_name,
|
||||
type,
|
||||
xtreamId: cat.category_id,
|
||||
// Restore hidden status if the category was previously hidden
|
||||
hidden: hiddenSet.has(cat.category_id),
|
||||
}));
|
||||
|
||||
await db.insert(schema.categories).values(values);
|
||||
|
||||
@@ -18,14 +18,27 @@ ipcMain.handle(
|
||||
try {
|
||||
const db = await getDatabase();
|
||||
|
||||
// First, get all category IDs for this playlist
|
||||
// First, get all categories for this playlist (including hidden status)
|
||||
const categories = await db
|
||||
.select({ id: schema.categories.id })
|
||||
.select({
|
||||
id: schema.categories.id,
|
||||
xtreamId: schema.categories.xtreamId,
|
||||
type: schema.categories.type,
|
||||
hidden: schema.categories.hidden,
|
||||
})
|
||||
.from(schema.categories)
|
||||
.where(eq(schema.categories.playlistId, playlistId));
|
||||
|
||||
const categoryIds = categories.map((c) => c.id);
|
||||
|
||||
// Save hidden categories info to restore after refresh
|
||||
const hiddenCategories = categories
|
||||
.filter((c) => c.hidden)
|
||||
.map((c) => ({
|
||||
xtreamId: c.xtreamId,
|
||||
type: c.type,
|
||||
}));
|
||||
|
||||
// Before deleting content, save xtreamIds of favorited and recently viewed items
|
||||
// so they can be restored after refresh
|
||||
let favoritedXtreamIds: number[] = [];
|
||||
@@ -89,11 +102,12 @@ ipcMain.handle(
|
||||
.delete(schema.categories)
|
||||
.where(eq(schema.categories.playlistId, playlistId));
|
||||
|
||||
// Return the saved xtreamIds so favorites and recently viewed can be restored
|
||||
// Return the saved xtreamIds so favorites, recently viewed, and hidden categories can be restored
|
||||
return {
|
||||
success: true,
|
||||
favoritedXtreamIds,
|
||||
recentlyViewedXtreamIds,
|
||||
hiddenCategories,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error deleting Xtream content:', error);
|
||||
|
||||
Reference in new issue
Block a user