Skip to content

Commit

Permalink
[CON-676] Support storage v2 playlists+albums, and bump libs version …
Browse files Browse the repository at this point in the history
…to 2.0.3-beta.17 (#3314)
  • Loading branch information
theoilie authored May 5, 2023
1 parent 3cca778 commit 571c991
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 300 deletions.
6 changes: 3 additions & 3 deletions packages/common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/AudiusProject/audius-client/issues"
},
"dependencies": {
"@audius/sdk": "2.0.3-beta.16",
"@audius/sdk": "2.0.3-beta.17",
"@fingerprintjs/fingerprintjs-pro": "3.5.6",
"@metaplex-foundation/mpl-token-metadata": "2.5.2",
"@optimizely/optimizely-sdk": "4.0.0",
Expand Down
133 changes: 103 additions & 30 deletions packages/common/src/services/audius-backend/AudiusBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,12 +1290,21 @@ export const audiusBackend = ({
false
if (storageV2SignupEnabled || storageV2UploadEnabled) {
try {
return await audiusLibs.Track.uploadTrackV2(
trackFile,
coverArtFile,
metadata,
onProgress
)
const { trackId, updatedMetadata, txReceipt } =
await audiusLibs.Track.uploadTrackV2AndWriteToChain(
trackFile,
coverArtFile,
metadata,
onProgress
)
// Return with properties that confirmer expects
return {
blockHash: txReceipt.blockHash,
blockNumber: txReceipt.blockNumber,
trackId,
transcodedTrackCID: updatedMetadata.track_cid,
error: false
}
} catch (e: any) {
return { error: e }
}
Expand All @@ -1310,20 +1319,43 @@ export const audiusBackend = ({
}
}

// Used to upload multiple tracks as part of an album/playlist
// Returns { metadataMultihash, metadataFileUUID, transcodedTrackCID, transcodedTrackUUID, metadata }
// Used to upload multiple tracks as part of an album/playlist.
// V2: Returns { metadataMultihash, updatedMetadata }
// LEGACY: Returns { metadataMultihash, metadataFileUUID, transcodedTrackCID, transcodedTrackUUID, metadata }
async function uploadTrackToCreatorNode(
trackFile: File,
coverArtFile: File,
metadata: TrackMetadata,
onProgress: (loaded: number, total: number) => void
) {
return audiusLibs.Track.uploadTrackContentToCreatorNode(
trackFile,
coverArtFile,
metadata,
onProgress
const storageV2UploadEnabled = await getFeatureEnabled(
FeatureFlags.STORAGE_V2_TRACK_UPLOAD
)
if (storageV2UploadEnabled) {
const updatedMetadata = await audiusLibs.Track.uploadTrackV2(
trackFile,
coverArtFile,
metadata,
onProgress
)
return {
metadata: updatedMetadata,

// We don't need these properties, but the confirmer expects them.
// TODO: Remove after v2 is fully rolled out and v1 is removed
transcodedTrackCID: updatedMetadata.track_cid,
metadataMultihash: '',
metadataFileUUID: '',
transcodedTrackUUID: ''
}
} else {
return await audiusLibs.Track.uploadTrackContentToCreatorNode(
trackFile,
coverArtFile,
metadata,
onProgress
)
}
}

async function getUserEmail() {
Expand All @@ -1333,9 +1365,8 @@ export const audiusBackend = ({
}

/**
* Takes an array of [{metadataMultihash, metadataFileUUID}, {}, ]
* Adds tracks to chain for this user
* Associates tracks with user on creatorNode
* Adds tracks to chain for this user.
* Associates tracks with user on creatorNode if in legacy flow (non storage v2).
*/
async function registerUploadedTracks(
uploadedTracks: {
Expand All @@ -1344,25 +1375,41 @@ export const audiusBackend = ({
metadata: TrackMetadata
}[]
) {
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
return audiusLibs.Track.addTracksToChainAndCnode(
uploadedTracks,
writeMetadataThroughChainEnabled
const storageV2UploadEnabled = await getFeatureEnabled(
FeatureFlags.STORAGE_V2_TRACK_UPLOAD
)
if (storageV2UploadEnabled) {
return await audiusLibs.Track.addTracksToChainV2(
uploadedTracks.map((t) => t.metadata)
)
} else {
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
return await audiusLibs.Track.addTracksToChainAndCnode(
uploadedTracks,
writeMetadataThroughChainEnabled
)
}
}

async function uploadImage(file: File) {
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
return audiusLibs.File.uploadImage(
file,
undefined,
null,
writeMetadataThroughChainEnabled
const storageV2UploadEnabled = await getFeatureEnabled(
FeatureFlags.STORAGE_V2_TRACK_UPLOAD
)
if (storageV2UploadEnabled) {
return await audiusLibs.creatorNode.uploadTrackCoverArtV2(file, () => {})
} else {
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
return await audiusLibs.File.uploadImage(
file,
undefined,
null,
writeMetadataThroughChainEnabled
)
}
}

async function updateTrack(
Expand Down Expand Up @@ -1508,6 +1555,7 @@ export const audiusBackend = ({
return null
}

// TODO (theo): don't call uploadImage if storage v2 signup is enabled
async function updateCreator(metadata: User, _id: ID) {
let newMetadata = { ...metadata }
const associatedWallets = await fetchUserAssociatedWallets(metadata)
Expand Down Expand Up @@ -1580,6 +1628,7 @@ export const audiusBackend = ({
}
}

// TODO (theo): don't call uploadImage if storage v2 signup is enabled
async function updateUser(metadata: User, id: ID) {
let newMetadata = { ...metadata }
const writeMetadataThroughChainEnabled =
Expand Down Expand Up @@ -1732,6 +1781,9 @@ export const audiusBackend = ({
track: trackId,
metadata_time: currentBlock.timestamp
}))
const storageV2UploadEnabled = await getFeatureEnabled(
FeatureFlags.STORAGE_V2_TRACK_UPLOAD
)
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
Expand All @@ -1743,6 +1795,7 @@ export const audiusBackend = ({
is_album: isAlbum,
is_private: isPrivate
},
storageV2UploadEnabled,
writeMetadataThroughChainEnabled
)
const { blockHash, blockNumber, error } = response
Expand All @@ -1757,13 +1810,17 @@ export const audiusBackend = ({
}

async function updatePlaylist(metadata: Collection) {
const storageV2UploadEnabled = await getFeatureEnabled(
FeatureFlags.STORAGE_V2_TRACK_UPLOAD
)
try {
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
const { blockHash, blockNumber } =
await audiusLibs.EntityManager.updatePlaylist(
metadata,
storageV2UploadEnabled,
writeMetadataThroughChainEnabled
)

Expand All @@ -1775,13 +1832,17 @@ export const audiusBackend = ({
}

async function orderPlaylist(playlist: any) {
const storageV2UploadEnabled = await getFeatureEnabled(
FeatureFlags.STORAGE_V2_TRACK_UPLOAD
)
try {
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
const { blockHash, blockNumber } =
await audiusLibs.EntityManager.updatePlaylist(
playlist,
storageV2UploadEnabled,
writeMetadataThroughChainEnabled
)
return { blockHash, blockNumber }
Expand All @@ -1792,6 +1853,9 @@ export const audiusBackend = ({
}

async function publishPlaylist(playlist: Collection) {
const storageV2UploadEnabled = await getFeatureEnabled(
FeatureFlags.STORAGE_V2_TRACK_UPLOAD
)
try {
playlist.is_private = false
const writeMetadataThroughChainEnabled =
Expand All @@ -1803,6 +1867,7 @@ export const audiusBackend = ({
...playlist,
is_private: false
},
storageV2UploadEnabled,
writeMetadataThroughChainEnabled
)
return { blockHash, blockNumber }
Expand All @@ -1813,13 +1878,17 @@ export const audiusBackend = ({
}

async function addPlaylistTrack(playlist: Collection) {
const storageV2UploadEnabled = await getFeatureEnabled(
FeatureFlags.STORAGE_V2_TRACK_UPLOAD
)
try {
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
const { blockHash, blockNumber } =
await audiusLibs.EntityManager.updatePlaylist(
playlist,
storageV2UploadEnabled,
writeMetadataThroughChainEnabled
)
return { blockHash, blockNumber }
Expand All @@ -1830,13 +1899,17 @@ export const audiusBackend = ({
}

async function deletePlaylistTrack(playlist: Collection) {
const storageV2UploadEnabled = await getFeatureEnabled(
FeatureFlags.STORAGE_V2_TRACK_UPLOAD
)
try {
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
const { blockHash, blockNumber } =
await audiusLibs.EntityManager.updatePlaylist(
playlist,
storageV2UploadEnabled,
writeMetadataThroughChainEnabled
)
return { blockHash, blockNumber }
Expand Down
Loading

0 comments on commit 571c991

Please sign in to comment.