Skip to content

Commit

Permalink
Upgrade axios
Browse files Browse the repository at this point in the history
  • Loading branch information
brahma-dev committed Mar 1, 2024
1 parent e402d23 commit 51b7071
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
22 changes: 14 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "metafetch",
"description": "Metafetch fetches a given URL's title, description, images, links etc.",
"version": "3.1.0",
"version": "3.1.1",
"homepage": "https://github.com/brahma-dev/metafetch",
"repository": {
"type": "git",
Expand All @@ -21,7 +21,7 @@
],
"main": "dist/index",
"dependencies": {
"axios": "^0.27.2",
"axios": "^0.28.0",
"cheerio": "^1.0.0-rc.12",
"franc": "^6.2.0",
"iconv-lite": "^0.6.3",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Expand Up @@ -4,7 +4,7 @@ import parser, { MetafetchResponse } from "./parser";
import axios, { AxiosRequestHeaders, AxiosBasicCredentials, AxiosProxyConfig } from "axios";

axios.interceptors.response.use(response => {
let enc = (response.headers['content-type'].match(/charset=(.+)/) || []).pop();
let enc = (response.headers['content-type']?.match(/charset=(.+)/) || []).pop();
if (!enc) {
// Extracted from <meta charset="gb2312"> or <meta http-equiv=Content-Type content="text/html;charset=gb2312">
enc = (response.data.toString().match(/<meta.+?charset=['"]?([^"']+)/i) || []).pop()
Expand Down Expand Up @@ -123,7 +123,7 @@ class Metafetch {
maxContentLength: http_options.maxContentLength,
responseType: 'arraybuffer',
}).then((response) => {
let result = parser(cleanurl, _options, response.data, response.headers, franc)
let result = parser(cleanurl, _options, response.data?response.data.toString():"", response.headers, franc)
resolve(result);
}).catch((err) => {
if (err.response) {
Expand Down
2 changes: 1 addition & 1 deletion src/parser.ts
Expand Up @@ -35,7 +35,7 @@ export default function (url: string, options: any, body: string, headers: Axios
title = $('title').text();
}
if (options.charset) {
response.charset = $("meta[charset]").attr("charset") || (headers['content-type'].match(/charset=(.+)/) || []).pop();
response.charset = $("meta[charset]").attr("charset") || (headers['content-type']?.match(/charset=(.+)/) || []).pop();
}
if (options.images) {
var imagehash: { [x: string]: boolean } = {};
Expand Down

0 comments on commit 51b7071

Please sign in to comment.