-
Notifications
You must be signed in to change notification settings - Fork 126
Tus uploads for stems #13577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tus uploads for stems #13577
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| 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, | ||
|
|
@@ -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' | ||
|
|
@@ -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 ( | ||
|
|
@@ -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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
| metadata: { | ||
| filename: file.name, | ||
| filetype: file.type, | ||
|
|
@@ -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)}` | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank god