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', ''),

View file

@ -1,7 +1,19 @@
{embed '../form.latte', path: '/settings/api', method: 'POST', submit: true}
{block fields}
{var $use_endpoints = \App\Helpers\Cookies::check('api-test_endpoints', 'yes')}
<div class="field">
<p>TODO</p>
<label class="label">Use test endpoints</label>
<div class="control">
<label class="radio">
<input type="radio" name="api-test_endpoints" value="yes" n:attr="checked => $use_endpoints" />
<span>Yes</span>
</label>
<label class="radio">
<input type="radio" name="api-test_endpoints" value="no" n:attr="checked => !$use_endpoints" />
<span>No</span>
</label>
</div>
<p class="help">This <i>may</i> help bypass rate limits</p>
</div>
{/block}
{/embed}

View file

@ -1,7 +1,7 @@
{
"name": "pablouser1/proxitok",
"description": "An alternative frontend for TikTok",
"version": "2.3.1.0",
"version": "2.3.2.0",
"license": "AGPL-3.0-or-later",
"type": "project",
"authors": [

14
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "387c0d1d767d85d4d08fadad9b583080",
"content-hash": "5c6b3247dd4d2f94f65a47d2eb39717a",
"packages": [
{
"name": "bramus/router",
@ -117,16 +117,16 @@
},
{
"name": "latte/latte",
"version": "v2.11.4",
"version": "v2.11.5",
"source": {
"type": "git",
"url": "https://github.com/nette/latte.git",
"reference": "3a5ed09d92b3bb2c428814bb919c2f8637bc49b1"
"reference": "89e647e51213af8a270fe9903b8735a2f6c83ad1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/latte/zipball/3a5ed09d92b3bb2c428814bb919c2f8637bc49b1",
"reference": "3a5ed09d92b3bb2c428814bb919c2f8637bc49b1",
"url": "https://api.github.com/repos/nette/latte/zipball/89e647e51213af8a270fe9903b8735a2f6c83ad1",
"reference": "89e647e51213af8a270fe9903b8735a2f6c83ad1",
"shasum": ""
},
"require": {
@ -195,9 +195,9 @@
],
"support": {
"issues": "https://github.com/nette/latte/issues",
"source": "https://github.com/nette/latte/tree/v2.11.4"
"source": "https://github.com/nette/latte/tree/v2.11.5"
},
"time": "2022-05-30T13:34:15+00:00"
"time": "2022-06-26T10:12:18+00:00"
},
{
"name": "m1/env",

View file

@ -72,9 +72,9 @@ glob-parent@~5.1.2:
is-glob "^4.0.1"
immutable@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.0.0.tgz#b86f78de6adef3608395efb269a91462797e2c23"
integrity sha512-zIE9hX70qew5qTUjSS7wi1iwj/l7+m54KWU247nhM3v806UdGj1yDndXj+IOYxxtW9zyLI+xqFNZjTuDaLUqFw==
version "4.1.0"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.1.0.tgz#f795787f0db780183307b9eb2091fcac1f6fafef"
integrity sha512-oNkuqVTA8jqG1Q6c+UglTOD1xhC1BtjKI7XkCXRkZHrN5m18/XsnUp8Q89GkQO/z+0WjonSvl0FLhDYftp46nQ==
is-binary-path@~2.1.0:
version "2.1.0"
@ -86,7 +86,7 @@ is-binary-path@~2.1.0:
is-extglob@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=
integrity sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==
is-glob@^4.0.1, is-glob@~4.0.1:
version "4.0.3"
@ -118,9 +118,9 @@ readdirp@~3.6.0:
picomatch "^2.2.1"
sass@^1.46.0:
version "1.52.1"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.52.1.tgz#554693da808543031f9423911d62c60a1acf7889"
integrity sha512-fSzYTbr7z8oQnVJ3Acp9hV80dM1fkMN7mSD/25mpcct9F7FPBMOI8krEYALgU1aZoqGhQNhTPsuSmxjnIvAm4Q==
version "1.53.0"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.53.0.tgz#eab73a7baac045cc57ddc1d1ff501ad2659952eb"
integrity sha512-zb/oMirbKhUgRQ0/GFz8TSAwRq2IlR29vOUJZOx0l8sV+CkHUfHa4u5nqrG+1VceZp7Jfj59SVW9ogdhTvJDcQ==
dependencies:
chokidar ">=3.0.0 <4.0.0"
immutable "^4.0.0"

View file

@ -9,7 +9,8 @@
{block content}
<p class="title">About this instance</p>
<p>Version: {version()}</p>
<p>Frontend version: {version_frontend()}</p>
<p>Scraper version: {version_scraper()}</p>
<hr />
<p class="title">Why would I want to use ProxiTok?</p>
<p>