123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- const getEntities = async (blockHash: Hash): Promise<Map<number, Entity>> => {
- let nrEntities: number = await getNextEntity(this.api, blockHash);
- let entities = new Map<number, Entity>();
- for (let i = 0; i < nrEntities; ++i) {
- const entity: Entity = await getEntity(this.api, blockHash, i);
- entities.set(i, entity);
- }
- return entities;
- };
- export const computeUsedSpaceInMbs = async (
- contentIds: Vec<ContentId>
- ): Promise<number> => {
- let space = 0;
- for (let contentId of contentIds) {
- const dataObject: Option<DataObject> = await getDataObject(
- this.api,
- contentId
- );
- space += dataObject.unwrap().size_in_bytes.toNumber();
- }
- return space / 1024 / 1024;
- };
- export const parseVideos = async (
- entities: Map<number, Entity>
- ): Promise<Media[]> => {
- let videos: Media[] = [];
- for (let [key, entity] of entities) {
- if (entity.class_id.toNumber() != VIDEO_CLASS_iD || entity.values.isEmpty)
- continue;
- let values = Array.from(entity.getField("values").entries());
- if (values.length < 2 || values[2].length < 1) continue;
- let title = values[2][1].getValue().toString();
- videos.push(new Media(key, title));
- }
- return videos;
- };
- const parseChannels = async (
- entities: Map<number, Entity>
- ): Promise<Channel[]> => {
- let channels: Channel[] = [];
- for (let [key, entity] of entities) {
- if (
- entity.class_id.toNumber() != CHANNEL_CLASS_iD ||
- entity.values.isEmpty
- ) {
- continue;
- }
- let values = Array.from(entity.getField("values").entries());
- let title = values[0][1].getValue().toString();
- channels.push(new Channel(key, title));
- }
- return channels;
- };
|