From a27f5b22bf851a4dac5a2e4ee0e3fe0cd6aef999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=C3=ADn=20=C5=A0ajboch?= <38006361+sedlakos@users.noreply.github.com> Date: Mon, 6 Feb 2023 00:05:12 +0000 Subject: [PATCH 1/2] Added custom fetch method 'doFetch' --- src/index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index ad92ca2..a2ba31b 100644 --- a/src/index.js +++ b/src/index.js @@ -84,6 +84,7 @@ export default class LinkTool { this.config = { endpoint: config.endpoint || '', headers: config.headers || {}, + doFetch: config.doFetch || null }; this.nodes = { @@ -391,13 +392,17 @@ export default class LinkTool { this.data = { link: url }; try { - const { body } = await (ajax.get({ - url: this.config.endpoint, - headers: this.config.headers, - data: { - url, - }, - })); + const { body } = this.config.doFetch ? + await this.config.doFetch( + {url, endpoint: this.config.endpoint, headers: this.config.headers} + ) : + await (ajax.get({ + url: this.config.endpoint, + headers: this.config.headers, + data: { + url, + }, + })); this.onFetch(body); } catch (error) { From 390a8f8ebc2567f93aad2e7b86a83dbf475a8f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=C3=ADn=20=C5=A0ajboch?= <38006361+sedlakos@users.noreply.github.com> Date: Mon, 6 Feb 2023 00:11:02 +0000 Subject: [PATCH 2/2] Update documentation (custom fetch) --- README.md | 1 + src/index.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 35e25e4..6080e0d 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ Link Tool supports these configuration parameters: | ---------|-------------|------------------------------------------------| | endpoint | `string` | **Required:** the endpoint for link data fetching. | | headers | `object` | **Optional:** the headers used in the GET request. | +| doFetch | `callback` | **Optional:** the callback for custom fetch implementation `({url, endpoin, heaers}) => {}` | ## Output data diff --git a/src/index.js b/src/index.js index a2ba31b..6bceb38 100644 --- a/src/index.js +++ b/src/index.js @@ -84,7 +84,7 @@ export default class LinkTool { this.config = { endpoint: config.endpoint || '', headers: config.headers || {}, - doFetch: config.doFetch || null + doFetch: config.doFetch || null, }; this.nodes = { @@ -392,11 +392,15 @@ export default class LinkTool { this.data = { link: url }; try { - const { body } = this.config.doFetch ? - await this.config.doFetch( - {url, endpoint: this.config.endpoint, headers: this.config.headers} - ) : - await (ajax.get({ + const { body } = this.config.doFetch + ? await this.config.doFetch( + { + url, + endpoint: this.config.endpoint, + headers: this.config.headers, + } + ) + : await (ajax.get({ url: this.config.endpoint, headers: this.config.headers, data: {