From c0173a02b6cb2a893f025bfda7cb87c036228071 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Wed, 29 Jul 2020 11:08:18 -0700 Subject: [PATCH 1/2] feat: make urlSource compatible with new ipfs.add --- src/files/url-source.js | 17 +++++++++++------ test/files/url-source.spec.js | 5 +++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/files/url-source.js b/src/files/url-source.js index fd2e0dc..89ec6f6 100644 --- a/src/files/url-source.js +++ b/src/files/url-source.js @@ -2,12 +2,17 @@ const Http = require('../http') -module.exports = async function * urlSource (url, options) { - const http = new Http() - const response = await http.get(url, options) - - yield { +const urlSource = (url, options) => { + return { path: decodeURIComponent(new URL(url).pathname.split('/').pop() || ''), - content: response.iterator() + content: readURLContent(url, options) } } + +const readURLContent = async function * (url, options) { + const http = new Http() + const response = await http.get(url, options) + yield * response.iterator() +} + +module.exports = urlSource diff --git a/test/files/url-source.spec.js b/test/files/url-source.spec.js index 7d12fae..8583075 100644 --- a/test/files/url-source.spec.js +++ b/test/files/url-source.spec.js @@ -5,13 +5,14 @@ const { expect } = require('aegir/utils/chai') const all = require('it-all') const urlSource = require('../../src/files/url-source') -const last = require('it-last') const { Buffer } = require('buffer') describe('url-source', function () { it('can get url content', async function () { const content = 'foo' - const file = await last(urlSource(`${process.env.ECHO_SERVER}/download?data=${content}`)) + const file = urlSource(`${process.env.ECHO_SERVER}/download?data=${content}`) + + expect(file).to.have.property('path', 'download') await expect(all(file.content)).to.eventually.deep.equal([Buffer.from(content)]) }) From d1e97b7876f98e95b3c0bbbe43347d5b2f2bf9ab Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 15 Jan 2021 15:46:59 +0000 Subject: [PATCH 2/2] chore: add types to read method --- src/files/url-source.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/files/url-source.js b/src/files/url-source.js index 8ca9197..2880c7d 100644 --- a/src/files/url-source.js +++ b/src/files/url-source.js @@ -3,12 +3,13 @@ const HTTP = require('../http') /** + * * @param {string} url * @param {import("../types").HTTPOptions} [options] * @returns {{ - path: string; - content?: AsyncIterable; -}} + * path: string; + * content?: AsyncIterable; + * }} */ const urlSource = (url, options) => { return { @@ -17,7 +18,13 @@ const urlSource = (url, options) => { } } -const readURLContent = async function * (url, options) { +/** + * + * @param {string} url + * @param {import("../types").HTTPOptions} [options] + * @returns {AsyncIterable} + */ +async function * readURLContent (url, options) { const http = new HTTP() const response = await http.get(url, options)