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
831 changes: 259 additions & 572 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@
},
"resolutions": {
"@babel/core": "7.25.2",
"cipher-base": "1.0.7",
"tslib": "^2.6.0"
"cipher-base": "1.0.7"
},
"overrides": {
"@types/prop-types": "15.7.5",
Expand All @@ -148,8 +147,7 @@
"react-native-svg": "15.11.1",
"redux": "4.1.1",
"webpack": "5.88.2",
"elliptic": "6.6.1",
"tslib": "^2.6.0"
"elliptic": "6.6.1"
},
"packageManager": "npm@9.6.7"
}
3 changes: 1 addition & 2 deletions packages/common/src/adapters/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ export const trackMetadataForUploadToSdk = (
'is_custom_musical_key',
'comments_disabled',
'ddex_release_ids',
'parental_warning_type',
'cover_art_sizes'
'parental_warning_type'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank god

])
),
trackId: OptionalId.parse(input.track_id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ type PublishCollectionParams = {
tracks: {
clientId: string
metadata: TrackMetadataForUpload
onProgress: (clientId: string, progress: Progress) => void
onProgress: (
clientId: string,
stemIndex: number | null,
progress: Progress
) => void
}[]
}

Expand Down
58 changes: 48 additions & 10 deletions packages/common/src/api/tan-query/upload/usePublishTracks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { USDC } from '@audius/fixed-decimal'
import { HashId, Id } from '@audius/sdk'
import { HashId, Id, type UploadResponse } from '@audius/sdk'
import {
mutationOptions,
useMutation,
Expand All @@ -10,6 +10,8 @@ import { useDispatch } from 'react-redux'
import { trackMetadataForUploadToSdk } from '~/adapters'
import {
isContentUSDCPurchaseGated,
StemCategory,
type StemUploadPending,
type USDCPurchaseConditions
} from '~/models'
import { ProgressStatus } from '~/store'
Expand All @@ -30,7 +32,13 @@ type PublishTracksContext = Pick<QueryContextType, 'audiusSdk'> & {
type PublishTracksParams = {
clientId: string
metadata: TrackMetadataForUpload
onProgress: (clientId: string, progress: Progress) => void
audioUploadResponse: UploadResponse
artUploadResponse: UploadResponse
onProgress: (
clientId: string,
stemIndex: number | null,
progress: Progress
) => void
}[]

export const publishTracks = async (
Expand All @@ -49,19 +57,49 @@ export const publishTracks = async (
return await Promise.all(
params.map(async (param) => {
try {
const metadata = trackMetadataForUploadToSdk(
addPremiumMetadata(userBank.toString(), param.metadata)
const snakeMetadata = addPremiumMetadata(
userBank.toString(),
param.metadata
)
const res = await sdk.tracks.writeTrackToChain(
Id.parse(userId),
metadata
)
param.onProgress(param.clientId, {
const camelMetadata = trackMetadataForUploadToSdk(snakeMetadata)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐫🐫🐫
🐫🐍🐫
🐫🐫🐫

const res = await sdk.tracks.publishTrack({
userId: Id.parse(userId),
metadata: camelMetadata,
audioUploadResponse: param.audioUploadResponse,
artUploadResponse: param.artUploadResponse
})
param.onProgress(param.clientId, null, {
status: ProgressStatus.COMPLETE
})

await Promise.all(
(param.metadata.stems ?? []).map(async (s, index) => {
const stem = s as StemUploadPending
const metadata = {
...snakeMetadata,
...stem.metadata,
is_downloadable: true,
stem_of: {
category: stem.category ?? StemCategory.OTHER,
parent_track_id: HashId.parse(res.trackId)
}
}
const stemRes = await sdk.tracks.publishTrack({
userId: Id.parse(userId),
metadata: trackMetadataForUploadToSdk(metadata),
audioUploadResponse: stem.audioUploadResponse,
artUploadResponse: param.artUploadResponse
})
param.onProgress(param.clientId, index, {
status: ProgressStatus.COMPLETE
})
return stemRes
})
)

return { clientId: param.clientId, trackId: res.trackId }
} catch (e) {
param.onProgress(param.clientId, {
param.onProgress(param.clientId, null, {
status: ProgressStatus.ERROR
})
console.error('Error publishing track:', e)
Expand Down
6 changes: 6 additions & 0 deletions packages/common/src/models/Stems.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { UploadResponse } from '@audius/sdk'

import { TrackMetadataForUpload } from '~/store'
import { Nullable } from '~/utils'

Expand Down Expand Up @@ -41,3 +43,7 @@ export type StemUpload = {
export type StemUploadWithFile = StemUpload & {
file: File
}

export type StemUploadPending = StemUpload & {
audioUploadResponse: UploadResponse
}
17 changes: 17 additions & 0 deletions packages/common/src/store/upload/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ const actionsMap = {
const trackIndex = newState.uploadProgress.findIndex(
(p) => p && p.clientId === clientId
)

if (
stemIndex !== null &&
newState.uploadProgress[trackIndex] &&
!newState.uploadProgress[trackIndex]?.stems[stemIndex]
) {
newState.uploadProgress[trackIndex].stems[stemIndex] = {
...cloneDeep(initialUploadState),
art: {
status: ProgressStatus.COMPLETE,
loaded: 0,
total: 0,
transcode: 0
}
}
}

const prevProgress =
stemIndex === null
? newState.uploadProgress[trackIndex]?.[key]
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/store/upload/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { NativeFile } from '@audius/sdk'
import { CollectionValues } from '~/schemas'

import {
CollectionMetadata,
StemUpload,
StemUploadWithFile,
TrackMetadata
TrackMetadata,
type StemUploadPending
} from '../../models'
import { Nullable } from '../../utils/typeUtils'

Expand Down Expand Up @@ -54,7 +54,7 @@ export interface TrackMetadataForUpload
source?: string
}>
| TrackMetadata['artwork']
stems?: (StemUploadWithFile | StemUpload)[]
stems?: (StemUploadWithFile | StemUpload | StemUploadPending)[]
/** During Upload, tracks will typically not have a track_id, but it might
* be assigned ahead of time for tracks with stems.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/sdk/api/tracks/TrackUploadHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class TrackUploadHelper extends BaseAPI {
origFilename: audioResponse.orig_filename || trackMetadata.origFilename,
audioUploadId: audioResponse.id,
coverArtSizes: coverArtResponse?.id,
duration: parseInt(audioResponse.probe.format.duration, 10),
duration: parseInt(audioResponse?.probe?.format?.duration ?? '0', 10),
bpm: audioResponse.audio_analysis_results?.bpm
? audioResponse.audio_analysis_results.bpm
: trackMetadata.bpm,
Expand Down
30 changes: 29 additions & 1 deletion packages/sdk/src/sdk/api/tracks/TracksApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ import {
UpdateTrackSchema,
UploadTrackFilesSchema,
ShareTrackSchema,
ShareTrackRequest
ShareTrackRequest,
type PublishTrackRequest,
PublishTrackSchema
} from './types'

// Extend that new class
Expand Down Expand Up @@ -206,6 +208,32 @@ export class TracksApi extends GeneratedTracksApi {
)
}

/** @hidden
* Publishes a track that was uploaded using storage node uploadFileV2 uploads.
*/
async publishTrack(params: PublishTrackRequest) {
const {
userId,
metadata: parsedMetadata,
audioUploadResponse,
artUploadResponse
} = await parseParams('publishTrack', PublishTrackSchema)(params)

const metadata = this.trackUploadHelper.transformTrackUploadMetadata(
parsedMetadata,
userId
)

const populatedMetadata =
this.trackUploadHelper.populateTrackMetadataWithUploadResponse(
metadata,
audioUploadResponse,
artUploadResponse
)

return this.writeTrackToChain(params.userId, populatedMetadata)
}

/** @hidden
* Write track upload to chain
*/
Expand Down
49 changes: 49 additions & 0 deletions packages/sdk/src/sdk/api/tracks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,52 @@ export const PurchaseTrackSchema = z
.strict()

export type PurchaseTrackRequest = z.input<typeof PurchaseTrackSchema>

const UploadResponseSchema = z.object({
id: z.string(),
status: z.enum([
'new',
'error',
'busy',
'timeout',
'audio_analysis',
'busy_audio_analysis',
'done'
]),
orig_file_cid: z.string(),
orig_filename: z.string(),
results: z.record(z.string(), z.string()),
probe: z
.object({
format: z
.object({
duration: z.string().optional()
})
.optional()
})
.optional(),
audio_analysis_results: z
.object({
bpm: z.number().optional(),
key: z.string().optional()
})
.optional()
.nullable(),
audio_analysis_error_count: z.number()
})

export type UploadResponse = z.input<typeof UploadResponseSchema>

export const PublishTrackSchema = z
.object({
userId: HashId,
metadata: UploadTrackMetadataSchema.extend({
genre: z.optional(z.enum(Object.values(Genre) as [Genre, ...Genre[]]))
}).strict(),
audioUploadResponse: UploadResponseSchema,
artUploadResponse: UploadResponseSchema,
stemsUploadResponses: z.array(UploadResponseSchema).optional()
})
.strict()

export type PublishTrackRequest = z.input<typeof PublishTrackSchema>
7 changes: 3 additions & 4 deletions packages/sdk/src/sdk/services/Storage/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ export class Storage implements StorageService {
const upload = new tus.Upload(file, {
endpoint: `${selectedNode}/files/`,
retryDelays: [0, 3000, 5000, 10000, 20000],
chunkSize: 100_000_000, // 100MB
removeFingerprintOnSuccess: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

metadata: {
filename: file.name,
filetype: file.type,
Expand Down Expand Up @@ -277,10 +279,7 @@ export class Storage implements StorageService {
if (resp?.status === 'done') {
return resp
}
if (
resp?.status === 'error' ||
resp?.status === 'error_retranscode_preview'
) {
if (resp?.status === 'error') {
throw new Error(
`Upload failed: id=${id}, resp=${JSON.stringify(resp)}`
)
Expand Down
20 changes: 10 additions & 10 deletions packages/sdk/src/sdk/services/Storage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ export type StorageService = {

export type ProcessingStatus =
| 'new'
| 'busy'
| 'done'
| 'error'
| 'retranscode_preview'
| 'busy_retranscode_preview'
| 'error_retranscode_preview'
| 'busy'
| 'timeout'
| 'audio_analysis'
| 'busy_audio_analysis'
| 'done'

export type UploadResponse = {
id: string
Expand All @@ -87,11 +86,12 @@ export type UploadResponse = {
orig_filename: string
audio_analysis_error_count: number
audio_analysis_results?: {
[key: string]: string
}
probe: {
format: {
duration: string
bpm?: number
key?: string
} | null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why nullable too instead of just undef?

probe?: {
format?: {
duration?: string
}
}
transcode_progress?: number
Expand Down
Loading
Loading