Revert "Attempt to circumvent Cloudflare on Oatmealdome's API..."

This reverts commit b5b545ae7e.
This commit is contained in:
flash 2024-04-12 00:49:41 +00:00
parent b5b545ae7e
commit e2aa45bf3f
2 changed files with 7 additions and 26 deletions

View file

@ -2,7 +2,7 @@
namespace Satori; namespace Satori;
final class SHttp { final class SHttp {
public static function getJson(string $url, bool $pretendToBeFirefox = false): mixed { public static function getJson(string $url): mixed {
$curl = curl_init($url); $curl = curl_init($url);
curl_setopt_array($curl, [ curl_setopt_array($curl, [
CURLOPT_AUTOREFERER => true, CURLOPT_AUTOREFERER => true,
@ -17,35 +17,16 @@ final class SHttp {
CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS, CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS,
CURLOPT_CONNECTTIMEOUT => 2, CURLOPT_CONNECTTIMEOUT => 2,
CURLOPT_TIMEOUT => 5, CURLOPT_TIMEOUT => 5,
]);
if($pretendToBeFirefox) {
curl_setopt_array($curl, [
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0',
CURLOPT_HTTPHEADER => [
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language: en-GB,en;q=0.5',
'Sec-Fetch-Dest: document',
'Sec-Fetch-Mode: navigate',
'Sec-Fetch-Site: none',
'Sec-Fetch-User: ?1',
'Upgrade-Insecure-Requests: 1',
],
]);
} else {
curl_setopt_array($curl, [
CURLOPT_USERAGENT => sprintf('Satori/%s (+https://fii.moe/satori)', SAT_VERSION), CURLOPT_USERAGENT => sprintf('Satori/%s (+https://fii.moe/satori)', SAT_VERSION),
CURLOPT_HTTPHEADER => ['Accept: application/json'], CURLOPT_HTTPHEADER => ['Accept: application/json'],
]); ]);
}
$response = json_decode(curl_exec($curl), true); $response = json_decode(curl_exec($curl), true);
curl_close($curl); curl_close($curl);
return $response; return $response;
} }
public static function getJsonCached(string $url, bool $pretendToBeFirefox = false): mixed { public static function getJsonCached(string $url): mixed {
return SFileCache::for15mins($url, fn() => self::getJson($url, $pretendToBeFirefox)); return SFileCache::for15mins($url, fn() => self::getJson($url));
} }
} }

View file

@ -57,7 +57,7 @@ class Splatoon1Game implements ISplatoonGame, ISplatoonHasSchedules {
public function createLocale(string $locale): ISplatoonLocale { public function createLocale(string $locale): ISplatoonLocale {
return new Splatoon1Locale( return new Splatoon1Locale(
SHttp::getJsonCached(sprintf(self::LOCALE_URL, $locale), true) SHttp::getJsonCached(sprintf(self::LOCALE_URL, $locale))
); );
} }
@ -94,7 +94,7 @@ class Splatoon1Game implements ISplatoonGame, ISplatoonHasSchedules {
private ?array $rawSchedule = null; private ?array $rawSchedule = null;
private function getRawScheduleData(): array { private function getRawScheduleData(): array {
if($this->rawSchedule === null) if($this->rawSchedule === null)
$this->rawSchedule = SHttp::getJsonCached(self::SCHED_URL, true); $this->rawSchedule = SHttp::getJsonCached(self::SCHED_URL);
return $this->rawSchedule; return $this->rawSchedule;
} }