diff --git a/.env.example b/.env.example index 58f0789..ea615e7 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,7 @@ # API CONFIG # USE_TEST_ENDPOINTS=1 # Discomment for usage of testing TikTok endpoints, may help sometimes # 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_HOST=HOSTNAME diff --git a/app/Controllers/SettingsController.php b/app/Controllers/SettingsController.php index 670a3c2..6522a11 100644 --- a/app/Controllers/SettingsController.php +++ b/app/Controllers/SettingsController.php @@ -20,4 +20,10 @@ class SettingsController { $url = Misc::url('/settings'); header("Location: {$url}"); } + + static public function api() { + $_POST['legacy'] ?? Cookies::set('api-legacy', '1'); + $url = Misc::url('/settings'); + header("Location: {$url}"); + } } diff --git a/app/Helpers/Misc.php b/app/Helpers/Misc.php index e3ddede..f4c9871 100644 --- a/app/Helpers/Misc.php +++ b/app/Helpers/Misc.php @@ -30,8 +30,9 @@ class Misc { /** * Setup of TikTok Api wrapper + * @return \TikScraper\Api|\TikScraper\Legacy */ - static public function api(): \TikScraper\Api { + static public function api() { $options = [ 'remote_signer' => self::env('SIGNER_URL', 'http://localhost:8080/signature'), 'use_test_endpoints' => self::env('USE_TEST_ENDPOINTS', false), @@ -75,8 +76,12 @@ class Misc { 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); } /** diff --git a/components/settings/api.latte b/components/settings/api.latte new file mode 100644 index 0000000..feeba44 --- /dev/null +++ b/components/settings/api.latte @@ -0,0 +1,12 @@ +
diff --git a/composer.json b/composer.json index 5a05bb4..5fc5fc6 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "pablouser1/proxitok", "description": "An alternative frontend for TikTok", - "version": "1.5.0", + "version": "2.0.0", "license": "AGPL-3.0-or-later", "type": "project", "homepage": "https://github.com/pablouser1/ProxiTok", diff --git a/composer.lock b/composer.lock index 5f054b4..cced9c7 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "f5e451a254a58bf7d512421237641801", + "content-hash": "f4a37c76a2ece697a18abfae8dcb6e9f", "packages": [ { "name": "bramus/router", @@ -306,16 +306,16 @@ }, { "name": "pablouser1/tikscraper", - "version": "v1.2.6", + "version": "v1.2.7.1", "source": { "type": "git", "url": "https://github.com/pablouser1/TikScraperPHP.git", - "reference": "1bd1d62a62d8dcca433df904162649fd04905114" + "reference": "13f1f2d220cb2a6d833cd8249ddd1eeea269c149" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/1bd1d62a62d8dcca433df904162649fd04905114", - "reference": "1bd1d62a62d8dcca433df904162649fd04905114", + "url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/13f1f2d220cb2a6d833cd8249ddd1eeea269c149", + "reference": "13f1f2d220cb2a6d833cd8249ddd1eeea269c149", "shasum": "" }, "require": { @@ -339,9 +339,9 @@ "description": "Get data from TikTok API", "support": { "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", diff --git a/public/index.php b/public/index.php index fb32eaa..b29ed8b 100644 --- a/public/index.php +++ b/public/index.php @@ -2,7 +2,7 @@ require __DIR__ . "/../vendor/autoload.php"; // LOAD DOTENV -$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); +$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..'); $dotenv->safeLoad(); // ROUTER diff --git a/routes.php b/routes.php index aa0a364..35abcfd 100644 --- a/routes.php +++ b/routes.php @@ -41,6 +41,7 @@ $router->get('/music/([^/]+)', 'MusicController@get'); $router->mount('/settings', function () use ($router) { $router->get('/', 'SettingsController@index'); $router->post('/proxy', 'SettingsController@proxy'); + $router->post('/api', 'SettingsController@api'); }); $router->get('/discover', 'DiscoverController@get'); diff --git a/views/settings.latte b/views/settings.latte index 595d687..2375748 100644 --- a/views/settings.latte +++ b/views/settings.latte @@ -8,4 +8,7 @@Proxy
{include '../components/settings/proxy.latte'} +Api
+ {include '../components/settings/api.latte'} {/block}