Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-freeform-genre-adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@audius/common': patch
---

Fix freeform/custom track genres silently reverting to Electronic on save. `toSdkGenre` in the track adapter filtered out any value not in the canonical `Genre` enum and returned `undefined`, which then fell back to `DEFAULT_GENRE` (Electronic) before reaching the SDK. Now any non-empty genre string is passed through unchanged (the SDK upload schema already caps it at 100 chars), so custom genres entered by artists are preserved end-to-end.
22 changes: 22 additions & 0 deletions packages/common/src/adapters/track.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,26 @@ describe('trackMetadataForUploadToSdk', () => {

expect(result.allowedApiKeys).toBeNull()
})

it('passes a freeform/custom genre through to the SDK unchanged', () => {
const result = trackMetadataForUploadToSdk(
makeMetadata({ genre: 'Ambient Drone' })
)

expect(result.genre).toBe('Ambient Drone')
})

it('preserves a canonical genre', () => {
const result = trackMetadataForUploadToSdk(
makeMetadata({ genre: Genre.HipHopRap })
)

expect(result.genre).toBe(Genre.HipHopRap)
})

it('falls back to Electronic only when genre is empty', () => {
const result = trackMetadataForUploadToSdk(makeMetadata({ genre: '' }))

expect(result.genre).toBe(Genre.Electronic)
})
})
17 changes: 10 additions & 7 deletions packages/common/src/adapters/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ import { repostFromSDK } from './repost'
import { userMetadataFromSDK } from './user'
import { transformAndCleanList } from './utils'

const VALID_GENRES = new Set<string>(Object.values(Genre))
const VALID_MOODS = new Set<string>(Object.values(Mood))

function toSdkGenre(
value: string | undefined | ''
): (typeof Genre)[keyof typeof Genre] | undefined {
/**
* Pass through any non-empty genre string to the SDK. Canonical Genre enum
* values are returned as-is; freeform strings are also passed through
* unchanged so artists can enter custom genres (the SDK upload schema caps
* them at 100 chars). Previously this filtered out any value not in the
* canonical Genre enum, which caused custom genres to silently fall back to
* Electronic.
*/
function toSdkGenre(value: string | undefined | ''): string | undefined {
if (value === undefined || value === '') return undefined
return VALID_GENRES.has(value)
? (value as (typeof Genre)[keyof typeof Genre])
: undefined
return value
}

function toSdkMood(
Expand Down
Loading