@@ -2,6 +2,7 @@ package dbv1
22
33import (
44 "context"
5+ "encoding/json"
56 "fmt"
67
78 "bridgerton.audius.co/trashid"
@@ -13,12 +14,18 @@ type FullTracksParams GetTracksParams
1314type FullTrack struct {
1415 GetTracksRow
1516
16- Artwork * SquareImage `json:"artwork"`
17- UserID string `json:"user_id"`
18- User FullUser `json:"user"`
17+ Permalink string `json:"permalink"`
18+ IsStreamable bool `json:"is_streamable"`
19+ Artwork * SquareImage `json:"artwork"`
20+ Stream * MediaLink `json:"stream"`
21+ Download * MediaLink `json:"download"`
22+ Preview * MediaLink `json:"preview"`
23+ UserID string `json:"user_id"`
24+ User FullUser `json:"user"`
1925
2026 FolloweeReposts []* FolloweeRepost `json:"followee_reposts"`
2127 FolloweeFavorites []* FolloweeFavorite `json:"followee_favorites"`
28+ RemixOf FullRemixOf `json:"remix_of"`
2229}
2330
2431func (q * Queries ) FullTracksKeyed (ctx context.Context , arg GetTracksParams ) (map [int32 ]FullTrack , error ) {
@@ -30,6 +37,12 @@ func (q *Queries) FullTracksKeyed(ctx context.Context, arg GetTracksParams) (map
3037 userIds := []int32 {}
3138 for _ , track := range rawTracks {
3239 userIds = append (userIds , track .UserID )
40+
41+ var remixOf RemixOf
42+ json .Unmarshal (track .RemixOf , & remixOf )
43+ for _ , r := range remixOf .Tracks {
44+ userIds = append (userIds , r .ParentUserId )
45+ }
3346 }
3447
3548 userMap , err := q .FullUsersKeyed (ctx , GetUsersParams {
@@ -52,13 +65,55 @@ func (q *Queries) FullTracksKeyed(ctx context.Context, arg GetTracksParams) (map
5265 continue
5366 }
5467
68+ // Collect media links
69+ // TODO(API-49): support self-access via grants
70+ // see https://github.com/AudiusProject/audius-protocol/blob/4bd9fe80d8cca519844596061505ad8737579019/packages/discovery-provider/src/queries/query_helpers.py#L905
71+ stream := mediaLink (track .TrackCid .String , track .TrackID , arg .MyID .(int32 ))
72+ var download * MediaLink
73+ if track .IsDownloadable {
74+ download = mediaLink (track .OrigFileCid .String , track .TrackID , arg .MyID .(int32 ))
75+ }
76+ var preview * MediaLink
77+ if track .PreviewCid .String != "" {
78+ preview = mediaLink (track .PreviewCid .String , track .TrackID , arg .MyID .(int32 ))
79+ }
80+
81+ // client dies if this field is nil
82+ // todo: what are default field visibility values?
83+ if track .FieldVisibility == nil {
84+ track .FieldVisibility = []byte (`{}` )
85+ }
86+
87+ // remix_of
88+ var remixOf RemixOf
89+ var fullRemixOf FullRemixOf
90+ json .Unmarshal (track .RemixOf , & remixOf )
91+ fullRemixOf = FullRemixOf {
92+ Tracks : make ([]FullRemixOfTrack , len (remixOf .Tracks )),
93+ }
94+ for idx , r := range remixOf .Tracks {
95+ trackId , _ := trashid .EncodeHashId (int (r .ParentTrackId ))
96+ fullRemixOf .Tracks [idx ] = FullRemixOfTrack {
97+ HasRemixAuthorReposted : r .HasRemixAuthorReposted ,
98+ HasRemixAuthorSaved : r .HasRemixAuthorSaved ,
99+ ParentTrackId : trackId ,
100+ User : userMap [r .ParentUserId ],
101+ }
102+ }
103+
55104 fullTrack := FullTrack {
56105 GetTracksRow : track ,
106+ IsStreamable : ! track .IsDelete && ! user .IsDeactivated ,
107+ Permalink : fmt .Sprintf ("/%s/%s" , user .Handle .String , track .Slug .String ),
57108 Artwork : squareImageStruct (track .CoverArtSizes , track .CoverArt ),
109+ Stream : stream ,
110+ Download : download ,
111+ Preview : preview ,
58112 User : user ,
59113 UserID : user .ID ,
60114 FolloweeFavorites : fullFolloweeFavorites (track .FolloweeFavorites ),
61115 FolloweeReposts : fullFolloweeReposts (track .FolloweeReposts ),
116+ RemixOf : fullRemixOf ,
62117 }
63118 trackMap [track .TrackID ] = fullTrack
64119 }
0 commit comments