Skip to content

Commit d864806

Browse files
rickyromboCopilot
andauthored
Replace getPlaylistByHandleAndSlug (#13795)
Regenerates the SDK following AudiusProject/api#678 and AudiusProject/api#677 - Removes `getPlaylistByHandleAndSlug` in favor of calling `getBulkPlaylists` with permalink arg - Updates return values of CommentsAPI to match other writes - Updates embed player and client to use `getBulkPlaylists` - Updates API and SDK docs --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 21b78c9 commit d864806

16 files changed

Lines changed: 201 additions & 221 deletions

File tree

.changeset/four-peas-impress.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@audius/sdk': major
3+
---
4+
5+
Remove getPlaylistByHandleAndSlug in favor of getBulkPlaylists
6+
7+
- Removes `sdk.playlists.getPlaylistByHandleAndSlug()` in favor of calling `sdk.playlists.getBulkPlaylists({ permalink: ['/handle/playlist/playlist-name-slug'] })`
8+
- Changes return values of `CommentsAPI` to match other APIs, removing `success` param.

docs/docs/developers/api/sidebar.generated.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,6 @@ const sidebar = {
513513
label: "Create Playlist",
514514
className: "api-method post",
515515
},
516-
{
517-
type: "doc",
518-
id: "developers/api/get-playlist-by-handle-and-slug",
519-
label: "Get Playlist By Handle and Slug",
520-
className: "api-method get",
521-
},
522516
{
523517
type: "doc",
524518
id: "developers/api/search-playlists",

docs/docs/developers/api/sidebar.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,6 @@ const sidebar: SidebarsConfig = {
514514
label: "Create Playlist",
515515
className: "api-method post",
516516
},
517-
{
518-
type: "doc",
519-
id: "developers/api/get-playlist-by-handle-and-slug",
520-
label: "Get Playlist By Handle and Slug",
521-
className: "api-method get",
522-
},
523517
{
524518
type: "doc",
525519
id: "developers/api/search-playlists",

docs/docs/developers/openapi.yaml

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ paths:
10841084
get:
10851085
tags:
10861086
- playlists
1087-
description: Gets a list of playlists by ID
1087+
description: Gets a list of playlists by ID, UPC, or permalink
10881088
operationId: Get Bulk Playlists
10891089
parameters:
10901090
- name: user_id
@@ -1101,6 +1101,15 @@ paths:
11011101
type: array
11021102
items:
11031103
type: string
1104+
- name: permalink
1105+
in: query
1106+
description: The permalink(s) of the playlist(s)
1107+
style: form
1108+
explode: true
1109+
schema:
1110+
type: array
1111+
items:
1112+
type: string
11041113
- name: upc
11051114
in: query
11061115
description: The UPC of the playlist(s)
@@ -1161,37 +1170,6 @@ paths:
11611170
'500':
11621171
description: Server error
11631172
content: {}
1164-
/playlists/by_permalink/{handle}/{slug}:
1165-
get:
1166-
tags:
1167-
- playlists
1168-
description: Get a playlist by handle and slug
1169-
operationId: Get Playlist By Handle and Slug
1170-
parameters:
1171-
- name: handle
1172-
in: path
1173-
description: playlist owner handle
1174-
required: true
1175-
schema:
1176-
type: string
1177-
- name: slug
1178-
in: path
1179-
description: playlist slug
1180-
required: true
1181-
schema:
1182-
type: string
1183-
- name: user_id
1184-
in: query
1185-
description: The user ID of the user making the request
1186-
schema:
1187-
type: string
1188-
responses:
1189-
'200':
1190-
description: Success
1191-
content:
1192-
application/json:
1193-
schema:
1194-
$ref: '#/components/schemas/playlist_response'
11951173
/playlists/search:
11961174
get:
11971175
tags:
@@ -10415,12 +10393,16 @@ components:
1041510393
create_user_response:
1041610394
type: object
1041710395
properties:
10418-
success:
10419-
type: boolean
10420-
description: Whether the user was created successfully
1042110396
transaction_hash:
1042210397
type: string
1042310398
description: The blockchain transaction hash
10399+
block_hash:
10400+
type: string
10401+
description: The blockchain block hash
10402+
block_number:
10403+
type: integer
10404+
format: int64
10405+
description: The blockchain block number/height
1042410406
user_id:
1042510407
type: string
1042610408
description: The ID of the created user
@@ -10595,12 +10577,16 @@ components:
1059510577
create_comment_response:
1059610578
type: object
1059710579
properties:
10598-
success:
10599-
type: boolean
10600-
description: Whether the comment was created successfully
1060110580
transaction_hash:
1060210581
type: string
1060310582
description: The blockchain transaction hash
10583+
block_hash:
10584+
type: string
10585+
description: The blockchain block hash
10586+
block_number:
10587+
type: integer
10588+
format: int64
10589+
description: The blockchain block number/height
1060410590
comment_id:
1060510591
type: string
1060610592
description: The ID of the created comment
@@ -10644,12 +10630,16 @@ components:
1064410630
write_response:
1064510631
type: object
1064610632
properties:
10647-
success:
10648-
type: boolean
10649-
description: Whether the operation was successful
1065010633
transaction_hash:
1065110634
type: string
1065210635
description: The blockchain transaction hash
10636+
block_hash:
10637+
type: string
10638+
description: The blockchain block hash
10639+
block_number:
10640+
type: integer
10641+
format: int64
10642+
description: The blockchain block number/height
1065310643
playlist_artwork:
1065410644
type: object
1065510645
properties:
@@ -11116,6 +11106,13 @@ components:
1111611106
transaction_hash:
1111711107
type: string
1111811108
description: Transaction hash of the creation
11109+
block_hash:
11110+
type: string
11111+
description: The blockchain block hash
11112+
block_number:
11113+
type: integer
11114+
format: int64
11115+
description: The blockchain block number/height
1111911116
playlist_response:
1112011117
required:
1112111118
- latest_chain_block
@@ -12203,12 +12200,16 @@ components:
1220312200
create_playlist_response:
1220412201
type: object
1220512202
properties:
12206-
success:
12207-
type: boolean
12208-
description: Whether the playlist was created successfully
1220912203
transaction_hash:
1221012204
type: string
1221112205
description: The blockchain transaction hash
12206+
block_hash:
12207+
type: string
12208+
description: The blockchain block hash
12209+
block_number:
12210+
type: integer
12211+
format: int64
12212+
description: The blockchain block number/height
1221212213
playlist_id:
1221312214
type: string
1221412215
description: The ID of the created playlist
@@ -13074,12 +13075,16 @@ components:
1307413075
create_track_response:
1307513076
type: object
1307613077
properties:
13077-
success:
13078-
type: boolean
13079-
description: Whether the track was created successfully
1308013078
transaction_hash:
1308113079
type: string
1308213080
description: The blockchain transaction hash
13081+
block_hash:
13082+
type: string
13083+
description: The blockchain block hash
13084+
block_number:
13085+
type: integer
13086+
format: int64
13087+
description: The blockchain block number/height
1308313088
track_id:
1308413089
type: string
1308513090
description: The ID of the created track

docs/docs/developers/sdk/playlists.mdx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Returns a `Promise` containing an object with a `data` field. `data` contains a
4444

4545
> #### getBulkPlaylists(`params`)
4646
47-
Get a list of playlists by id.
47+
Get a list of playlists by ID, UPC, or permalink.
4848

4949
Example:
5050

@@ -61,11 +61,12 @@ console.log(playlists)
6161
Create an object with the following fields and pass it as the first argument, as shown in the
6262
example above.
6363

64-
| Name | Type | Description | Required? |
65-
| :------- | :--------- | :------------------------------------ | :--------- |
66-
| `id` | `string[]` | An array of playlist IDs | _Optional_ |
67-
| `upc` | `string[]` | An array of UPC codes | _Optional_ |
68-
| `userId` | `string` | The ID of the user making the request | _Optional_ |
64+
| Name | Type | Description | Required? |
65+
| :---------- | :--------- | :------------------------------------ | :--------- |
66+
| `id` | `string[]` | An array of playlist IDs | _Optional_ |
67+
| `permalink` | `string[]` | An array of permalinks of playlists | _Optional_ |
68+
| `upc` | `string[]` | An array of UPC codes | _Optional_ |
69+
| `userId` | `string` | The ID of the user making the request | _Optional_ |
6970

7071
#### Returns
7172

packages/common/src/api/tan-query/collection/useCollectionByPermalink.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,14 @@ export const getCollectionByPermalinkQueryKey = (
2424
] as unknown as QueryKey<ID>
2525
}
2626

27-
export const playlistPermalinkToHandleAndSlug = (permalink: string) => {
28-
const splitPermalink = permalink.split('/')
29-
if (splitPermalink.length !== 4) {
30-
throw Error(
31-
'Permalink formatted incorrectly. Should follow /<handle>/playlist/<slug> format.'
32-
)
33-
}
34-
const handle = splitPermalink[1]
35-
const slug = splitPermalink[3]
36-
return { handle, slug }
37-
}
38-
3927
export const getCollectionByPermalinkQueryFn = async (
4028
permalink: string,
4129
currentUserId: number | null | undefined,
4230
queryClient: QueryClient,
4331
sdk: any
4432
) => {
45-
const { handle, slug } = playlistPermalinkToHandleAndSlug(permalink)
46-
const { data = [] } = await sdk.playlists.getPlaylistByHandleAndSlug({
47-
handle,
48-
slug,
33+
const { data = [] } = await sdk.playlists.getBulkPlaylists({
34+
permalink: [permalink],
4935
userId: OptionalId.parse(currentUserId)
5036
})
5137

packages/embed/src/components/app.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ const DEFAULT_DOMINANT_COLOR = '#7e1bcc'
4848

4949
const RequestType = Object.seal({
5050
TRACK: 'track',
51-
COLLECTION: 'collection'
51+
ALBUM: 'album',
52+
PLAYLIST: 'playlist'
5253
})
5354

5455
const pathComponentRequestTypeMap = {
55-
playlist: RequestType.COLLECTION,
56-
album: RequestType.COLLECTION,
56+
playlist: RequestType.PLAYLIST,
57+
album: RequestType.ALBUM,
5758
track: RequestType.TRACK
5859
}
5960

@@ -214,12 +215,16 @@ const App = (props) => {
214215

215216
setDominantColor({ primary: color })
216217
}
217-
} else if (requestType === RequestType.COLLECTION) {
218+
} else if (
219+
requestType === RequestType.ALBUM ||
220+
requestType === RequestType.PLAYLIST
221+
) {
218222
let collection
219223
if (request.handle && request.slug) {
220224
collection = await getCollectionByPermalink(
221225
request.handle,
222-
request.slug
226+
request.slug,
227+
requestType
223228
)
224229
} else if (request.hashId) {
225230
collection = await getCollectionWithHashId(request.hashId)

packages/embed/src/util/BedtimeClient.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ export const getCollectionWithHashId = async (hashId) => {
107107
return getFormattedCollectionResponse(res.data)
108108
}
109109

110-
export const getCollectionByPermalink = async (handle, slug) => {
111-
const res = await audiusSdk.playlists.getPlaylistByHandleAndSlug({
112-
handle,
113-
slug
110+
export const getCollectionByPermalink = async (handle, slug, type) => {
111+
const permalink = `/${handle}/${type}/${slug}`
112+
const res = await audiusSdk.playlists.getBulkPlaylists({
113+
permalink: [permalink]
114114
})
115115
return getFormattedCollectionResponse(res.data)
116116
}

0 commit comments

Comments
 (0)