export-data-directory.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* global api, hashing, keyring, types, util, joy */
  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 }) => {
  8. const ids = await api.query.dataDirectory.knownContentIds()
  9. // When a BTreeMap is constructed for injection the node will fail to decode
  10. // it if its not sorted.
  11. ids.sort()
  12. const transformed = await Promise.all(
  13. ids.map(async (id) => {
  14. let obj = await api.query.dataDirectory.dataObjectByContentId(id)
  15. if (obj.isNone) {
  16. return null
  17. }
  18. obj = obj.unwrap()
  19. return [
  20. id,
  21. {
  22. owner: obj.owner,
  23. added_at: obj.added_at,
  24. type_id: obj.type_id,
  25. size: obj.size_in_bytes,
  26. liaison: obj.liaison,
  27. liaison_judgement: obj.liaison_judgement,
  28. ipfs_content_id: obj.ipfs_content_id,
  29. },
  30. ]
  31. })
  32. )
  33. console.log(JSON.stringify(transformed))
  34. console.error(`Exported ${transformed.length} objects`)
  35. }
  36. if (typeof module === 'undefined') {
  37. // Pioneer js-toolbox
  38. script({ api, hashing, keyring, types, util, joy })
  39. } else {
  40. // Node
  41. module.exports = script
  42. }