Force legacy mode, instance level and user level

This commit is contained in:
Pablo Ferreiro 2022-03-11 20:50:11 +01:00
parent db3799c344
commit 73dd93420f
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
9 changed files with 40 additions and 12 deletions

View file

@ -4,6 +4,7 @@
# API CONFIG # API CONFIG
# USE_TEST_ENDPOINTS=1 # Discomment for usage of testing TikTok endpoints, may help sometimes # USE_TEST_ENDPOINTS=1 # Discomment for usage of testing TikTok endpoints, may help sometimes
# SIGNER_URL="https://example.com" # External signing service # SIGNER_URL="https://example.com" # External signing service
# FORCE_LEGACY=1 # Force legacy mode for wrapper
# Proxy Config, will be used to make TikTok requests, useful if having VERIFY_CODE issues # Proxy Config, will be used to make TikTok requests, useful if having VERIFY_CODE issues
# PROXY_HOST=HOSTNAME # PROXY_HOST=HOSTNAME

View file

@ -20,4 +20,10 @@ class SettingsController {
$url = Misc::url('/settings'); $url = Misc::url('/settings');
header("Location: {$url}"); header("Location: {$url}");
} }
static public function api() {
$_POST['legacy'] ?? Cookies::set('api-legacy', '1');
$url = Misc::url('/settings');
header("Location: {$url}");
}
} }

View file

@ -30,8 +30,9 @@ class Misc {
/** /**
* Setup of TikTok Api wrapper * Setup of TikTok Api wrapper
* @return \TikScraper\Api|\TikScraper\Legacy
*/ */
static public function api(): \TikScraper\Api { static public function api() {
$options = [ $options = [
'remote_signer' => self::env('SIGNER_URL', 'http://localhost:8080/signature'), '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),
@ -75,8 +76,12 @@ class Misc {
break; break;
} }
} }
$api = new \TikScraper\Api($options, $cacheEngine);
return $api; // Legacy mode
$legacy = self::env('FORCE_LEGACY', false); // Instance level
$_COOKIE['enable_legacy'] ?? $legacy = true; // User level
return $legacy === false ? new \TikScraper\Api($options, $cacheEngine) : new \TikScraper\Legacy($options, $cacheEngine);
} }
/** /**

View file

@ -0,0 +1,12 @@
<form action="{path('/settings/api')}" method="POST">
<div class="field">
<label class="checkbox">
<input name="api-legacy" type="checkbox" checked="{isset($_COOKIE['api-legacy']) ? 'true' : 'false'}">Enable legacy mode
</label>
</div>
<div class="field">
<div class="control">
<button class="button is-success" type="submit">Submit</button>
</div>
</div>
</form>

View file

@ -1,7 +1,7 @@
{ {
"name": "pablouser1/proxitok", "name": "pablouser1/proxitok",
"description": "An alternative frontend for TikTok", "description": "An alternative frontend for TikTok",
"version": "1.5.0", "version": "2.0.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"type": "project", "type": "project",
"homepage": "https://github.com/pablouser1/ProxiTok", "homepage": "https://github.com/pablouser1/ProxiTok",

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", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "f5e451a254a58bf7d512421237641801", "content-hash": "f4a37c76a2ece697a18abfae8dcb6e9f",
"packages": [ "packages": [
{ {
"name": "bramus/router", "name": "bramus/router",
@ -306,16 +306,16 @@
}, },
{ {
"name": "pablouser1/tikscraper", "name": "pablouser1/tikscraper",
"version": "v1.2.6", "version": "v1.2.7.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/pablouser1/TikScraperPHP.git", "url": "https://github.com/pablouser1/TikScraperPHP.git",
"reference": "1bd1d62a62d8dcca433df904162649fd04905114" "reference": "13f1f2d220cb2a6d833cd8249ddd1eeea269c149"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/1bd1d62a62d8dcca433df904162649fd04905114", "url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/13f1f2d220cb2a6d833cd8249ddd1eeea269c149",
"reference": "1bd1d62a62d8dcca433df904162649fd04905114", "reference": "13f1f2d220cb2a6d833cd8249ddd1eeea269c149",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -339,9 +339,9 @@
"description": "Get data from TikTok API", "description": "Get data from TikTok API",
"support": { "support": {
"issues": "https://github.com/pablouser1/TikScraperPHP/issues", "issues": "https://github.com/pablouser1/TikScraperPHP/issues",
"source": "https://github.com/pablouser1/TikScraperPHP/tree/v1.2.6" "source": "https://github.com/pablouser1/TikScraperPHP/tree/v1.2.7.1"
}, },
"time": "2022-03-11T17:16:37+00:00" "time": "2022-03-11T19:24:56+00:00"
}, },
{ {
"name": "phpoption/phpoption", "name": "phpoption/phpoption",

View file

@ -2,7 +2,7 @@
require __DIR__ . "/../vendor/autoload.php"; require __DIR__ . "/../vendor/autoload.php";
// LOAD DOTENV // LOAD DOTENV
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
$dotenv->safeLoad(); $dotenv->safeLoad();
// ROUTER // ROUTER

View file

@ -41,6 +41,7 @@ $router->get('/music/([^/]+)', 'MusicController@get');
$router->mount('/settings', function () use ($router) { $router->mount('/settings', function () use ($router) {
$router->get('/', 'SettingsController@index'); $router->get('/', 'SettingsController@index');
$router->post('/proxy', 'SettingsController@proxy'); $router->post('/proxy', 'SettingsController@proxy');
$router->post('/api', 'SettingsController@api');
}); });
$router->get('/discover', 'DiscoverController@get'); $router->get('/discover', 'DiscoverController@get');

View file

@ -8,4 +8,7 @@
<!-- Proxy settings --> <!-- Proxy settings -->
<p class="title">Proxy</p> <p class="title">Proxy</p>
{include '../components/settings/proxy.latte'} {include '../components/settings/proxy.latte'}
<hr />
<p class="title">Api</p>
{include '../components/settings/api.latte'}
{/block} {/block}