This repository was archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Update explore endpoints in libs to use v1 #1539
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,19 @@ | ||
| import { ID } from '@audius/common' | ||
|
|
||
| import { Collection } from 'common/models/Collection' | ||
| import { Collection, UserCollectionMetadata } from 'common/models/Collection' | ||
| import FeedFilter from 'common/models/FeedFilter' | ||
| import { Track, UserTrack } from 'common/models/Track' | ||
| import { removeNullable } from 'common/utils/typeUtils' | ||
| import AudiusBackend, { | ||
| IDENTITY_SERVICE, | ||
| AuthHeaders | ||
| } from 'services/AudiusBackend' | ||
| import apiClient from 'services/audius-api-client/AudiusAPIClient' | ||
| import * as adapter from 'services/audius-api-client/ResponseAdapter' | ||
| import { APIPlaylist, APITrack } from 'services/audius-api-client/types' | ||
| import { encodeHashId } from 'utils/route/hashIds' | ||
|
|
||
| type CollectionWithScore = Collection & { score: number } | ||
| type CollectionWithScore = APIPlaylist & { score: number } | ||
|
|
||
| // @ts-ignore | ||
| const libs = () => window.audiusLibs | ||
|
|
@@ -64,17 +68,19 @@ class Explore { | |
| } | ||
|
|
||
| static async getTopFolloweeTracksFromWindow( | ||
| userId: ID, | ||
| window: string, | ||
| limit = 25 | ||
| ): Promise<UserTrack[]> { | ||
| try { | ||
| const tracks = await libs().discoveryProvider.getTopFolloweeWindowed( | ||
| 'track', | ||
| const encodedUserId = encodeHashId(userId) | ||
| const tracks = await libs().discoveryProvider.getBestNewReleases( | ||
| encodedUserId, | ||
| window, | ||
| limit, | ||
| true | ||
| ) | ||
| return tracks | ||
| return tracks.map(adapter.makeTrack).filter(removeNullable) | ||
| } catch (e) { | ||
| console.error(e) | ||
| return [] | ||
|
|
@@ -130,6 +136,22 @@ class Explore { | |
| } | ||
| } | ||
|
|
||
| static async getMostLovedTracks(userId: ID, limit = 25) { | ||
| try { | ||
| const encodedUserId = encodeHashId(userId) | ||
| const tracks: APITrack[] = | ||
| await libs().discoveryProvider.getMostLovedTracks( | ||
| encodedUserId, | ||
| limit, | ||
| true | ||
| ) | ||
| return tracks.map(adapter.makeTrack).filter(removeNullable) | ||
| } catch (e) { | ||
| console.error(e) | ||
| return [] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just wondering what the error case is here, i guess seems like the pattern in the file?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Retuning |
||
| } | ||
| } | ||
|
|
||
| static async getLatestTrackID(): Promise<number> { | ||
| try { | ||
| const latestTrackID = await libs().discoveryProvider.getLatest('track') | ||
|
|
@@ -147,14 +169,15 @@ class Explore { | |
| limit = 20 | ||
| ): Promise<Collection[]> { | ||
| try { | ||
| const playlists = await libs().discoveryProvider.getTopPlaylists( | ||
| const playlists = await libs().discoveryProvider.getTopFullPlaylists({ | ||
| type, | ||
| limit, | ||
| undefined, | ||
| followeesOnly ? 'followees' : undefined, | ||
| true | ||
| ) | ||
| return playlists | ||
| mood: undefined, | ||
| filter: followeesOnly ? 'followees' : undefined, | ||
| withUsers: true | ||
| }) | ||
| const adapted = playlists.map(adapter.makePlaylist) | ||
| return adapted | ||
| } catch (e) { | ||
| console.error(e) | ||
| return [] | ||
|
|
@@ -164,24 +187,26 @@ class Explore { | |
| static async getTopPlaylistsForMood( | ||
| moods: string[], | ||
| limit = 16 | ||
| ): Promise<Collection[]> { | ||
| ): Promise<UserCollectionMetadata[]> { | ||
| try { | ||
| const requests = moods.map((mood) => { | ||
| return libs().discoveryProvider.getTopPlaylists( | ||
| 'playlist', | ||
| return libs().discoveryProvider.getTopFullPlaylists({ | ||
| type: 'playlist', | ||
| limit, | ||
| mood, | ||
| undefined, | ||
| true | ||
| ) | ||
| filter: undefined, | ||
| withUsers: true | ||
| }) | ||
| }) | ||
| const playlistsByMood = await Promise.all(requests) | ||
|
|
||
| const playlistsByMood: CollectionWithScore[] = await Promise.all(requests) | ||
| let allPlaylists: CollectionWithScore[] = [] | ||
| playlistsByMood.forEach((playlists) => { | ||
| allPlaylists = allPlaylists.concat(playlists) | ||
| }) | ||
| return allPlaylists.sort(scoreComparator).slice(0, 20) | ||
| const playlists: APIPlaylist[] = allPlaylists | ||
| .sort(scoreComparator) | ||
| .slice(0, 20) | ||
| return playlists.map(adapter.makePlaylist).filter(removeNullable) | ||
| } catch (e) { | ||
| console.error(e) | ||
| return [] | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does
const tracks = yield* call(...)not returnUserTrackMetadata[]? or are the types not defined in libs or something?