3
0

content.ts 2.7 KB

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