export-data-directory.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /* global api, hashing, keyring, types, util */
  2. // run this script with:
  3. // yarn script exportDataDirectory
  4. //
  5. // or copy and paste the code into the pioneer javascript toolbox at:
  6. // https://testnet.joystream.org/#/js
  7. const script = async ({ api, hashing, keyring, types, util }) => {
  8. console.log('Getting information from data directory. This may take a while')
  9. const dataDirObjects = await api.query.dataDirectory.dataByContentId.entries()
  10. let transformed = await Promise.all(dataDirObjects.map(async (obj) => {
  11. if (obj.isNone) { return null }
  12. return [obj[0], {
  13. owner: obj[1].owner,
  14. added_at: obj[1].added_at,
  15. type_id: obj[1].type_id,
  16. size: obj[1].size,
  17. liaison_judgement: obj[1].liaison,
  18. liaison_judgement: obj[1].liaison_judgement,
  19. ipfs_content_id: obj[1].ipfs_content_id }]
  20. }))
  21. console.log(JSON.stringify(transformed))
  22. console.error(`Exported ${transformed.length} objects`)
  23. }
  24. if (typeof module === 'undefined') {
  25. // Pioneer js-toolbox
  26. script({ api, hashing, keyring, types, util })
  27. } else {
  28. // Node
  29. module.exports = script
  30. }