mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-14 21:26:15 -08:00
test(e2e): enhance Xtream category management and sorting with unique title handling
This commit is contained in:
1 parent
654e63de27
commit
3a66bf21a3
9 files changed
+501
-108
No files matched your search
@@ -52,6 +52,20 @@ export async function saveCategories(
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
const existingCategories = await db
|
||||
.select({ count: sql<number>`count(*)` })
|
||||
.from(schema.categories)
|
||||
.where(
|
||||
and(
|
||||
eq(schema.categories.playlistId, playlistId),
|
||||
eq(schema.categories.type, type)
|
||||
)
|
||||
);
|
||||
|
||||
if ((existingCategories[0]?.count ?? 0) > 0) {
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
const hiddenSet = new Set(hiddenCategoryXtreamIds || []);
|
||||
const values = categories.map((category) => ({
|
||||
playlistId,
|
||||
@@ -61,7 +75,16 @@ export async function saveCategories(
|
||||
hidden: hiddenSet.has(category.category_id),
|
||||
}));
|
||||
|
||||
await db.insert(schema.categories).values(values);
|
||||
await db
|
||||
.insert(schema.categories)
|
||||
.values(values)
|
||||
.onConflictDoNothing({
|
||||
target: [
|
||||
schema.categories.playlistId,
|
||||
schema.categories.type,
|
||||
schema.categories.xtreamId,
|
||||
],
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
@@ -219,13 +219,28 @@ export async function saveContent(
|
||||
type: 'live' | 'movie' | 'series',
|
||||
control?: OperationControl
|
||||
): Promise<{ success: boolean; count: number }> {
|
||||
console.log(
|
||||
`>>> DB_SAVE_CONTENT called: ${streams.length} items, type: ${type}, playlist: ${playlistId}`
|
||||
);
|
||||
|
||||
const dbType =
|
||||
type === 'series' ? 'series' : type === 'movie' ? 'movies' : 'live';
|
||||
|
||||
const existingContent = await db
|
||||
.select({ count: sql<number>`count(*)` })
|
||||
.from(schema.content)
|
||||
.innerJoin(
|
||||
schema.categories,
|
||||
eq(schema.content.categoryId, schema.categories.id)
|
||||
)
|
||||
.where(
|
||||
and(
|
||||
eq(schema.categories.playlistId, playlistId),
|
||||
eq(schema.categories.type, dbType),
|
||||
eq(schema.content.type, type)
|
||||
)
|
||||
);
|
||||
|
||||
if ((existingContent[0]?.count ?? 0) > 0) {
|
||||
return { success: true, count: existingContent[0].count };
|
||||
}
|
||||
|
||||
const categories = await db
|
||||
.select({
|
||||
id: schema.categories.id,
|
||||
@@ -255,7 +270,16 @@ export async function saveContent(
|
||||
for (let index = 0; index < values.length; index += chunkSize) {
|
||||
await checkpointOperation(control);
|
||||
const chunk = values.slice(index, index + chunkSize);
|
||||
await db.insert(schema.content).values(chunk);
|
||||
await db
|
||||
.insert(schema.content)
|
||||
.values(chunk)
|
||||
.onConflictDoNothing({
|
||||
target: [
|
||||
schema.content.categoryId,
|
||||
schema.content.type,
|
||||
schema.content.xtreamId,
|
||||
],
|
||||
});
|
||||
totalInserted += chunk.length;
|
||||
await reportOperationProgress(control, {
|
||||
phase: 'saving-content',
|
||||
|
||||
Reference in new issue
Block a user