temp favicon, updated scrapper and .env changes
This commit is contained in:
parent
574ae51582
commit
ebe5941fa2
18 changed files with 75 additions and 24 deletions
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
namespace App\Cache;
|
||||
|
||||
class JSONCache {
|
||||
use TikScraper\CacheInterface;
|
||||
|
||||
class JSONCache implements CacheInterface {
|
||||
private string $cache_path = __DIR__ . '/../../cache/api';
|
||||
|
||||
function __construct() {
|
||||
|
|
@ -24,7 +26,7 @@ class JSONCache {
|
|||
return is_file($filename);
|
||||
}
|
||||
|
||||
public function set(string $cache_key, mixed $data, $timeout = 3600) {
|
||||
public function set(string $cache_key, string $data, $timeout = 3600) {
|
||||
file_put_contents($this->cache_path . '/' . $cache_key . '.json', $data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
namespace App\Cache;
|
||||
|
||||
class RedisCache {
|
||||
use TikScraper\CacheInterface;
|
||||
|
||||
class RedisCache implements CacheInterface {
|
||||
private \Redis $client;
|
||||
function __construct(string $host, int $port, ?string $password) {
|
||||
$this->client = new \Redis();
|
||||
|
|
@ -21,10 +23,7 @@ class RedisCache {
|
|||
|
||||
public function get(string $cache_key): ?object {
|
||||
$data = $this->client->get($cache_key);
|
||||
if ($data) {
|
||||
return json_decode($data);
|
||||
}
|
||||
return null;
|
||||
return $data ? json_decode($data) : null;
|
||||
}
|
||||
|
||||
public function exists(string $cache_key): bool {
|
||||
|
|
|
|||
7
app/Constants/CacheMethods.php
Normal file
7
app/Constants/CacheMethods.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
namespace App\Constants;
|
||||
|
||||
class CacheMethods {
|
||||
const JSON = 'json';
|
||||
const REDIS = 'redis';
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ namespace App\Helpers;
|
|||
|
||||
use App\Cache\JSONCache;
|
||||
use App\Cache\RedisCache;
|
||||
use App\Constants\CacheMethods;
|
||||
|
||||
class Wrappers {
|
||||
/**
|
||||
|
|
@ -49,22 +50,35 @@ class Wrappers {
|
|||
* Setup of TikTok Api wrapper
|
||||
*/
|
||||
static public function api(): \TikScraper\Api {
|
||||
$method = Misc::env('API_SIGNER', '');
|
||||
$url = Misc::env('API_SIGNER_URL', '');
|
||||
if (!$method) {
|
||||
// Legacy support
|
||||
$browser_url = Misc::env('API_BROWSER_URL', '');
|
||||
if ($url) {
|
||||
$method = 'remote';
|
||||
} elseif ($browser_url) {
|
||||
$url = $browser_url;
|
||||
$method = 'browser';
|
||||
}
|
||||
}
|
||||
|
||||
$options = [
|
||||
'use_test_endpoints' => Misc::env('API_TEST_ENDPOINTS', false) || isset($_COOKIE['api-test_endpoints']) && $_COOKIE['api-test_endpoints'] === 'yes',
|
||||
'signer' => [
|
||||
'remote_url' => Misc::env('API_SIGNER_URL', ''),
|
||||
'browser_url' => Misc::env('API_BROWSER_URL', ''),
|
||||
'method' => $method,
|
||||
'url' => $url,
|
||||
'close_when_done' => false
|
||||
]
|
||||
];
|
||||
// Cache config
|
||||
$cacheEngine = false;
|
||||
$cacheEngine = null;
|
||||
if (isset($_ENV['API_CACHE'])) {
|
||||
switch ($_ENV['API_CACHE']) {
|
||||
case 'json':
|
||||
case CacheMethods::JSON:
|
||||
$cacheEngine = new JSONCache();
|
||||
break;
|
||||
case 'redis':
|
||||
case CacheMethods::REDIS:
|
||||
if (!(isset($_ENV['REDIS_URL']) || isset($_ENV['REDIS_HOST'], $_ENV['REDIS_PORT']))) {
|
||||
throw new \Exception('You need to set REDIS_URL or REDIS_HOST and REDIS_PORT to use Redis Cache!');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue