diff --git a/api/dbv1/full_developer_apps.go b/api/dbv1/full_developer_apps.go index cda0b799..6f6c28c9 100644 --- a/api/dbv1/full_developer_apps.go +++ b/api/dbv1/full_developer_apps.go @@ -29,3 +29,21 @@ func (q *Queries) FullDeveloperApps(ctx context.Context, arg GetDeveloperAppsPar return fullDeveloperApps, nil } + +type MinDeveloperApp struct { + FullDeveloperApp +} + +func ToMinDeveloperApp(fullDeveloperApp FullDeveloperApp) MinDeveloperApp { + return MinDeveloperApp{ + FullDeveloperApp: fullDeveloperApp, + } +} + +func ToMinDeveloperApps(fullDeveloperApps []FullDeveloperApp) []MinDeveloperApp { + result := make([]MinDeveloperApp, len(fullDeveloperApps)) + for i, d := range fullDeveloperApps { + result[i] = ToMinDeveloperApp(d) + } + return result +} diff --git a/api/dbv1/full_playlists.go b/api/dbv1/full_playlists.go index 75d47e0a..7e1dc6d3 100644 --- a/api/dbv1/full_playlists.go +++ b/api/dbv1/full_playlists.go @@ -97,3 +97,52 @@ func (q *Queries) FullPlaylists(ctx context.Context, arg GetPlaylistsParams) ([] return fullPlaylists, nil } + +type MinPlaylist struct { + ID string `json:"id"` + PlaylistName *string `json:"playlist_name"` + PlaylistOwnerID int32 `json:"playlist_owner_id"` + PlaylistID int32 `json:"playlist_id"` + Artwork SquareImage `json:"artwork"` + Description *string `json:"description"` + PlaylistContents interface{} `json:"playlist_contents"` + IsAlbum bool `json:"is_album"` + IsPrivate bool `json:"is_private"` + FavoriteCount int32 `json:"favorite_count"` + RepostCount int32 `json:"repost_count"` + UserID string `json:"user_id"` + User MinUser `json:"user"` + Tracks []MinTrack `json:"tracks"` +} + +func ToMinPlaylist(fullPlaylist FullPlaylist) MinPlaylist { + minTracks := make([]MinTrack, len(fullPlaylist.Tracks)) + for i, track := range fullPlaylist.Tracks { + minTracks[i] = ToMinTrack(track) + } + + return MinPlaylist{ + ID: fullPlaylist.ID, + PlaylistName: fullPlaylist.PlaylistName, + PlaylistOwnerID: fullPlaylist.PlaylistOwnerID, + PlaylistID: fullPlaylist.PlaylistID, + Artwork: fullPlaylist.Artwork, + PlaylistContents: fullPlaylist.PlaylistContents, + Description: nil, + IsAlbum: false, + IsPrivate: false, + FavoriteCount: 0, + RepostCount: 0, + UserID: fullPlaylist.UserID, + User: ToMinUser(fullPlaylist.User), + Tracks: minTracks, + } +} + +func ToMinPlaylists(fullPlaylists []FullPlaylist) []MinPlaylist { + result := make([]MinPlaylist, len(fullPlaylists)) + for i, playlist := range fullPlaylists { + result[i] = ToMinPlaylist(playlist) + } + return result +} diff --git a/api/dbv1/full_tracks.go b/api/dbv1/full_tracks.go index 24335b02..8e4140a8 100644 --- a/api/dbv1/full_tracks.go +++ b/api/dbv1/full_tracks.go @@ -2,8 +2,10 @@ package dbv1 import ( "context" + "fmt" "bridgerton.audius.co/trashid" + "bridgerton.audius.co/utils" ) type FullTracksParams GetTracksParams @@ -61,3 +63,71 @@ func (q *Queries) FullTracks(ctx context.Context, arg GetTracksParams) ([]FullTr return fullTracks, nil } + +type MinTrack struct { + ID string `json:"id"` + Title *string `json:"title"` + User MinUser `json:"user"` + Artwork SquareImage `json:"artwork"` + Duration *int32 `json:"duration"` + Description *string `json:"description"` + Genre *string `json:"genre"` + TrackCid *string `json:"track_cid"` + PreviewCid *string `json:"preview_cid"` + OrigFileCid *string `json:"orig_file_cid"` + OrigFilename *string `json:"orig_filename"` + IsOriginalAvailable bool `json:"is_original_available"` + Mood *string `json:"mood"` + ReleaseDate interface{} `json:"release_date"` + RemixOf interface{} `json:"remix_of"` + RepostCount int32 `json:"repost_count"` + FavoriteCount int32 `json:"favorite_count"` + CommentCount *int32 `json:"comment_count"` + Tags *string `json:"tags"` + IsDownloadable bool `json:"is_downloadable"` + PlayCount *int64 `json:"play_count"` + PinnedCommentID *int32 `json:"pinned_comment_id"` + PlaylistsContainingTrack []interface{} `json:"playlists_containing_track"` + AlbumBacklink interface{} `json:"album_backlink"` + IsStreamable bool `json:"is_streamable"` + Permalink string `json:"permalink"` +} + +func ToMinTrack(fullTrack FullTrack) MinTrack { + return MinTrack{ + ID: fullTrack.ID, + Title: fullTrack.Title, + User: ToMinUser(fullTrack.User), + Artwork: fullTrack.Artwork, + Duration: fullTrack.Duration, + Description: fullTrack.Description, + Genre: fullTrack.Genre, + TrackCid: fullTrack.TrackCid, + PreviewCid: fullTrack.PreviewCid, + OrigFileCid: fullTrack.OrigFileCid, + OrigFilename: fullTrack.OrigFilename, + IsOriginalAvailable: fullTrack.IsOriginalAvailable, + Mood: fullTrack.Mood, + ReleaseDate: fullTrack.ReleaseDate, + RemixOf: fullTrack.RemixOf, + RepostCount: fullTrack.RepostCount, + FavoriteCount: fullTrack.FavoriteCount, + CommentCount: fullTrack.CommentCount, + Tags: fullTrack.Tags, + IsDownloadable: fullTrack.IsDownloadable, + PlayCount: fullTrack.PlayCount, + PinnedCommentID: fullTrack.PinnedCommentID, + PlaylistsContainingTrack: []interface{}{}, // TODO + AlbumBacklink: nil, + IsStreamable: !fullTrack.IsDelete && !fullTrack.User.IsDeactivated, + Permalink: fmt.Sprintf("/%s/%s", utils.String(fullTrack.User.Handle), utils.String(fullTrack.Slug)), + } +} + +func ToMinTracks(fullTracks []FullTrack) []MinTrack { + result := make([]MinTrack, len(fullTracks)) + for i, track := range fullTracks { + result[i] = ToMinTrack(track) + } + return result +} diff --git a/api/dbv1/full_users.go b/api/dbv1/full_users.go index bc260768..1f57d578 100644 --- a/api/dbv1/full_users.go +++ b/api/dbv1/full_users.go @@ -102,3 +102,83 @@ func squareImageStruct(maybeCids ...*string) SquareImage { Mirrors: rest, } } + +type MinUser struct { + ID string `json:"id"` + AlbumCount *int64 `json:"album_count"` + ArtistPickTrackID *string `json:"artist_pick_track_id"` + Bio *string `json:"bio"` + CoverPhoto RectangleImage `json:"cover_photo"` + FolloweeCount *int64 `json:"followee_count"` + FollowerCount *int64 `json:"follower_count"` + Handle *string `json:"handle"` + IsVerified bool `json:"is_verified"` + TwitterHandle *string `json:"twitter_handle"` + InstagramHandle *string `json:"instagram_handle"` + TiktokHandle *string `json:"tiktok_handle"` + VerifiedWithTwitter *bool `json:"verified_with_twitter"` + VerifiedWithInstagram *bool `json:"verified_with_instagram"` + VerifiedWithTiktok *bool `json:"verified_with_tiktok"` + Website *string `json:"website"` + Donation *string `json:"donation"` + Location *string `json:"location"` + Name *string `json:"name"` + PlaylistCount *int64 `json:"playlist_count"` + ProfilePicture SquareImage `json:"profile_picture"` + RepostCount *int64 `json:"repost_count"` + TrackCount *int64 `json:"track_count"` + IsDeactivated bool `json:"is_deactivated"` + IsAvailable bool `json:"is_available"` + ErcWallet *string `json:"erc_wallet"` + SplWallet *string `json:"spl_wallet"` + SplUsdcPayoutWallet *string `json:"spl_usdc_payout_wallet"` + SupporterCount int32 `json:"supporter_count"` + SupportingCount int32 `json:"supporting_count"` + TotalAudioBalance int32 `json:"total_audio_balance"` + Wallet *string `json:"wallet"` +} + +func ToMinUser(fullUser FullUser) MinUser { + return MinUser{ + ID: fullUser.ID, + AlbumCount: fullUser.AlbumCount, + ArtistPickTrackID: fullUser.ArtistPickTrackID, + Bio: fullUser.Bio, + CoverPhoto: fullUser.CoverPhoto, + FolloweeCount: fullUser.FolloweeCount, + FollowerCount: fullUser.FollowerCount, + Handle: fullUser.Handle, + IsVerified: fullUser.IsVerified, + TwitterHandle: fullUser.TwitterHandle, + InstagramHandle: fullUser.InstagramHandle, + TiktokHandle: fullUser.TiktokHandle, + VerifiedWithTwitter: fullUser.VerifiedWithTwitter, + VerifiedWithInstagram: fullUser.VerifiedWithInstagram, + VerifiedWithTiktok: fullUser.VerifiedWithTiktok, + Website: fullUser.Website, + Donation: fullUser.Donation, + Location: fullUser.Location, + Name: fullUser.Name, + PlaylistCount: fullUser.PlaylistCount, + ProfilePicture: fullUser.ProfilePicture, + RepostCount: fullUser.RepostCount, + TrackCount: fullUser.TrackCount, + IsDeactivated: fullUser.IsDeactivated, + IsAvailable: fullUser.IsAvailable, + ErcWallet: fullUser.ErcWallet, + SplWallet: fullUser.SplWallet, + SplUsdcPayoutWallet: fullUser.SplUsdcPayoutWallet, + SupporterCount: fullUser.SupporterCount, + SupportingCount: fullUser.SupportingCount, + TotalAudioBalance: fullUser.TotalAudioBalance, + Wallet: fullUser.Wallet, + } +} + +func ToMinUsers(fullUsers []FullUser) []MinUser { + result := make([]MinUser, len(fullUsers)) + for i, user := range fullUsers { + result[i] = ToMinUser(user) + } + return result +} diff --git a/api/dbv1/get_tracks.sql.go b/api/dbv1/get_tracks.sql.go index b8d21cfb..d90d56a8 100644 --- a/api/dbv1/get_tracks.sql.go +++ b/api/dbv1/get_tracks.sql.go @@ -32,6 +32,7 @@ SELECT comment_count, tags, title, + track_routes.slug as slug, -- user, duration, is_downloadable, @@ -43,7 +44,7 @@ SELECT pinned_comment_id, -- album_backlink, -- access, - blocknumber, + t.blocknumber, create_date, t.created_at, cover_art_sizes, @@ -83,8 +84,8 @@ SELECT stem_of, -- track_segments, todo: can we just get rid of this now? t.updated_at, - owner_id as user_id, - is_delete, + t.owner_id as user_id, + t.is_delete, cover_art, is_available, ai_attribution_user_id, @@ -123,8 +124,9 @@ SELECT FROM tracks t JOIN aggregate_track using (track_id) LEFT JOIN aggregate_plays on play_item_id = t.track_id +LEFT JOIN track_routes on t.track_id = track_routes.track_id and track_routes.is_current = true WHERE is_available = true - AND (is_unlisted = false OR owner_id = $1) + AND (is_unlisted = false OR t.owner_id = $1) AND ( t.track_id = $2 OR t.owner_id = $3 @@ -158,6 +160,7 @@ type GetTracksRow struct { CommentCount *int32 `json:"comment_count"` Tags *string `json:"tags"` Title *string `json:"title"` + Slug *string `json:"slug"` Duration *int32 `json:"duration"` IsDownloadable bool `json:"is_downloadable"` PlayCount *int64 `json:"play_count"` @@ -240,6 +243,7 @@ func (q *Queries) GetTracks(ctx context.Context, arg GetTracksParams) ([]GetTrac &i.CommentCount, &i.Tags, &i.Title, + &i.Slug, &i.Duration, &i.IsDownloadable, &i.PlayCount, diff --git a/api/dbv1/queries/get_tracks.sql b/api/dbv1/queries/get_tracks.sql index ba081fd1..3e627e55 100644 --- a/api/dbv1/queries/get_tracks.sql +++ b/api/dbv1/queries/get_tracks.sql @@ -18,6 +18,7 @@ SELECT comment_count, tags, title, + track_routes.slug as slug, -- user, duration, is_downloadable, @@ -29,7 +30,7 @@ SELECT pinned_comment_id, -- album_backlink, -- access, - blocknumber, + t.blocknumber, create_date, t.created_at, cover_art_sizes, @@ -69,8 +70,8 @@ SELECT stem_of, -- track_segments, todo: can we just get rid of this now? t.updated_at, - owner_id as user_id, - is_delete, + t.owner_id as user_id, + t.is_delete, cover_art, is_available, ai_attribution_user_id, @@ -109,8 +110,9 @@ SELECT FROM tracks t JOIN aggregate_track using (track_id) LEFT JOIN aggregate_plays on play_item_id = t.track_id +LEFT JOIN track_routes on t.track_id = track_routes.track_id and track_routes.is_current = true WHERE is_available = true - AND (is_unlisted = false OR owner_id = @my_id) + AND (is_unlisted = false OR t.owner_id = @my_id) AND ( t.track_id = @track_id OR t.owner_id = @owner_id diff --git a/api/server.go b/api/server.go index 7bb744f6..d8cda682 100644 --- a/api/server.go +++ b/api/server.go @@ -62,6 +62,18 @@ func InitLogger(config Config) *zap.Logger { return logger } +func Min(handler func(*fiber.Ctx, bool) error) fiber.Handler { + return func(c *fiber.Ctx) error { + return handler(c, true) + } +} + +func Full(handler func(*fiber.Ctx, bool) error) fiber.Handler { + return func(c *fiber.Ctx) error { + return handler(c, false) + } +} + func NewApiServer(config Config) *ApiServer { logger := InitLogger(config) @@ -89,24 +101,38 @@ func NewApiServer(config Config) *ApiServer { app.Get("/", app.home) // v1/full - app.Get("/v1/full/users", app.v1Users) - app.Get("/v1/full/users/:userId/followers", app.v1UsersFollowers) - app.Get("/v1/full/users/:userId/following", app.v1UsersFollowing) - app.Get("/v1/full/users/:userId/mutuals", app.v1UsersMutuals) - app.Get("/v1/full/users/:userId/supporting", app.v1UsersSupporting) + app.Get("/v1/full/users", Full(app.v1Users)) + app.Get("/v1/full/users/:userId/followers", Full(app.v1UsersFollowers)) + app.Get("/v1/full/users/:userId/following", Full(app.v1UsersFollowing)) + app.Get("/v1/full/users/:userId/mutuals", Full(app.v1UsersMutuals)) + app.Get("/v1/full/users/:userId/supporting", Full(app.v1UsersSupporting)) - app.Get("/v1/full/tracks", app.v1Tracks) - app.Get("/v1/full/tracks/:trackId/reposts", app.v1TrackReposts) - app.Get("/v1/full/tracks/:trackId/favorites", app.v1TrackFavorites) + app.Get("/v1/full/tracks", Full(app.v1Tracks)) + app.Get("/v1/full/tracks/:trackId/reposts", Full(app.v1TrackReposts)) + app.Get("/v1/full/tracks/:trackId/favorites", Full(app.v1TrackFavorites)) - app.Get("/v1/full/playlists", app.v1playlists) - app.Get("/v1/full/playlists/:playlistId/reposts", app.v1PlaylistsReposts) - app.Get("/v1/full/playlists/:playlistId/favorites", app.v1PlaylistsFavorites) + app.Get("/v1/full/playlists", Full(app.v1playlists)) + app.Get("/v1/full/playlists/:playlistId/reposts", Full(app.v1PlaylistsReposts)) + app.Get("/v1/full/playlists/:playlistId/favorites", Full(app.v1PlaylistsFavorites)) - app.Get("/v1/full/developer_apps/:address", app.v1DeveloperApps) + app.Get("/v1/full/developer_apps/:address", Full(app.v1DeveloperApps)) // v1 - app.Get("/v1/developer_apps/:address", app.v1DeveloperApps) + app.Get("/v1/users", Min(app.v1Users)) + app.Get("/v1/users/:userId/followers", Min(app.v1UsersFollowers)) + app.Get("/v1/users/:userId/following", Min(app.v1UsersFollowing)) + app.Get("/v1/users/:userId/mutuals", Min(app.v1UsersMutuals)) + app.Get("/v1/users/:userId/supporting", Min(app.v1UsersSupporting)) + + app.Get("/v1/tracks", Min(app.v1Tracks)) + app.Get("/v1/tracks/:trackId/reposts", Min(app.v1TrackReposts)) + app.Get("/v1/tracks/:trackId/favorites", Min(app.v1TrackFavorites)) + + app.Get("/v1/playlists", Min(app.v1playlists)) + app.Get("/v1/playlists/:playlistId/reposts", Min(app.v1PlaylistsReposts)) + app.Get("/v1/playlists/:playlistId/favorites", Min(app.v1PlaylistsFavorites)) + + app.Get("/v1/developer_apps/:address", Min(app.v1DeveloperApps)) // proxy unhandled requests thru to existing discovery API { diff --git a/api/v1_developer_apps.go b/api/v1_developer_apps.go index 45a80cea..512cf450 100644 --- a/api/v1_developer_apps.go +++ b/api/v1_developer_apps.go @@ -7,7 +7,7 @@ import ( "github.com/gofiber/fiber/v2" ) -func (as *ApiServer) v1DeveloperApps(c *fiber.Ctx) error { +func (as *ApiServer) v1DeveloperApps(c *fiber.Ctx, minResponse bool) error { address := c.Params("address") if address == "" { return fiber.NewError(fiber.StatusBadRequest, "Missing address parameter") @@ -29,6 +29,12 @@ func (as *ApiServer) v1DeveloperApps(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusNotFound, "Developer app not found") } + if minResponse { + return c.JSON(fiber.Map{ + "data": dbv1.ToMinDeveloperApps(developerApps)[0], + }) + } + return c.JSON(fiber.Map{ "data": developerApps[0], }) diff --git a/api/v1_playlists.go b/api/v1_playlists.go index 50e509a3..14e2c1b9 100644 --- a/api/v1_playlists.go +++ b/api/v1_playlists.go @@ -7,7 +7,7 @@ import ( "github.com/jackc/pgx/v5" ) -func (app *ApiServer) v1playlists(c *fiber.Ctx) error { +func (app *ApiServer) v1playlists(c *fiber.Ctx, minResponse bool) error { myId, _ := trashid.DecodeHashId(c.Query("user_id")) ids := decodeIdList(c) @@ -19,12 +19,18 @@ func (app *ApiServer) v1playlists(c *fiber.Ctx) error { return err } + if minResponse { + return c.JSON(fiber.Map{ + "data": dbv1.ToMinPlaylists(playlists), + }) + } + return c.JSON(fiber.Map{ "data": playlists, }) } -func (app *ApiServer) v1PlaylistsReposts(c *fiber.Ctx) error { +func (app *ApiServer) v1PlaylistsReposts(c *fiber.Ctx, minResponse bool) error { sql := ` SELECT user_id FROM reposts r @@ -46,10 +52,10 @@ func (app *ApiServer) v1PlaylistsReposts(c *fiber.Ctx) error { return app.queryFullUsers(c, sql, pgx.NamedArgs{ "playlistId": playlistId, - }) + }, minResponse) } -func (app *ApiServer) v1PlaylistsFavorites(c *fiber.Ctx) error { +func (app *ApiServer) v1PlaylistsFavorites(c *fiber.Ctx, minResponse bool) error { sql := ` SELECT user_id FROM saves @@ -71,5 +77,5 @@ func (app *ApiServer) v1PlaylistsFavorites(c *fiber.Ctx) error { return app.queryFullUsers(c, sql, pgx.NamedArgs{ "playlistId": playlistId, - }) + }, minResponse) } diff --git a/api/v1_tracks.go b/api/v1_tracks.go index 854d070c..bf25b6fe 100644 --- a/api/v1_tracks.go +++ b/api/v1_tracks.go @@ -7,7 +7,7 @@ import ( "github.com/jackc/pgx/v5" ) -func (app *ApiServer) v1Tracks(c *fiber.Ctx) error { +func (app *ApiServer) v1Tracks(c *fiber.Ctx, minResponse bool) error { myId, _ := trashid.DecodeHashId(c.Query("user_id")) ids := decodeIdList(c) @@ -18,12 +18,18 @@ func (app *ApiServer) v1Tracks(c *fiber.Ctx) error { if err != nil { return err } + if minResponse { + return c.JSON(fiber.Map{ + "data": dbv1.ToMinTracks(tracks), + }) + } + return c.JSON(fiber.Map{ "data": tracks, }) } -func (app *ApiServer) v1TrackReposts(c *fiber.Ctx) error { +func (app *ApiServer) v1TrackReposts(c *fiber.Ctx, minResponse bool) error { sql := ` SELECT user_id FROM reposts r @@ -45,10 +51,10 @@ func (app *ApiServer) v1TrackReposts(c *fiber.Ctx) error { return app.queryFullUsers(c, sql, pgx.NamedArgs{ "trackId": trackId, - }) + }, minResponse) } -func (app *ApiServer) v1TrackFavorites(c *fiber.Ctx) error { +func (app *ApiServer) v1TrackFavorites(c *fiber.Ctx, minResponse bool) error { sql := ` SELECT user_id FROM saves @@ -70,5 +76,5 @@ func (app *ApiServer) v1TrackFavorites(c *fiber.Ctx) error { return app.queryFullUsers(c, sql, pgx.NamedArgs{ "trackId": trackId, - }) + }, minResponse) } diff --git a/api/v1_users.go b/api/v1_users.go index 72597bff..6a47f7f9 100644 --- a/api/v1_users.go +++ b/api/v1_users.go @@ -7,7 +7,8 @@ import ( "github.com/jackc/pgx/v5" ) -func (app *ApiServer) v1Users(c *fiber.Ctx) error { +// v1Users is a handler that retrieves full user data +func (app *ApiServer) v1Users(c *fiber.Ctx, minResponse bool) error { myId, _ := trashid.DecodeHashId(c.Query("user_id")) ids := decodeIdList(c) @@ -26,12 +27,18 @@ func (app *ApiServer) v1Users(c *fiber.Ctx) error { return err } + if minResponse { + return c.JSON(fiber.Map{ + "data": dbv1.ToMinUsers(users), + }) + } + return c.JSON(fiber.Map{ "data": users, }) } -func (app *ApiServer) v1UsersFollowers(c *fiber.Ctx) error { +func (app *ApiServer) v1UsersFollowers(c *fiber.Ctx, minResponse bool) error { sql := ` SELECT follower_user_id @@ -53,10 +60,10 @@ func (app *ApiServer) v1UsersFollowers(c *fiber.Ctx) error { return app.queryFullUsers(c, sql, pgx.NamedArgs{ "userId": userId, - }) + }, minResponse) } -func (app *ApiServer) v1UsersFollowing(c *fiber.Ctx) error { +func (app *ApiServer) v1UsersFollowing(c *fiber.Ctx, minResponse bool) error { sql := ` SELECT followee_user_id @@ -78,10 +85,10 @@ func (app *ApiServer) v1UsersFollowing(c *fiber.Ctx) error { return app.queryFullUsers(c, sql, pgx.NamedArgs{ "userId": userId, - }) + }, minResponse) } -func (app *ApiServer) v1UsersMutuals(c *fiber.Ctx) error { +func (app *ApiServer) v1UsersMutuals(c *fiber.Ctx, minResponse bool) error { myId, _ := trashid.DecodeHashId(c.Query("user_id")) sql := ` @@ -107,10 +114,10 @@ func (app *ApiServer) v1UsersMutuals(c *fiber.Ctx) error { return app.queryFullUsers(c, sql, pgx.NamedArgs{ "myId": myId, "userId": userId, - }) + }, minResponse) } -func (app *ApiServer) v1UsersSupporting(c *fiber.Ctx) error { +func (app *ApiServer) v1UsersSupporting(c *fiber.Ctx, minResponse bool) error { myId, _ := trashid.DecodeHashId(c.Query("user_id")) userId, err := trashid.DecodeHashId(c.Params("userId")) @@ -185,13 +192,32 @@ func (app *ApiServer) v1UsersSupporting(c *fiber.Ctx) error { supported[idx] = s } + if minResponse { + // Create a new array with MinUsers + type minSupportedUser struct { + supportedUser + Receiver dbv1.MinUser `json:"receiver"` + } + + minSupported := make([]minSupportedUser, len(supported)) + for i, user := range supported { + minSupported[i] = minSupportedUser{ + supportedUser: user, + Receiver: dbv1.ToMinUser(user.Receiver), + } + } + + return c.JSON(fiber.Map{ + "data": minSupported, + }) + } + return c.JSON(fiber.Map{ "data": supported, }) - } -func (app *ApiServer) queryFullUsers(c *fiber.Ctx, sql string, args pgx.NamedArgs) error { +func (app *ApiServer) queryFullUsers(c *fiber.Ctx, sql string, args pgx.NamedArgs, minResponse bool) error { myId, _ := trashid.DecodeHashId(c.Query("user_id")) args["limit"] = c.Query("limit", "20") @@ -224,6 +250,12 @@ func (app *ApiServer) queryFullUsers(c *fiber.Ctx, sql string, args pgx.NamedArg users[idx] = userMap[id] } + if minResponse { + return c.JSON(fiber.Map{ + "data": dbv1.ToMinUsers(users), + }) + } + return c.JSON(fiber.Map{ "data": users, }) diff --git a/apidiff.ts b/apidiff.ts index cf010af0..0821be3c 100644 --- a/apidiff.ts +++ b/apidiff.ts @@ -52,16 +52,37 @@ const testPaths = [ // "/v1/full/tracks/0dgQM/favorites?limit=15&offset=0&user_id=aNzoj", // "/v1/full/users/PWgX8NR/followers?limit=15&offset=0&user_id=aNzoj", - // "/v1/full/users/PWgX8NR/following?limit=15&offset=0&user_id=aNzoj" + // "/v1/full/users/PWgX8NR/following?limit=15&offset=0&user_id=aNzoj", // "/v1/full/users/PWgX8NR/mutuals?limit=5&offset=0&user_id=aNzoj", // "/v1/full/users/7KVbP/supporting?limit=100&offset=0&user_id=aNzoj", // "/v1/full/users/7KVbP/supporters?limit=100&offset=0&user_id=aNzoj", - // "/v1/full/playlists/P5abMZp/reposts?limit=15&offset=0&user_id=aNzoj", - // "/v1/full/playlists/P5abMZp/favorites?limit=15&offset=0&user_id=aNzoj", + "/v1/full/playlists/P5abMZp/reposts?limit=15&offset=0&user_id=aNzoj", + "/v1/full/playlists/P5abMZp/favorites?limit=15&offset=0&user_id=aNzoj", - "/v1/developer_apps/7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6" + // "/v1/users?id=0EoAm&user_id=aNzoj", + // "/v1/users?id=0EoAm&id=7eP5n&id=aWvp71&id=Wem1e&user_id=aNzoj", + + // "/v1/tracks?id=ZaXp01y&user_id=aNzoj", + // "/v1/tracks?id=ZaXp01y&id=5zdbywJ&id=Pb4MbAX&id=YVog04p&id=7Mv7ZMP&id=g5yzMy2&id=P7dlqNR&id=RR7krAG&id=O7OdxYV&id=72oXyvr&id=jYWyGG0&id=W6KOm8k&id=Xj554dq&id=gbOmq7k&id=G0z4Ap7&id=Yo0XYMm&id=80jlRwP&id=X63z9Wq&id=lZYWRKb&id=JEz6V0o&id=JZq6550&id=b9rbNdM&id=yy71xr7&id=JGNob5Z&id=VpxQ2Aa&id=qGbEZdz&id=B94qO0j&id=oRGgBka&id=jzwlVj0&id=Y5PNmOr&id=5zRm7dx&id=r3KjOg&id=WVP8qav&id=Nvayj1Y&id=V6GZJ3b&id=YoWO0MJ&id=JboVK8Y&id=9bbRG02&id=QRgjAJR&id=gWaBbkW&id=79q1xY7&id=51o1r9J&id=AMJ7d3k&id=O6ZKK0V&id=RpVzBx1&id=VPdaGdQ&id=lv7Obol&id=GQpBNxw&id=83xb96v&id=BJoM2Qx&id=bQoMKlK&id=8E1QjMW&id=O5OVlK4&id=63Gz0yQ&user_id=aNzoj", + + // "/v1/playlists?id=K99x4MB&id=Akkz9wv&id=kKdggMN&id=k2J9Na3&id=NVr4gVN&id=1E87V7Q&user_id=aNzoj", + + // "/v1/tracks/OvyMAV1/reposts?limit=15&offset=0&user_id=aNzoj", + // "/v1/tracks/0dgQM/favorites?limit=15&offset=0&user_id=aNzoj", + + // "/v1/users/PWgX8NR/followers?limit=15&offset=0&user_id=aNzoj", + // "/v1/users/PWgX8NR/following?limit=15&offset=0&user_id=aNzoj", + // "/v1/users/PWgX8NR/mutuals?limit=5&offset=0&user_id=aNzoj", + + // "/v1/users/7KVbP/supporting?limit=100&offset=0&user_id=aNzoj", + // "/v1/users/7KVbP/supporters?limit=100&offset=0&user_id=aNzoj", + + // "/v1/playlists/P5abMZp/reposts?limit=15&offset=0&user_id=aNzoj", + // "/v1/playlists/P5abMZp/favorites?limit=15&offset=0&user_id=aNzoj", + + // "/v1/developer_apps/7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6" ]; for (const path of testPaths) { diff --git a/utils/ptr.go b/utils/ptr.go new file mode 100644 index 00000000..d23483fa --- /dev/null +++ b/utils/ptr.go @@ -0,0 +1,8 @@ +package utils + +func String(s *string) string { + if s == nil { + return "" + } + return *s +}