Skip to content

Commit

Permalink
update playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsolo committed Jul 10, 2022
1 parent b4d91fe commit a0b7239
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
7 changes: 4 additions & 3 deletions discovery-provider/src/tasks/audius_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def audius_data_state_update(
else None
)
logger.info(
f"index.py | AudiusData state update: {user_id}, entity_id={entity_id}, entity_type={entity_type}, action={action}, metadata_cid={metadata_cid}, metadata={metadata} signer={signer}"
f"asdf index.py | AudiusData state update: {user_id}, entity_id={entity_id}, entity_type={entity_type}, action={action}, metadata_cid={metadata_cid}, metadata={metadata} signer={signer}"
)

# Handle playlist creation
Expand All @@ -77,8 +77,9 @@ def audius_data_state_update(
txhash,
)

if action == "Create":
playlist_id = entity_id
if action == "Create" or action == "Update":
logger.info("asdf update")

playlist_record = parse_playlist_create_data_event(
update_task,
entry,
Expand Down
85 changes: 85 additions & 0 deletions libs/src/api/audiusData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,92 @@ export class AudiusData extends Base {
}
return respValues
}
/**
* Update a playlist using updated data contracts flow
**/
async updatePlaylist({
playlistId,
playlistName,
trackIds,
description,
isAlbum,
isPrivate,
coverArt,
logger = console
}: {
playlistId: number
playlistName: string
trackIds: number[]
description: string
isAlbum: boolean
isPrivate: boolean
coverArt: any
logger: any
}): Promise<{ blockHash: any; blockNumber: any; playlistId: number }> {
let respValues = {
blockHash: null,
blockNumber: null,
playlistId: 0
}
try {
const userId: number = parseInt(this.userStateManager.getCurrentUserId())
const action = 'Update'
const entityType = 'Playlist'
this.REQUIRES(Services.CREATOR_NODE)
// if (playlistName){

// }
let dirCID;
if (coverArt) {
const updatedPlaylistImage = await this.creatorNode.uploadImage(
coverArt,
true // square
)
dirCID = updatedPlaylistImage.dirCID
console.log("asdf dirCID")

}

const playlist = (await this.discoveryProvider.getPlaylists(1, 0, [playlistId]))[0]
// if (playlistName){

// }

console.log(`asdf playlist ${JSON.stringify(playlist)}`)
const metadata = {
action, // why include action here?
entityType,
playlist_id: playlistId,
playlist_contents: playlist.playlist_contents,
playlist_name: playlistName || playlist.playlist_name,
playlist_image_sizes_multihash: dirCID || playlist.playlist_image_sizes_multihash,
description: description || playlist.description,
is_album: playlist.is_album,
is_private: playlist.is_private
}
console.log(`asdf metadata ${JSON.stringify(metadata)}`)
const { metadataMultihash } = await this.creatorNode.uploadPlaylistMetadata(metadata)
console.log(`asdf metadataMultihash ${JSON.stringify(metadataMultihash)}`)

const resp = await this.manageEntity({
userId,
entityType,
entityId: playlistId,
action,
metadataMultihash
})
logger.info(`asdf UpdatePlaylistData - ${JSON.stringify(resp)}`)
const txReceipt = resp.txReceipt
respValues = {
blockHash: txReceipt.blockHash,
blockNumber: txReceipt.blockNumber,
playlistId: entityId
}
} catch (e) {
logger.error(`Data update playlist: err ${e}`)
}
return respValues
}

/**
* Manage an entity with the updated data contract flow
Expand Down

0 comments on commit a0b7239

Please sign in to comment.