list-data-directory.js 897 B

123456789101112131415161718192021222324252627282930313233
  1. /* global api, hashing, keyring, types, util, joy */
  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(
  11. ids.map(async (id) => {
  12. let obj = await api.query.dataDirectory.dataObjectByContentId(id)
  13. if (obj.isNone) {
  14. return
  15. }
  16. obj = obj.unwrap()
  17. console.log(`contentId: ${api.createType('ContentId', id).encode()}, ipfs: ${obj.ipfs_content_id}`)
  18. })
  19. )
  20. console.error(`Data Directory contains ${ids.length} objects`)
  21. }
  22. if (typeof module === 'undefined') {
  23. // Pioneer js-toolbox
  24. script({ api, hashing, keyring, types, util, joy })
  25. } else {
  26. // Node
  27. module.exports = script
  28. }