filterChanges.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const fetchEntity = async (api, id) => api.query.contentDirectory.entityById(id)
  2. const processUpload = async (api, u) => {
  3. if (!u.classesOfEntityIds) return console.log(`no classesOfEntityIds`)
  4. u.entityIds = await Promise.all(
  5. u.entityIds.map(async (id) => {
  6. const entity = await fetchEntity(api, id)
  7. return { id, ...entity.toJSON() }
  8. })
  9. )
  10. return u
  11. const index = u.classesOfEntityIds
  12. .map((c, i) => (c === 4 ? i : null))
  13. .filter((i) => i)
  14. if (!index[0]) return console.log(`no index`)
  15. const entityId = u.entityIds[index[0]]
  16. if (!entityId) return console.log(`no entityId`)
  17. console.log(`fetching entity ${entityId}`)
  18. const entity = await fetchEntity(api, entityId)
  19. entity.id = entityId
  20. //console.log(`values`, entity.values)
  21. }
  22. console.log(`connecting ..`)
  23. const fs = require('fs')
  24. const { types } = require('@joystream/types')
  25. const { ApiPromise, WsProvider } = require('@polkadot/api')
  26. const { Header } = require('@polkadot/types/interfaces')
  27. const processChanges = async () => {
  28. const provider = new WsProvider(`ws://localhost:9944`)
  29. const api = await ApiPromise.create({ provider, types })
  30. let uploads = []
  31. const files = ['./changes.json', './changes2.json']
  32. files.forEach((file) => {
  33. const changes = JSON.parse(fs.readFileSync(`./curation/${file}`, 'utf8'))
  34. uploads.push(...changes.filter((c) => c && c.action === 'Video Upload'))
  35. })
  36. await api.isReady
  37. console.log(`processing ${uploads.length} uploads`)
  38. results = await Promise.all(uploads.map((u) => processUpload(api, u)))
  39. fs.writeFileSync(`uploads.json`, JSON.stringify(results))
  40. process.exit(0)
  41. }
  42. processChanges()