@audius/sdk 2.0.3-beta.4 → 2.0.3-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +127 -71
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +127 -71
- package/dist/index.esm.js.map +1 -1
- package/dist/legacy.js +127 -71
- package/dist/legacy.js.map +1 -1
- package/dist/native-libs.js +127 -71
- package/dist/native-libs.js.map +1 -1
- package/dist/services/creatorNode/CreatorNode.d.ts +3 -3
- package/dist/services/discoveryProvider/DiscoveryProvider.d.ts +2 -1
- package/package.json +2 -2
- package/src/api/Track.ts +7 -6
- package/src/services/creatorNode/CreatorNode.ts +43 -28
- package/src/services/dataContracts/AudiusContracts.ts +1 -1
- package/src/services/discoveryProvider/DiscoveryProvider.ts +14 -2
- package/src/utils/fileHasher.ts +2 -2
- package/src/api/Users.test.js +0 -3
|
@@ -272,9 +272,9 @@ export declare class CreatorNode {
|
|
|
272
272
|
*/
|
|
273
273
|
syncSecondary(secondary: string, primary?: string, immediate?: boolean, validate?: boolean): Promise<import("axios").AxiosResponse<any> | undefined>;
|
|
274
274
|
/**
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
275
|
+
* Makes an axios request to the connected creator node
|
|
276
|
+
* @return response body
|
|
277
|
+
*/
|
|
278
278
|
_makeRequestV2(axiosRequestObj: AxiosRequestConfig): Promise<import("axios").AxiosResponse<any>>;
|
|
279
279
|
/**
|
|
280
280
|
* Signs up a creator node user with a wallet address
|
|
@@ -93,6 +93,7 @@ export declare class DiscoveryProvider {
|
|
|
93
93
|
isInitialized: boolean;
|
|
94
94
|
discoveryNodeSelector?: DiscoveryNodeSelector;
|
|
95
95
|
discoveryNodeMiddleware?: Middleware;
|
|
96
|
+
selectionCallback?: DiscoveryProviderSelectionConfig['selectionCallback'];
|
|
96
97
|
constructor({ whitelist, blacklist, userStateManager, ethContracts, web3Manager, reselectTimeout, selectionCallback, monitoringCallbacks, selectionRequestTimeout, selectionRequestRetries, localStorage, unhealthySlotDiffPlays, unhealthyBlockDiff, discoveryNodeSelector }: DiscoveryProviderConfig);
|
|
97
98
|
init(): Promise<void>;
|
|
98
99
|
setEndpoint(endpoint: string): void;
|
|
@@ -541,7 +542,7 @@ export declare class DiscoveryProvider {
|
|
|
541
542
|
latest_chain_slot_plays: number;
|
|
542
543
|
data: Response;
|
|
543
544
|
} | undefined | null>;
|
|
544
|
-
_makeRequestInternalNext<Response>(requestObj: Record<string, unknown>, throwError?: boolean): Promise<DiscoveryResponse<Response> | null | undefined>;
|
|
545
|
+
_makeRequestInternalNext<Response>(requestObj: Record<string, unknown>, throwError?: boolean, blockNumber?: number): Promise<DiscoveryResponse<Response> | null | undefined>;
|
|
545
546
|
/**
|
|
546
547
|
* Gets the healthy discovery provider endpoint used in creating the axios request later.
|
|
547
548
|
* If the number of retries is over the max count for retires, clear the cache and reselect
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audius/sdk",
|
|
3
|
-
"version": "2.0.3-beta.
|
|
3
|
+
"version": "2.0.3-beta.5",
|
|
4
4
|
"audius": {
|
|
5
|
-
"releaseSHA": "
|
|
5
|
+
"releaseSHA": "29b38fb1a75d58b32ce4c98a46dc035540b43e1a"
|
|
6
6
|
},
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "dist/index.cjs.js",
|
package/src/api/Track.ts
CHANGED
|
@@ -409,12 +409,13 @@ export class Track extends Base {
|
|
|
409
409
|
this._validateTrackMetadata(metadata)
|
|
410
410
|
|
|
411
411
|
// Upload track audio and cover art to storage node
|
|
412
|
-
const updatedMetadata =
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
412
|
+
const updatedMetadata =
|
|
413
|
+
await this.creatorNode.uploadTrackAudioAndCoverArtV2(
|
|
414
|
+
trackFile,
|
|
415
|
+
coverArtFile,
|
|
416
|
+
metadata,
|
|
417
|
+
onProgress
|
|
418
|
+
)
|
|
418
419
|
|
|
419
420
|
// Write metadata to chain
|
|
420
421
|
const trackId = await this._generateTrackId()
|
|
@@ -397,20 +397,30 @@ export class CreatorNode {
|
|
|
397
397
|
trackFile: File,
|
|
398
398
|
coverArtFile: File,
|
|
399
399
|
metadata: TrackMetadata,
|
|
400
|
-
onProgress: ProgressCB = () => {
|
|
400
|
+
onProgress: ProgressCB = () => {}
|
|
401
401
|
) {
|
|
402
402
|
const updatedMetadata = { ...metadata }
|
|
403
403
|
|
|
404
404
|
// Upload audio and cover art
|
|
405
405
|
const [audioResp, coverArtResp] = await Promise.all([
|
|
406
|
-
this._retry3(
|
|
407
|
-
|
|
406
|
+
this._retry3(
|
|
407
|
+
async () => await this.uploadTrackAudioV2(trackFile, onProgress),
|
|
408
|
+
(e) => {
|
|
409
|
+
console.log('Retrying uploadTrackAudioV2', e)
|
|
410
|
+
}
|
|
411
|
+
),
|
|
412
|
+
this._retry3(
|
|
413
|
+
async () => await this.uploadTrackCoverArtV2(coverArtFile, onProgress),
|
|
414
|
+
(e) => {
|
|
415
|
+
console.log('Retrying uploadTrackCoverArtV2', e)
|
|
416
|
+
}
|
|
417
|
+
)
|
|
408
418
|
])
|
|
409
419
|
|
|
410
420
|
// Update metadata to include uploaded CIDs
|
|
411
421
|
// TODO: Make sure discovery and elsewhere accept 0-length array. Some checks in CN currently fail if there's not at least 1 valid segment
|
|
412
422
|
updatedMetadata.track_segments = []
|
|
413
|
-
updatedMetadata.track_cid = audioResp.results[
|
|
423
|
+
updatedMetadata.track_cid = audioResp.results['320']
|
|
414
424
|
if (updatedMetadata.download?.is_downloadable) {
|
|
415
425
|
updatedMetadata.download.cid = updatedMetadata.track_cid
|
|
416
426
|
}
|
|
@@ -420,14 +430,18 @@ export class CreatorNode {
|
|
|
420
430
|
}
|
|
421
431
|
|
|
422
432
|
async uploadTrackAudioV2(file: File, onProgress: ProgressCB) {
|
|
423
|
-
return this.uploadFileV2(file, onProgress, 'audio')
|
|
433
|
+
return await this.uploadFileV2(file, onProgress, 'audio')
|
|
424
434
|
}
|
|
425
435
|
|
|
426
436
|
async uploadTrackCoverArtV2(file: File, onProgress: ProgressCB) {
|
|
427
|
-
return this.uploadFileV2(file, onProgress, 'img_square')
|
|
437
|
+
return await this.uploadFileV2(file, onProgress, 'img_square')
|
|
428
438
|
}
|
|
429
439
|
|
|
430
|
-
async uploadFileV2(
|
|
440
|
+
async uploadFileV2(
|
|
441
|
+
file: File,
|
|
442
|
+
onProgress: ProgressCB,
|
|
443
|
+
template: 'audio' | 'img_square' | 'img_backdrop'
|
|
444
|
+
) {
|
|
431
445
|
const formData = new FormData()
|
|
432
446
|
formData.append('template', template)
|
|
433
447
|
formData.append('files', file, file.name)
|
|
@@ -436,11 +450,14 @@ export class CreatorNode {
|
|
|
436
450
|
url: '/mediorum/uploads',
|
|
437
451
|
data: formData,
|
|
438
452
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
439
|
-
onUploadProgress: (progressEvent) =>
|
|
453
|
+
onUploadProgress: (progressEvent) =>
|
|
454
|
+
onProgress(progressEvent.loaded, progressEvent.total)
|
|
440
455
|
})
|
|
441
|
-
return this.pollProcessingStatusV2(
|
|
456
|
+
return await this.pollProcessingStatusV2(
|
|
442
457
|
response.data[0].id,
|
|
443
|
-
template === 'audio'
|
|
458
|
+
template === 'audio'
|
|
459
|
+
? MAX_TRACK_TRANSCODE_TIMEOUT
|
|
460
|
+
: MAX_IMAGE_RESIZE_TIMEOUT_MS
|
|
444
461
|
)
|
|
445
462
|
}
|
|
446
463
|
|
|
@@ -457,7 +474,9 @@ export class CreatorNode {
|
|
|
457
474
|
const resp = await this.getProcessingStatusV2(id)
|
|
458
475
|
if (resp?.status === 'done') return resp
|
|
459
476
|
if (resp?.status === 'error') {
|
|
460
|
-
throw new Error(
|
|
477
|
+
throw new Error(
|
|
478
|
+
`Upload failed: id=${id}, resp=${JSON.stringify(resp)}`
|
|
479
|
+
)
|
|
461
480
|
}
|
|
462
481
|
} catch (e) {
|
|
463
482
|
// Swallow errors caused by failure to establish connection to node so we can retry polling
|
|
@@ -760,16 +779,14 @@ export class CreatorNode {
|
|
|
760
779
|
/* ------- INTERNAL FUNCTIONS ------- */
|
|
761
780
|
|
|
762
781
|
/**
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
async _makeRequestV2(
|
|
767
|
-
axiosRequestObj: AxiosRequestConfig
|
|
768
|
-
) {
|
|
782
|
+
* Makes an axios request to the connected creator node
|
|
783
|
+
* @return response body
|
|
784
|
+
*/
|
|
785
|
+
async _makeRequestV2(axiosRequestObj: AxiosRequestConfig) {
|
|
769
786
|
// TODO: This might want to have other error handling, request UUIDs, etc...
|
|
770
787
|
// But I didn't want to pull in all the chaos and incompatiblity of the old _makeRequest
|
|
771
788
|
axiosRequestObj.baseURL = this.creatorNodeEndpoint
|
|
772
|
-
return axios(axiosRequestObj)
|
|
789
|
+
return await axios(axiosRequestObj)
|
|
773
790
|
}
|
|
774
791
|
|
|
775
792
|
/**
|
|
@@ -1244,15 +1261,13 @@ export class CreatorNode {
|
|
|
1244
1261
|
/**
|
|
1245
1262
|
* Calls fn and then retries once after 500ms, again after 1500ms, and again after 4000ms
|
|
1246
1263
|
*/
|
|
1247
|
-
async _retry3(fn: () => Promise<any>, onRetry = (_err: any) => {
|
|
1248
|
-
return retry(fn,
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
}
|
|
1256
|
-
)
|
|
1264
|
+
async _retry3(fn: () => Promise<any>, onRetry = (_err: any) => {}) {
|
|
1265
|
+
return await retry(fn, {
|
|
1266
|
+
minTimeout: 500,
|
|
1267
|
+
maxTimeout: 4000,
|
|
1268
|
+
factor: 3,
|
|
1269
|
+
retries: 3,
|
|
1270
|
+
onRetry
|
|
1271
|
+
})
|
|
1257
1272
|
}
|
|
1258
1273
|
}
|
|
@@ -117,6 +117,7 @@ export class DiscoveryProvider {
|
|
|
117
117
|
isInitialized = false
|
|
118
118
|
discoveryNodeSelector?: DiscoveryNodeSelector
|
|
119
119
|
discoveryNodeMiddleware?: Middleware
|
|
120
|
+
selectionCallback?: DiscoveryProviderSelectionConfig['selectionCallback']
|
|
120
121
|
|
|
121
122
|
constructor({
|
|
122
123
|
whitelist,
|
|
@@ -139,6 +140,7 @@ export class DiscoveryProvider {
|
|
|
139
140
|
this.userStateManager = userStateManager
|
|
140
141
|
this.ethContracts = ethContracts
|
|
141
142
|
this.web3Manager = web3Manager
|
|
143
|
+
this.selectionCallback = selectionCallback
|
|
142
144
|
|
|
143
145
|
this.unhealthyBlockDiff = unhealthyBlockDiff ?? DEFAULT_UNHEALTHY_BLOCK_DIFF
|
|
144
146
|
this.serviceSelector = new DiscoveryProviderSelection(
|
|
@@ -177,6 +179,7 @@ export class DiscoveryProvider {
|
|
|
177
179
|
'change',
|
|
178
180
|
(endpoint: string) => {
|
|
179
181
|
this.setEndpoint(endpoint)
|
|
182
|
+
this.selectionCallback?.(endpoint, [])
|
|
180
183
|
}
|
|
181
184
|
)
|
|
182
185
|
|
|
@@ -1251,7 +1254,8 @@ export class DiscoveryProvider {
|
|
|
1251
1254
|
if (this.discoveryNodeSelector) {
|
|
1252
1255
|
return await this._makeRequestInternalNext<Response>(
|
|
1253
1256
|
requestObj,
|
|
1254
|
-
throwError
|
|
1257
|
+
throwError,
|
|
1258
|
+
blockNumber
|
|
1255
1259
|
)
|
|
1256
1260
|
}
|
|
1257
1261
|
|
|
@@ -1412,7 +1416,8 @@ export class DiscoveryProvider {
|
|
|
1412
1416
|
|
|
1413
1417
|
async _makeRequestInternalNext<Response>(
|
|
1414
1418
|
requestObj: Record<string, unknown>,
|
|
1415
|
-
throwError = false
|
|
1419
|
+
throwError = false,
|
|
1420
|
+
blockNumber?: number
|
|
1416
1421
|
) {
|
|
1417
1422
|
if (!this.discoveryProviderEndpoint || !this.discoveryNodeMiddleware) return
|
|
1418
1423
|
|
|
@@ -1465,6 +1470,13 @@ export class DiscoveryProvider {
|
|
|
1465
1470
|
})) ?? response
|
|
1466
1471
|
|
|
1467
1472
|
const responseBody: DiscoveryResponse<Response> = await response.json()
|
|
1473
|
+
|
|
1474
|
+
if (blockNumber && responseBody.latest_indexed_block < blockNumber) {
|
|
1475
|
+
throw new Error(
|
|
1476
|
+
`Requested blocknumber ${blockNumber}, but discovery is behind at ${responseBody.latest_indexed_block}`
|
|
1477
|
+
)
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1468
1480
|
return responseBody
|
|
1469
1481
|
}
|
|
1470
1482
|
|
package/src/utils/fileHasher.ts
CHANGED
|
@@ -237,7 +237,7 @@ export const fileHasher = {
|
|
|
237
237
|
logger: any = console
|
|
238
238
|
): Promise<string> {
|
|
239
239
|
const buffer = await fileHasher.convertToBuffer(content, logger)
|
|
240
|
-
return fileHasher.hashNonImages(buffer)
|
|
240
|
+
return await fileHasher.hashNonImages(buffer)
|
|
241
241
|
},
|
|
242
242
|
|
|
243
243
|
/**
|
|
@@ -250,6 +250,6 @@ export const fileHasher = {
|
|
|
250
250
|
content: ImportCandidate,
|
|
251
251
|
_: any = console
|
|
252
252
|
): Promise<HashedImage[]> {
|
|
253
|
-
return fileHasher.hashImages(content)
|
|
253
|
+
return await fileHasher.hashImages(content)
|
|
254
254
|
}
|
|
255
255
|
}
|
package/src/api/Users.test.js
DELETED