list-data-directory.js 856 B

1234567891011121314151617181920212223242526272829
  1. /* global api, hashing, keyring, types, util */
  2. // run this script with:
  3. // yarn script listDataDirectory
  4. //
  5. // or copy and paste the code into the pioneer javascript toolbox at:
  6. // https://testnet.joystream.org/#/js
  7. // requires nicaea release+
  8. const script = async ({ api, joy }) => {
  9. const ids = await api.query.dataDirectory.knownContentIds()
  10. await Promise.all(ids.map(async (id) => {
  11. let obj = await api.query.dataDirectory.dataObjectByContentId(id)
  12. if (obj.isNone) { return }
  13. obj = obj.unwrap()
  14. console.log(`contentId: ${new joy.media.ContentId(id).encode()}, ipfs: ${obj.ipfs_content_id}`)
  15. }))
  16. console.error(`Data Directory contains ${ids.length} objects`)
  17. }
  18. if (typeof module === 'undefined') {
  19. // Pioneer js-toolbox
  20. script({ api, hashing, keyring, types, util, joy })
  21. } else {
  22. // Node
  23. module.exports = script
  24. }