Skip to content

Commit

Permalink
Refactor request to Axios
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrooksuk committed Oct 14, 2024
1 parent ee8f854 commit a73f488
Show file tree
Hide file tree
Showing 4 changed files with 1,931 additions and 1,446 deletions.
21 changes: 12 additions & 9 deletions lib/summary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { convertHTMLToText, getTitle } from './helpers/html.js'
import { isValidUrl } from './helpers/urls.js'
import { default as request } from 'request'
import axios from 'axios'
import {
onlyGetSentences,
splitContentToSentences,
Expand All @@ -14,18 +14,21 @@ import {

export const summarizeFromUrl = function (url, callback) {
if (isValidUrl(url)) {
request.get(url, function (error, response, body) {
axios.get(url).then((response) => {
const body = response.data

let title = getTitle(body)
let text = convertHTMLToText(body)
let content = onlyGetSentences(text)
return summarize(title, content, (err, result, dict) => {
if (err) {
callback(err, result, dict)
} else {
callback(err, result, dict)
}
})

return summarize(title, content, (err, result, dict) => callback(err, result, dict))
})
.catch((error) => {
callback(
true,
'Failed to fetch the url. Please try again later.'
)
})
} else {
callback(
true,
Expand Down
Loading

0 comments on commit a73f488

Please sign in to comment.