Files
bitvid/dist/js/utils/videoDeduper.js
T
google-labs-jules[bot]andPR0M3TH3AN 0bfa3b08e8 fix(ci): fix netlify deployment by building to dist
- Move from root publishing to clean `dist/` directory
- Create `scripts/build-dist.mjs` to orchestrate build and copy assets
- Update `package.json` build script
- Update `netlify.toml` to publish `dist/`
- Ignore `dist/` in `.gitignore`

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-01-29 09:07:15 +00:00

38 lines
858 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// js/utils/videoDeduper.js
/**
* Given an array of video objects, return only the newest (by created_at) for
* each videoRootId. If no videoRootId is present, treat the video’s own ID as
* its root.
*/
export function dedupeToNewestByRoot(videos) {
const map = new Map();
const normalizeTimestamp = (value) => {
const numeric = Number(value);
return Number.isFinite(numeric) ? numeric : -Infinity;
};
for (const vid of videos || []) {
if (!vid) {
continue;
}
const rootId = vid.videoRootId || vid.id;
if (!rootId) {
continue;
}
const existing = map.get(rootId);
if (
!existing ||
normalizeTimestamp(vid.created_at) > normalizeTimestamp(existing.created_at)
) {
map.set(rootId, vid);
}
}
return Array.from(map.values());
}
export default dedupeToNewestByRoot;