content.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { ApiPromise } from "@polkadot/api";
  2. import {
  3. CuratorGroup,
  4. CuratorGroupId,
  5. Channel,
  6. ChannelCategory,
  7. ChannelCategoryId,
  8. Video,
  9. VideoId,
  10. VideoCategory,
  11. VideoCategoryId,
  12. } from "@joystream/types/content";
  13. import { ChannelId } from "@joystream/types/storage";
  14. import { Hash } from "@polkadot/types/interfaces";
  15. export const getCuratorGroup = (
  16. api: ApiPromise,
  17. id: CuratorGroupId | number
  18. ): Promise<CuratorGroup> =>
  19. api.query.content.curatorGroupById(id) as Promise<CuratorGroup>;
  20. export const getChannel = (
  21. api: ApiPromise,
  22. id: ChannelId | number
  23. ): Promise<Channel> => api.query.content.channelById(id) as Promise<Channel>;
  24. export const getChannelCategory = (
  25. api: ApiPromise,
  26. id: ChannelCategoryId | number
  27. ): Promise<ChannelCategory> =>
  28. api.query.content.channelCategoryById(id) as Promise<ChannelCategory>;
  29. export const getVideo = (
  30. api: ApiPromise,
  31. id: VideoId | number
  32. ): Promise<Video> => api.query.content.videoById(id) as Promise<Video>;
  33. export const getVideoCategory = (
  34. api: ApiPromise,
  35. id: VideoId | number
  36. ): Promise<Video> => api.query.content.videoCategoryById(id) as Promise<Video>;
  37. export const getNextChannel = (
  38. api: ApiPromise,
  39. hash?: Hash
  40. ): Promise<ChannelId> =>
  41. hash
  42. ? (api.query.content.nextChannelId.at(hash) as Promise<ChannelId>)
  43. : (api.query.content.nextChannelId() as Promise<ChannelId>);
  44. export const getNextChannelCategory = (
  45. api: ApiPromise,
  46. hash?: Hash
  47. ): Promise<ChannelCategoryId> =>
  48. hash
  49. ? api.query.content.nextChannelCategoryId.at(hash)
  50. : (api.query.content.nextChannelCategoryId() as Promise<ChannelCategoryId>);
  51. export const getNextCuratorGroup = (
  52. api: ApiPromise,
  53. hash?: Hash
  54. ): Promise<CuratorGroupId> =>
  55. hash
  56. ? api.query.content.nextCuratorGroupId.at(hash)
  57. : (api.query.content.nextCuratorGroupId() as Promise<CuratorGroupId>);
  58. export const getNextPerson = (api: ApiPromise, hash?: Hash): Promise<number> =>
  59. hash
  60. ? api.query.content.nextPersonId.at(hash)
  61. : (api.query.content.nextPersonId() as any);
  62. export const getNextPlaylist = (
  63. api: ApiPromise,
  64. hash?: Hash
  65. ): Promise<number> =>
  66. hash
  67. ? api.query.content.nextPlaylistId.at(hash)
  68. : (api.query.content.nextPlaylistId() as any);
  69. export const getNextSeries = (api: ApiPromise, hash?: Hash): Promise<number> =>
  70. hash
  71. ? api.query.content.nextSeriesId.at(hash)
  72. : (api.query.content.nextSeriesId() as any);
  73. export const getNextVideo = (api: ApiPromise, hash?: Hash): Promise<number> =>
  74. hash
  75. ? api.query.content.nextVideoId.at(hash)
  76. : (api.query.content.nextVideoId() as any);
  77. export const getNextVideoCategory = (
  78. api: ApiPromise,
  79. hash?: Hash
  80. ): Promise<number> =>
  81. hash
  82. ? api.query.content.nextVideoCategoryId.at(hash)
  83. : (api.query.content.nextVideoCategoryId() as any);