getContentFromStorageNode.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import axios from 'axios'
  2. import { assert } from 'chai'
  3. import { ContentId } from '@joystream/types/media'
  4. import { registry } from '@joystream/types'
  5. import { QueryNodeApi } from '../../Api'
  6. import { Utils } from '../../utils'
  7. export default async function getContentFromStorageNode(api: QueryNodeApi): Promise<void> {
  8. const videoTitle = 'Storage node test'
  9. // Temporary solution (wait 1 minute)
  10. await Utils.wait(60000)
  11. // Query video by title with where expression
  12. const videoWhereQueryResult = await api.performWhereQueryByVideoTitle(videoTitle)
  13. assert.equal(1, videoWhereQueryResult.data.videos.length, 'Should fetch only one video')
  14. // Get dataObjectId from the queried video's media location
  15. const dataObjectId = videoWhereQueryResult.data.videos[0].media.location.dataObjectId
  16. assert(dataObjectId.length > 2, 'dataObjectId should not be empty')
  17. const contentId = ContentId.decode(registry, dataObjectId)
  18. // Decode data object
  19. const dataObject = await api.getDataObjectByContentId(contentId)
  20. assert(dataObject, 'dataObject should not be null')
  21. const response = await axios.get(`${process.env.STORAGE_NODE_URL}/${dataObjectId}`)
  22. assert(response.headers['content-length'], 'Should have some value')
  23. const contentLenght = Number.parseInt(response.headers['content-length'])
  24. assert.equal(contentLenght, dataObject!.size_in_bytes.toJSON(), 'Content should be same size')
  25. }