User now can use test endpoints

This commit is contained in:
Pablo Ferreiro 2022-06-28 20:41:51 +02:00
parent 9acc40618a
commit bc3777d74c
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
8 changed files with 48 additions and 24 deletions

View file

@ -12,11 +12,6 @@ class SettingsController {
$latte->render(Misc::getView('settings'), new BaseTemplate('Settings'));
}
static private function redirect() {
$url = Misc::url('/settings');
header("Location: {$url}");
}
static public function general() {
if (isset($_POST['theme'])) {
$theme = $_POST['theme'];
@ -26,6 +21,15 @@ class SettingsController {
}
static public function api() {
// TODO, ADD COUNT
if (isset($_POST['api-test_endpoints'])) {
$test_endpoints = $_POST['api-test_endpoints'];
Cookies::set('api-test_endpoints', $test_endpoints);
}
self::redirect();
}
static private function redirect() {
$url = Misc::url('/settings');
header("Location: {$url}");
}
}

View file

@ -23,6 +23,10 @@ class Cookies {
return isset($_COOKIE[$name]);
}
static public function check(string $name, string $value): bool {
return self::exists($name) && $_COOKIE[$name] === $value;
}
static public function set(string $name, string $value) {
setcookie($name, $value, time()+60*60*24*30, '/', '', isset($_SERVER['HTTPS']), true);
}

View file

@ -19,9 +19,12 @@ class Wrappers {
return Misc::url($endpoint);
});
// Version being used
$latte->addFunction('version', function (): string {
$latte->addFunction('version_frontend', function (): string {
return \Composer\InstalledVersions::getVersion('pablouser1/proxitok');
});
$latte->addFunction('version_scraper', function (): string {
return \Composer\InstalledVersions::getVersion('pablouser1/tikscraper');
});
$latte->addFunction('theme', function(): string {
return Cookies::theme();
});
@ -47,7 +50,7 @@ class Wrappers {
*/
static public function api(): \TikScraper\Api {
$options = [
'use_test_endpoints' => Misc::env('API_TEST_ENDPOINTS', false),
'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', ''),