Browse Source

add api user agent customization

main
ghost 1 year ago
parent
commit
034a8c540a
  1. 4
      example/environment/env.example.php
  2. 4
      src/crontab/export/feed.php
  3. 2
      src/crontab/export/push.php
  4. 12
      src/library/curl.php

4
example/environment/env.example.php

@ -145,7 +145,9 @@ define('NODE_RULE_SUBJECT', 'Common'); @@ -145,7 +145,9 @@ define('NODE_RULE_SUBJECT', 'Common');
define('NODE_RULE_LANGUAGES', 'All');
// API
define('API_VERSION', 1);
define('API_VERSION', '1.0.0');
define('API_USER_AGENT', WEBSITE_NAME);
/// Export
define('API_EXPORT_ENABLED', true);

4
src/crontab/export/feed.php

@ -47,7 +47,6 @@ try @@ -47,7 +47,6 @@ try
// Manifest
$manifest =
[
'version' => API_VERSION,
'updated' => time(),
'settings' => (object)
@ -109,6 +108,9 @@ try @@ -109,6 +108,9 @@ try
'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_PUSH_ENABLED' => (bool) API_EXPORT_PUSH_ENABLED,
'API_EXPORT_USERS_ENABLED' => (bool) API_EXPORT_USERS_ENABLED,

2
src/crontab/export/push.php

@ -339,7 +339,7 @@ if (API_EXPORT_PUSH_ENABLED) @@ -339,7 +339,7 @@ if (API_EXPORT_PUSH_ENABLED)
// Send push 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())
{

12
src/library/curl.php

@ -6,8 +6,8 @@ class Curl @@ -6,8 +6,8 @@ class Curl
private $_response;
public function __construct(string $url,
array $post = [],
string $userAgent = 'YGGtracker',
array $post = [],
int $connectTimeout = 10,
bool $header = false,
bool $followLocation = false,
@ -17,6 +17,11 @@ class Curl @@ -17,6 +17,11 @@ class Curl
{
$this->_connection = curl_init($url);
if ($userAgent)
{
curl_setopt($this->_connection, CURLOPT_USERAGENT, $userAgent);
}
if (!empty($post))
{
curl_setopt($this->_connection, CURLOPT_POST, true);
@ -38,11 +43,6 @@ class Curl @@ -38,11 +43,6 @@ class Curl
curl_setopt($this->_connection, CURLOPT_SSL_VERIFYHOST, $sslVerifyHost);
curl_setopt($this->_connection, CURLOPT_SSL_VERIFYPEER, $sslVerifyPeer);
if ($userAgent)
{
curl_setopt($this->_connection, CURLOPT_USERAGENT, $userAgent);
}
$this->_response = curl_exec($this->_connection);
}

Loading…
Cancel
Save