Skip to content

Commit 985a4b2

Browse files
committed
Merge remote-tracking branch 'origin/main' into mjp-rewards
2 parents 0dcff70 + bccd821 commit 985a4b2

39 files changed

Lines changed: 879 additions & 103 deletions

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ test::
77
go test -count=1 -cover ./...
88

99
staging::
10-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/bridge-amd64
11-
rsync -ravz build/ stage-discovery-4:bridgerton
10+
mkdir -p build/staging
11+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/staging/bridge-amd64
12+
rsync -ravz build/staging/ stage-discovery-4:bridgerton
1213
ssh stage-discovery-4 -t 'cd bridgerton && docker compose up -d --build && docker compose restart bridge'
1314
curl 'https://bridgerton.staging.audius.co'
1415

16+
production::
17+
mkdir -p build/production
18+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/production/bridge-amd64
19+
rsync -ravz build/production/ prod-discovery-4:bridgerton
20+
ssh prod-discovery-4 -t 'cd bridgerton && docker compose up -d --build && docker compose restart bridge'
21+
curl 'https://bridgerton.audius.co'
22+
1523
psql::
1624
docker compose exec db psql -U postgres
1725

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ http://localhost:1323/v2/users/stereosteve
2424

2525
> This will watch sql files + re-run `sqlc generate` + restart server when go files change.
2626
27+
other env vars:
28+
```
29+
delegatePrivateKey: key to sign stream/download requests with
30+
axiomToken: axiom api token to pipe logs to axiom
31+
axiomDataset: axiom dataset name
32+
```
2733

2834
## API diff
2935

30-
test diffs from v1/ endpoints
31-
```
32-
make apidiff
33-
```
36+
http://localhost:1323/apidiff.html
3437

3538
## adminer
3639

api/dbv1/full_tracks.go

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dbv1
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67

78
"bridgerton.audius.co/trashid"
@@ -13,12 +14,18 @@ type FullTracksParams GetTracksParams
1314
type 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

2431
func (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
}

api/dbv1/full_users.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ func (q *Queries) FullUsersKeyed(ctx context.Context, arg GetUsersParams) (map[i
4646

4747
if cid != "" {
4848
// rendezvous for cid
49-
rankedHosts := rendezvous.GlobalHasher.Rank(cid)
50-
first := rankedHosts[0]
51-
rest := rankedHosts[1:3]
49+
first, rest := rendezvous.GlobalHasher.ReplicaSet3(cid)
5250

5351
coverPhoto = &RectangleImage{
5452
X640: fmt.Sprintf("%s/content/%s/640x.jpg", first, cid),
@@ -110,9 +108,7 @@ func squareImageStruct(maybeCids ...pgtype.Text) *SquareImage {
110108
}
111109

112110
// rendezvous for cid
113-
rankedHosts := rendezvous.GlobalHasher.Rank(cid)
114-
first := rankedHosts[0]
115-
rest := rankedHosts[1:3]
111+
first, rest := rendezvous.GlobalHasher.ReplicaSet3(cid)
116112

117113
return &SquareImage{
118114
X150x150: fmt.Sprintf("%s/content/%s/150x150.jpg", first, cid),

api/dbv1/get_tracks.sql.go

Lines changed: 30 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/dbv1/jsonb_types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,23 @@ type FolloweeFavorite struct {
4646
UserId string `json:"user_id"`
4747
CreatedAt string `json:"created_at"`
4848
}
49+
50+
type RemixOf struct {
51+
Tracks []struct {
52+
HasRemixAuthorReposted bool `json:"has_remix_author_reposted"`
53+
HasRemixAuthorSaved bool `json:"has_remix_author_saved"`
54+
ParentTrackId int32 `json:"parent_track_id"`
55+
ParentUserId int32 `json:"parent_user_id"`
56+
}
57+
}
58+
59+
type FullRemixOfTrack struct {
60+
HasRemixAuthorReposted bool `json:"has_remix_author_reposted"`
61+
HasRemixAuthorSaved bool `json:"has_remix_author_saved"`
62+
ParentTrackId string `json:"parent_track_id"`
63+
User FullUser `json:"user"`
64+
}
65+
66+
type FullRemixOf struct {
67+
Tracks []FullRemixOfTrack `json:"tracks"`
68+
}

0 commit comments

Comments
 (0)