mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 21:47:57 +08:00
fix: compatible with axios data and params
This commit is contained in:
@@ -3,6 +3,7 @@ const config = require('@/config');
|
|||||||
const SocksProxyAgent = require('socks-proxy-agent');
|
const SocksProxyAgent = require('socks-proxy-agent');
|
||||||
const tunnel = require('tunnel');
|
const tunnel = require('tunnel');
|
||||||
const got = require('got');
|
const got = require('got');
|
||||||
|
const queryString = require('query-string');
|
||||||
|
|
||||||
let agent = null;
|
let agent = null;
|
||||||
if (config.proxy && config.proxy.protocol && config.proxy.host && config.proxy.port) {
|
if (config.proxy && config.proxy.protocol && config.proxy.host && config.proxy.port) {
|
||||||
@@ -74,12 +75,24 @@ const custom = got.extend({
|
|||||||
return error;
|
return error;
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
beforeRequest: [
|
init: [
|
||||||
(options) => {
|
(options) => {
|
||||||
options.body = options.data;
|
// compatible with axios api
|
||||||
|
if (options.data) {
|
||||||
|
if (typeof options.data === 'object') {
|
||||||
|
options.json = options.json || options.data;
|
||||||
|
} else {
|
||||||
|
options.body = options.body || options.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (options.responseType === 'buffer') {
|
if (options.responseType === 'buffer') {
|
||||||
options.encoding = null;
|
options.encoding = null;
|
||||||
}
|
}
|
||||||
|
if (options.params) {
|
||||||
|
options.query = options.query || queryString.stringify(options.params);
|
||||||
|
options.searchParams = options.query; // for Got v11 after
|
||||||
|
}
|
||||||
|
|
||||||
if (agent && new RegExp(config.proxy.url_regex).test(options.href)) {
|
if (agent && new RegExp(config.proxy.url_regex).test(options.href)) {
|
||||||
options.agent = agent[options.protocol.slice(0, -1)];
|
options.agent = agent[options.protocol.slice(0, -1)];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user