From 64b14c6bc1dbea358076d3c367adf40d368fe5b1 Mon Sep 17 00:00:00 2001 From: maciejpedzich Date: Wed, 6 Jul 2022 14:01:20 +0200 Subject: [PATCH] Add numFollowers field to each snapshot --- server/api/playlists/[playlistId]/snapshots.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/server/api/playlists/[playlistId]/snapshots.ts b/server/api/playlists/[playlistId]/snapshots.ts index 8d1b0c7..d623936 100644 --- a/server/api/playlists/[playlistId]/snapshots.ts +++ b/server/api/playlists/[playlistId]/snapshots.ts @@ -2,6 +2,7 @@ import { $fetch } from 'ohmyfetch'; import { octokit } from '~~/server/utils/octokit'; import { filterByUniqueKeyValue } from '~~/server/utils/filterByUniqueKeyValue'; +import { Playlist } from '~~/models/playlist'; export default defineEventHandler(async (event) => { const query = useQuery(event); @@ -34,23 +35,24 @@ export default defineEventHandler(async (event) => { const snapshotFileContents = await Promise.all( commitListings.map(({ sha }) => - $fetch<{ snapshot_id: string }>( + $fetch( `https://raw.githubusercontent.com/mackorone/spotify-playlist-archive/${sha}/playlists/pretty/${playlistId}.json`, { parseResponse: JSON.parse } ) ) ); const possiblyDuplicateSnapshotEntries = snapshotFileContents.map( - ({ snapshot_id }, index) => ({ + ({ snapshot_id, num_followers }, index) => ({ snapshotId: snapshot_id, commitSha: commitListings[index].sha, - dateCaptured: commitListings[index].commit.author.date + dateCaptured: commitListings[index].commit.author.date, + numFollowers: num_followers }) ); - // Since the above's entries are sorted by the latest dateCaptured first, + // Since commit listings are sorted by the latest dateCaptured first, // the following will preserve the last item with a duplicate key value. - // Therefore, we'll be left with entries containing the earliest dateCaptured... + // Therefore, we'll be left with entries containing the earliest dateCaptured. const uniqueSnapshotEntries = filterByUniqueKeyValue( possiblyDuplicateSnapshotEntries, 'snapshotId'