mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 12:21:31 +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 tunnel = require('tunnel');
|
||||
const got = require('got');
|
||||
const queryString = require('query-string');
|
||||
|
||||
let agent = null;
|
||||
if (config.proxy && config.proxy.protocol && config.proxy.host && config.proxy.port) {
|
||||
@@ -74,12 +75,24 @@ const custom = got.extend({
|
||||
return error;
|
||||
},
|
||||
],
|
||||
beforeRequest: [
|
||||
init: [
|
||||
(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') {
|
||||
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)) {
|
||||
options.agent = agent[options.protocol.slice(0, -1)];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user