Skip to content

Commit

Permalink
Update src/index.js and README.md - Allow Overriding the link from a …
Browse files Browse the repository at this point in the history
…server response. Allow using headers in HTTP requests
  • Loading branch information
Ali I. Avci committed Jan 4, 2022
1 parent ae759ec commit a7df05b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const editor = EditorJS({
linkTool: {
class: LinkTool,
config: {
endpoint: 'http://localhost:8008/fetchUrl', // Your backend endpoint for url data fetching
endpoint: 'http://localhost:8008/fetchUrl', // Your backend endpoint for url data fetching,
}
}
},
Expand All @@ -70,6 +70,7 @@ Link Tool supports these configuration parameters:
| Field | Type | Description |
| ---------|-------------|------------------------------------------------|
| endpoint | `string` | **Required:** the endpoint for link data fetching. |
| headaers | `object` | **Optional:** the headers used in the GET request. |

## Output data

Expand Down Expand Up @@ -107,6 +108,7 @@ Backend response **should** cover following format:
```json5
{
"success" : 1,
"link": "https://codex.so", // Optionally return a link to set the hyperlink URL
"meta": {
// ... any fields you want
}
Expand All @@ -115,6 +117,8 @@ Backend response **should** cover following format:

**success** — uploading status. 1 for successful, 0 for failed

**link** - You are able to return the l

**meta** — link fetched data.

Currently, the plugin's design supports the 'title', 'image', and 'description' fields. They should have the following format in the response:
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export default class LinkTool {
*/
this.config = {
endpoint: config.endpoint || '',
headers: config.headers || {},
};

this.nodes = {
Expand Down Expand Up @@ -385,6 +386,7 @@ export default class LinkTool {
try {
const { body } = await (ajax.get({
url: this.config.endpoint,
headers: this.config.headers,
data: {
url,
},
Expand All @@ -410,6 +412,8 @@ export default class LinkTool {

const metaData = response.meta;

const link = response.link || this.data.link;

this.data = { meta: metaData };

if (!metaData) {
Expand Down

0 comments on commit a7df05b

Please sign in to comment.