mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-03-10 20:41:04 +00:00
add api user agent customization
This commit is contained in:
parent
11c397b566
commit
034a8c540a
@ -145,7 +145,9 @@ define('NODE_RULE_SUBJECT', 'Common');
|
|||||||
define('NODE_RULE_LANGUAGES', 'All');
|
define('NODE_RULE_LANGUAGES', 'All');
|
||||||
|
|
||||||
// API
|
// API
|
||||||
define('API_VERSION', 1);
|
define('API_VERSION', '1.0.0');
|
||||||
|
|
||||||
|
define('API_USER_AGENT', WEBSITE_NAME);
|
||||||
|
|
||||||
/// Export
|
/// Export
|
||||||
define('API_EXPORT_ENABLED', true);
|
define('API_EXPORT_ENABLED', true);
|
||||||
|
@ -47,7 +47,6 @@ try
|
|||||||
// Manifest
|
// Manifest
|
||||||
$manifest =
|
$manifest =
|
||||||
[
|
[
|
||||||
'version' => API_VERSION,
|
|
||||||
'updated' => time(),
|
'updated' => time(),
|
||||||
|
|
||||||
'settings' => (object)
|
'settings' => (object)
|
||||||
@ -109,6 +108,9 @@ try
|
|||||||
|
|
||||||
'MAGNET_STOP_WORDS_SIMILAR' => (object) MAGNET_STOP_WORDS_SIMILAR,
|
'MAGNET_STOP_WORDS_SIMILAR' => (object) MAGNET_STOP_WORDS_SIMILAR,
|
||||||
|
|
||||||
|
'API_VERSION' => (string) API_VERSION,
|
||||||
|
'API_USER_AGENT' => (string) API_USER_AGENT,
|
||||||
|
|
||||||
'API_EXPORT_ENABLED' => (bool) API_EXPORT_ENABLED,
|
'API_EXPORT_ENABLED' => (bool) API_EXPORT_ENABLED,
|
||||||
'API_EXPORT_PUSH_ENABLED' => (bool) API_EXPORT_PUSH_ENABLED,
|
'API_EXPORT_PUSH_ENABLED' => (bool) API_EXPORT_PUSH_ENABLED,
|
||||||
'API_EXPORT_USERS_ENABLED' => (bool) API_EXPORT_USERS_ENABLED,
|
'API_EXPORT_USERS_ENABLED' => (bool) API_EXPORT_USERS_ENABLED,
|
||||||
|
@ -339,7 +339,7 @@ if (API_EXPORT_PUSH_ENABLED)
|
|||||||
// Send push request
|
// Send push request
|
||||||
$debug['result'][$manifest->import->push]['request'] = $request;
|
$debug['result'][$manifest->import->push]['request'] = $request;
|
||||||
|
|
||||||
$curl = new Curl($manifest->import->push, $request);
|
$curl = new Curl($manifest->import->push, API_USER_AGENT, $request);
|
||||||
|
|
||||||
if ($response = $curl->getResponse())
|
if ($response = $curl->getResponse())
|
||||||
{
|
{
|
||||||
|
@ -6,8 +6,8 @@ class Curl
|
|||||||
private $_response;
|
private $_response;
|
||||||
|
|
||||||
public function __construct(string $url,
|
public function __construct(string $url,
|
||||||
array $post = [],
|
|
||||||
string $userAgent = 'YGGtracker',
|
string $userAgent = 'YGGtracker',
|
||||||
|
array $post = [],
|
||||||
int $connectTimeout = 10,
|
int $connectTimeout = 10,
|
||||||
bool $header = false,
|
bool $header = false,
|
||||||
bool $followLocation = false,
|
bool $followLocation = false,
|
||||||
@ -17,6 +17,11 @@ class Curl
|
|||||||
{
|
{
|
||||||
$this->_connection = curl_init($url);
|
$this->_connection = curl_init($url);
|
||||||
|
|
||||||
|
if ($userAgent)
|
||||||
|
{
|
||||||
|
curl_setopt($this->_connection, CURLOPT_USERAGENT, $userAgent);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($post))
|
if (!empty($post))
|
||||||
{
|
{
|
||||||
curl_setopt($this->_connection, CURLOPT_POST, true);
|
curl_setopt($this->_connection, CURLOPT_POST, true);
|
||||||
@ -38,11 +43,6 @@ class Curl
|
|||||||
curl_setopt($this->_connection, CURLOPT_SSL_VERIFYHOST, $sslVerifyHost);
|
curl_setopt($this->_connection, CURLOPT_SSL_VERIFYHOST, $sslVerifyHost);
|
||||||
curl_setopt($this->_connection, CURLOPT_SSL_VERIFYPEER, $sslVerifyPeer);
|
curl_setopt($this->_connection, CURLOPT_SSL_VERIFYPEER, $sslVerifyPeer);
|
||||||
|
|
||||||
if ($userAgent)
|
|
||||||
{
|
|
||||||
curl_setopt($this->_connection, CURLOPT_USERAGENT, $userAgent);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->_response = curl_exec($this->_connection);
|
$this->_response = curl_exec($this->_connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user