fix: Instagram 热点去除重复卡片
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
286b73a287
commit
ceadeca4eb
@ -159,6 +159,21 @@ describe("InstagramAdapter", () => {
|
||||
expect(items[0].id).toBe("high");
|
||||
expect(items[1].id).toBe("mid");
|
||||
});
|
||||
|
||||
it("deduplicates items by id", async () => {
|
||||
mockFetch.mockResolvedValueOnce({
|
||||
items: [
|
||||
{ code: "AAA", caption: "First", user: { username: "a" }, like_count: 8000 },
|
||||
{ code: "AAA", caption: "First dup", user: { username: "a" }, like_count: 8000 },
|
||||
{ code: "BBB", caption: "Second", user: { username: "b" }, like_count: 3000 },
|
||||
],
|
||||
});
|
||||
|
||||
const items = await adapter.fetchTrending(20);
|
||||
expect(items).toHaveLength(2);
|
||||
expect(items[0].id).toBe("AAA");
|
||||
expect(items[1].id).toBe("BBB");
|
||||
});
|
||||
});
|
||||
|
||||
describe("fetchDetail", () => {
|
||||
|
||||
@ -33,11 +33,16 @@ export class InstagramAdapter implements PlatformAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
const seen = new Set<string>();
|
||||
return items
|
||||
.map((item: unknown, index: number) =>
|
||||
this.mapToContentItem(item as Record<string, unknown>, index)
|
||||
)
|
||||
.filter((item) => item.like_count != null && item.like_count >= 100)
|
||||
.filter((item) => {
|
||||
if (seen.has(item.id)) return false;
|
||||
seen.add(item.id);
|
||||
return item.like_count != null && item.like_count >= 100;
|
||||
})
|
||||
.sort((a, b) => (b.like_count ?? 0) - (a.like_count ?? 0))
|
||||
.slice(0, count);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user