Skip to content

Commit

Permalink
feat: not return duplicate result
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Apr 24, 2023
1 parent 7ef9ccc commit 9bd8c1e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/animegarden/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ export async function fetchResources(
}
}
return {
resources: [...map.values()].sort((lhs, rhs) => rhs.createdAt.localeCompare(lhs.createdAt)),
resources: uniq([...map.values()]),
timestamp
};
} else {
return fetchPage(options.page ?? 1);
const r = await fetchPage(options.page ?? 1);
return {
resources: uniq(r.resources),
timestamp: r.timestamp
};
}

async function fetchPage(page: number) {
Expand Down Expand Up @@ -121,6 +125,14 @@ export async function fetchResources(
);
}
}

function uniq(resources: Resource[]) {
const map = new Map<string, Resource>();
for (const r of resources) {
map.set(r.href, r);
}
return [...map.values()].sort((lhs, rhs) => rhs.createdAt.localeCompare(lhs.createdAt));
}
}

export async function fetchResourceDetail(
Expand Down

0 comments on commit 9bd8c1e

Please sign in to comment.