Skip to content
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

Improve sdk track upload logs #7007

Merged
merged 2 commits into from
Jan 2, 2024
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
6 changes: 6 additions & 0 deletions packages/libs/src/sdk/api/tracks/TracksApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class TracksApi extends GeneratedTracksApi {
advancedOptions?: AdvancedOptions
) {
// Parse inputs
this.logger.info('Parsing inputs')
const {
userId,
trackFile,
Expand All @@ -91,6 +92,7 @@ export class TracksApi extends GeneratedTracksApi {
} = await parseParams('uploadTrack', createUploadTrackSchema())(params)

// Transform metadata
this.logger.info('Transforming metadata')
const metadata = this.trackUploadHelper.transformTrackUploadMetadata(
parsedMetadata,
userId
Expand All @@ -102,6 +104,7 @@ export class TracksApi extends GeneratedTracksApi {
}

// Upload track audio and cover art to storage node
this.logger.info('Uploading track audio and cover art')
const [coverArtResponse, audioResponse] = await Promise.all([
retry3(
async () =>
Expand Down Expand Up @@ -137,6 +140,7 @@ export class TracksApi extends GeneratedTracksApi {
)

// Write metadata to chain
this.logger.info('Writing metadata to chain')
const trackId = await this.trackUploadHelper.generateId('track')
const response = await this.entityManager.manageEntity({
userId,
Expand All @@ -150,6 +154,8 @@ export class TracksApi extends GeneratedTracksApi {
auth: this.auth,
...advancedOptions
})

this.logger.info('Successfully uploaded track')
return {
...response,
trackId: encodeHashId(trackId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export class EntityManager implements EntityManagerService {
signature
)

const response = await fetch(`${await this.getRelayEndpoint()}/relay`, {
const url = `${await this.getRelayEndpoint()}/relay`
this.logger.info(`Making relay request to ${url}`)
const response = await fetch(url, {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json'
Expand Down Expand Up @@ -152,6 +154,7 @@ export class EntityManager implements EntityManagerService {
confirmationTimeout?: number
confirmationPollingInterval?: number
}) {
this.logger.info('Confirming write')
const confirmBlock = async () => {
const endpoint = await this.discoveryNodeSelector.getSelectedEndpoint()
const {
Expand Down Expand Up @@ -182,6 +185,7 @@ export class EntityManager implements EntityManagerService {
confirmation = await confirmBlock()
}

this.logger.info('Write confirmed')
return true
}

Expand Down
8 changes: 5 additions & 3 deletions packages/libs/src/sdk/services/Storage/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export class Storage implements StorageService {
data: formData,
headers: formData.getBoundary
? {
'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`
}
'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`
}
: undefined,
onUploadProgress: (progressEvent) =>
onProgress?.(progressEvent.loaded, progressEvent.total)
Expand Down Expand Up @@ -225,7 +225,9 @@ export class Storage implements StorageService {
if (response.ok) {
return await response.json()
} else {
lastErr = `HTTP error: ${response.status} ${response.statusText}, ${await response.text()}`
lastErr = `HTTP error: ${response.status} ${
response.statusText
}, ${await response.text()}`
}
} catch (e: any) {
lastErr = e
Expand Down
Loading