list-data-directory.js 858 B

12345678910111213141516171819202122232425262728
  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. console.log('Getting information from data directory. This may take a while')
  10. const dataDirObjects = await api.query.dataDirectory.dataByContentId.entries()
  11. await Promise.all(dataDirObjects.map(async (obj) => {
  12. if (obj.isNone) { return }
  13. console.log(`contentId: ${obj[0]}, ipfs: ${obj[1].ipfs_content_id}`)
  14. }))
  15. console.error(`Data Directory contains ${dataDirObjects.length} objects`)
  16. }
  17. if (typeof module === 'undefined') {
  18. // Pioneer js-toolbox
  19. script({ api, hashing, keyring, types, util, joy })
  20. } else {
  21. // Node
  22. module.exports = script
  23. }