1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- const fetchEntity = async (api, id) => api.query.contentDirectory.entityById(id)
- const processUpload = async (api, u) => {
- if (!u.classesOfEntityIds) return console.log(`no classesOfEntityIds`)
- u.entityIds = await Promise.all(
- u.entityIds.map(async (id) => {
- const entity = await fetchEntity(api, id)
- return { id, ...entity.toJSON() }
- })
- )
- return u
- const index = u.classesOfEntityIds
- .map((c, i) => (c === 4 ? i : null))
- .filter((i) => i)
- if (!index[0]) return console.log(`no index`)
- const entityId = u.entityIds[index[0]]
- if (!entityId) return console.log(`no entityId`)
- console.log(`fetching entity ${entityId}`)
- const entity = await fetchEntity(api, entityId)
- entity.id = entityId
- //console.log(`values`, entity.values)
- }
- console.log(`connecting ..`)
- const fs = require('fs')
- const { types } = require('@joystream/types')
- const { ApiPromise, WsProvider } = require('@polkadot/api')
- const { Header } = require('@polkadot/types/interfaces')
- const processChanges = async () => {
- const provider = new WsProvider(`ws://localhost:9944`)
- const api = await ApiPromise.create({ provider, types })
- let uploads = []
- const files = ['./changes.json', './changes2.json']
- files.forEach((file) => {
- const changes = JSON.parse(fs.readFileSync(`./curation/${file}`, 'utf8'))
- uploads.push(...changes.filter((c) => c && c.action === 'Video Upload'))
- })
- await api.isReady
- console.log(`processing ${uploads.length} uploads`)
- results = await Promise.all(uploads.map((u) => processUpload(api, u)))
- fs.writeFileSync(`uploads.json`, JSON.stringify(results))
- process.exit(0)
- }
- processChanges()
|