diff --git a/README.md b/README.md index 9cad266..0d8eb5e 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,6 @@ Apply to: Main window (address bar) * Fix embed styling * Fix crash when invalid vm.tiktok.com/CODE or www.tiktok.com/t/CODE is provided * Add custom amount of videos per page -* Discover does not work ## Credits [@TheFrenchGhosty](https://github.com/TheFrenchGhosty): Initial Dockerfile and fixes to a usable state. You can check his Docker image [here](https://github.com/PussTheCat-org/docker-proxitok-quay) on Github or [here](https://quay.io/repository/pussthecatorg/proxitok) on Quay diff --git a/app/Controllers/DiscoverController.php b/app/Controllers/DiscoverController.php index 2087138..7169c85 100644 --- a/app/Controllers/DiscoverController.php +++ b/app/Controllers/DiscoverController.php @@ -14,7 +14,7 @@ class DiscoverController { $latte = Wrappers::latte(); $latte->render(Misc::getView('discover'), new FeedTemplate('Discover', $feed)); } else { - ErrorHandler::show($feed->meta); + ErrorHandler::showMeta($feed->meta); } } } diff --git a/app/Controllers/EmbedController.php b/app/Controllers/EmbedController.php index 7e78741..7dfe694 100644 --- a/app/Controllers/EmbedController.php +++ b/app/Controllers/EmbedController.php @@ -9,12 +9,14 @@ use App\Models\VideoTemplate; class EmbedController { static public function v2(int $id) { $api = Wrappers::api(); - $feed = $api->getVideoByID($id); - if ($feed->meta->success) { + $video = $api->video($id); + $video->feed(); + if ($video->ok()) { + $data = $video->getFull(); $latte = Wrappers::latte(); - $latte->render(Misc::getView('video'), new VideoTemplate($feed->items[0], $feed->info->detail, true)); + $latte->render(Misc::getView('video'), new VideoTemplate($data->feed->items[0], $data->info->detail, true)); } else { - ErrorHandler::show($feed->meta); + ErrorHandler::showMeta($video->error()); } } } diff --git a/app/Controllers/MusicController.php b/app/Controllers/MusicController.php index c0b80e6..a43435a 100644 --- a/app/Controllers/MusicController.php +++ b/app/Controllers/MusicController.php @@ -18,7 +18,7 @@ class MusicController { $latte = Wrappers::latte(); $latte->render(Misc::getView('music'), new FullTemplate('Music', $data)); } else { - ErrorHandler::show($music->error()); + ErrorHandler::showMeta($music->error()); } } } diff --git a/app/Controllers/RedirectController.php b/app/Controllers/RedirectController.php index 2f7158a..b1535db 100644 --- a/app/Controllers/RedirectController.php +++ b/app/Controllers/RedirectController.php @@ -15,7 +15,7 @@ class RedirectController { case 'url': $endpoint = self::to_endpoint($term); if (!$endpoint) { - echo 'Invalid or unknown TikTok URL format'; + ErrorHandler::showText(400, 'Invalid TikTok URL'); return; } break; diff --git a/app/Controllers/TagController.php b/app/Controllers/TagController.php index eca0345..99ac1a8 100644 --- a/app/Controllers/TagController.php +++ b/app/Controllers/TagController.php @@ -18,7 +18,7 @@ class TagController { $latte = Wrappers::latte(); $latte->render(Misc::getView('tag'), new FullTemplate('Tag', $data)); } else { - ErrorHandler::show($hashtag->error()); + ErrorHandler::showMeta($hashtag->error()); } } diff --git a/app/Controllers/TrendingController.php b/app/Controllers/TrendingController.php index 587b330..6c4e5a9 100644 --- a/app/Controllers/TrendingController.php +++ b/app/Controllers/TrendingController.php @@ -20,7 +20,7 @@ class TrendingController { $latte = Wrappers::latte(); $latte->render(Misc::getView('trending'), new FeedTemplate('Trending', $feed)); } else { - ErrorHandler::show($trending->error()); + ErrorHandler::showMeta($trending->error()); } } diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 5e0b61b..7ece1d9 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -17,14 +17,13 @@ class UserController { if ($user->ok()) { $data = $user->getFull(); if ($data->info->detail->privateAccount) { - http_response_code(403); - echo 'Private account detected! Not supported'; - exit; + ErrorHandler::showText(401, "Private account detected! Not supported"); + return; } $latte = Wrappers::latte(); $latte->render(Misc::getView('user'), new FullTemplate($data->info->detail->nickname, $data)); } else { - ErrorHandler::show($user->error()); + ErrorHandler::showMeta($user->error()); } } @@ -37,7 +36,7 @@ class UserController { $latte = Wrappers::latte(); $latte->render(Misc::getView('video'), new VideoTemplate($data->feed->items[0], $data->info->detail)); } else { - ErrorHandler::show($video->error()); + ErrorHandler::showMeta($video->error()); } } diff --git a/app/Helpers/ErrorHandler.php b/app/Helpers/ErrorHandler.php index 4010182..3bd0d64 100644 --- a/app/Helpers/ErrorHandler.php +++ b/app/Helpers/ErrorHandler.php @@ -5,9 +5,15 @@ use App\Models\ErrorTemplate; use TikScraper\Models\Meta; class ErrorHandler { - static public function show(Meta $meta) { + static public function showMeta(Meta $meta) { http_response_code($meta->http_code); $latte = Wrappers::latte(); - $latte->render(Misc::getView('error'), new ErrorTemplate($meta)); + $latte->render(Misc::getView('error'), new ErrorTemplate($meta->http_code, $meta->tiktok_msg, $meta->tiktok_code)); + } + + static public function showText(int $code, string $msg) { + http_response_code($code); + $latte = Wrappers::latte(); + $latte->render(Misc::getView('error'), new ErrorTemplate($code, $msg)); } } diff --git a/app/Models/ErrorTemplate.php b/app/Models/ErrorTemplate.php index ad38f9f..258e1a1 100644 --- a/app/Models/ErrorTemplate.php +++ b/app/Models/ErrorTemplate.php @@ -1,13 +1,16 @@ error = $error; + $this->http_code = $http_code; + $this->msg = $msg; + $this->tiktok_code = $tiktok_code; } } diff --git a/components/navbar.latte b/components/navbar.latte index cc9cf60..3f302da 100644 --- a/components/navbar.latte +++ b/components/navbar.latte @@ -1,5 +1,6 @@