user 5 лет назад
Родитель
Сommit
f511fb41ee
7 измененных файлов с 50 добавлено и 2 удалено
  1. 1 0
      lib/index.d.ts
  2. 21 0
      lib/index.js
  3. 1 1
      lib/index.js.map
  4. 3 0
      lib/sample.js
  5. 1 1
      lib/sample.js.map
  6. 19 0
      src/index.ts
  7. 4 0
      src/sample.ts

+ 1 - 0
lib/index.d.ts

@@ -38,6 +38,7 @@ export declare class BankClient {
     updateContact(peerId: string, contactId: string, newProperties: any): Promise<ContactItem>;
     getContentItemByHash(hashInPlaylist: string): Promise<ContentItem>;
     getItemsForCommaList(commaList: string): Promise<any[]>;
+    getContentItemsForCommaList(commaList: string): Promise<any[]>;
     parseItemHash(itemHash: string): {
         type: string;
         timestamp: string | null;

+ 21 - 0
lib/index.js

@@ -303,6 +303,27 @@ class BankClient {
         return __awaiter(this, void 0, void 0, function* () {
             const itemHashes = commaList.split(',').filter(x => x.trim() !== '');
             const items = yield Promise.all(itemHashes.map(itemId => {
+                const { hash, type } = this.parseItemHash(itemId);
+                if (type === 'CO') {
+                    return this.getContentItemByHash(itemId);
+                }
+                else {
+                    return this.webClient.requestJSON({
+                        method: 'get',
+                        url: this.ipfsUrlBase + '/ipfs/' + hash,
+                    });
+                }
+            }));
+            for (const item of items) {
+                item.hash = itemHashes.shift();
+            }
+            return items;
+        });
+    }
+    getContentItemsForCommaList(commaList) {
+        return __awaiter(this, void 0, void 0, function* () {
+            const itemHashes = commaList.split(',').filter(x => x.trim() !== '');
+            const items = yield Promise.all(itemHashes.map(itemId => {
                 const itemHash = this.parseItemHash(itemId).hash;
                 return this.webClient.requestJSON({
                     method: 'get',

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
lib/index.js.map


+ 3 - 0
lib/sample.js

@@ -26,6 +26,9 @@ const bankClient = new index_1.BankClient(host, ipfsHost, new storage_node_1.Sto
     console.log('peerId', peerId);
     const balance = yield bankClient.getBalance();
     console.log('my balance', balance);
+    const starting = yield bankClient.retrievePrivate('QmXRkCwxqecBMXs4DQucS9w85pW16i26tdKcZHExt9z8s5', '🌎');
+    const items = yield bankClient.getItemsForCommaList(starting);
+    console.log('items', items);
     // await bankClient.appendBank('bank:qmlink/📥', uploadResult);
     // console.log('added.');
     // const publishRes = await bankClient.appendPrivate(peerId, 'bleh', 'zdj7Wjbc1NqWsVVRaQjWhvvc49MGtszd2VZQ3pWnVKbh6tDWi');

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
lib/sample.js.map


+ 19 - 0
src/index.ts

@@ -293,6 +293,25 @@ export class BankClient {
     public async getItemsForCommaList(commaList: string): Promise<any[]> {
       const itemHashes = commaList.split(',').filter(x => x.trim() !== '');
       const items: any[] = await Promise.all(itemHashes.map(itemId => {
+        const { hash, type } = this.parseItemHash(itemId);
+        if (type === 'CO') {
+          return this.getContentItemByHash(itemId);
+        } else {
+          return this.webClient.requestJSON({
+            method: 'get',
+            url: this.ipfsUrlBase + '/ipfs/' + hash,
+          });
+        }
+      }));
+      for (const item of items) {
+        item.hash = itemHashes.shift();
+      }
+      return items;
+    }
+
+    public async getContentItemsForCommaList(commaList: string): Promise<any[]> {
+      const itemHashes = commaList.split(',').filter(x => x.trim() !== '');
+      const items: any[] = await Promise.all(itemHashes.map(itemId => {
         const itemHash = this.parseItemHash(itemId).hash;
         return this.webClient.requestJSON({
           method: 'get',

+ 4 - 0
src/sample.ts

@@ -17,6 +17,10 @@ const bankClient = new BankClient(host, ipfsHost, new StorageNode('bankClient'),
     const balance = await bankClient.getBalance();
     console.log('my balance', balance);
 
+    const starting = await bankClient.retrievePrivate('QmXRkCwxqecBMXs4DQucS9w85pW16i26tdKcZHExt9z8s5', '🌎');
+    const items = await bankClient.getItemsForCommaList(starting);
+    console.log('items', items);
+
     // await bankClient.appendBank('bank:qmlink/📥', uploadResult);
     // console.log('added.');
     // const publishRes = await bankClient.appendPrivate(peerId, 'bleh', 'zdj7Wjbc1NqWsVVRaQjWhvvc49MGtszd2VZQ3pWnVKbh6tDWi');