Instance-level proxy and test endpoint fix
This commit is contained in:
parent
279a4f50c6
commit
d60e4400a2
9 changed files with 42 additions and 33 deletions
|
|
@ -8,7 +8,7 @@ use App\Models\SettingsTemplate;
|
|||
class SettingsController {
|
||||
static public function index() {
|
||||
$latte = Misc::latte();
|
||||
$latte->render(Misc::getView('settings'), new SettingsTemplate());
|
||||
$latte->render(Misc::getView('settings'), new SettingsTemplate);
|
||||
}
|
||||
|
||||
static public function proxy() {
|
||||
|
|
|
|||
|
|
@ -13,8 +13,9 @@ class UserController {
|
|||
$feed = $api->getUserFeed($username, $cursor);
|
||||
if ($feed->meta->success) {
|
||||
if ($feed->info->detail->privateAccount) {
|
||||
http_response_code(400);
|
||||
http_response_code(403);
|
||||
echo 'Private account detected! Not supported';
|
||||
exit;
|
||||
}
|
||||
$latte = Misc::latte();
|
||||
$latte->render(Misc::getView('user'), new FeedTemplate($feed->info->detail->nickname, $feed));
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
namespace App\Helpers;
|
||||
|
||||
class Cookies {
|
||||
const PROXY = ['proxy-host', 'proxy-port', 'proxy-username', 'proxy-password'];
|
||||
const PROXY = ['host', 'port', 'user', 'password'];
|
||||
|
||||
static public function get(string $name): string {
|
||||
static public function get(string $name): ?string {
|
||||
if (isset($_COOKIE[$name]) && !empty($_COOKIE[$name])) {
|
||||
return $_COOKIE[$name];
|
||||
}
|
||||
return '';
|
||||
return null;
|
||||
}
|
||||
|
||||
static public function exists(string $name): bool {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class Misc {
|
|||
return self::env('APP_URL', '') . $endpoint;
|
||||
}
|
||||
|
||||
static public function env(string $key, string $default_value): string {
|
||||
static public function env(string $key, $default_value) {
|
||||
return $_ENV[$key] ?? $default_value;
|
||||
}
|
||||
|
||||
|
|
@ -34,16 +34,23 @@ class Misc {
|
|||
static public function api(): \TikScraper\Api {
|
||||
$options = [
|
||||
'remote_signer' => self::env('SIGNER_URL', 'http://localhost:8080/signature'),
|
||||
'use_test_endpoints' => self::env('USE_TEST_ENDPOINTS', false)
|
||||
'use_test_endpoints' => self::env('USE_TEST_ENDPOINTS', false),
|
||||
// Instance level proxy config
|
||||
'proxy' => [
|
||||
'host' => self::env('PROXY_HOST', null),
|
||||
'port' => self::env('PROXY_PORT', null),
|
||||
'user' => self::env('PROXY_USER', null),
|
||||
'password' => self::env('PROXY_PASSWORD', null)
|
||||
]
|
||||
];
|
||||
$cacheEngine = false;
|
||||
// Proxy config
|
||||
// User level proxy config, will overwrite instance config
|
||||
foreach(Cookies::PROXY as $proxy_element) {
|
||||
if (isset($_COOKIE[$proxy_element])) {
|
||||
$options['proxy'][$proxy_element] = $_COOKIE[$proxy_element];
|
||||
}
|
||||
}
|
||||
// Cache config
|
||||
$cacheEngine = false;
|
||||
if (isset($_ENV['API_CACHE'])) {
|
||||
switch ($_ENV['API_CACHE']) {
|
||||
case 'json':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue