Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 16 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default class LinkTool {
this.config = {
endpoint: config.endpoint || '',
headers: config.headers || {},
doFetch: config.doFetch || null,
};

this.nodes = {
Expand Down Expand Up @@ -391,13 +392,21 @@ 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) {
Expand Down