From ec611478e3f96baf119115df5a6c8adb62f7045a Mon Sep 17 00:00:00 2001 From: Pablo Ferreiro Date: Wed, 28 Aug 2024 14:34:02 +0200 Subject: [PATCH] implemented following (AKA discover) & fyp using new endpoints --- app/Controllers/FollowingController.php | 23 +++++++++++++++ app/Controllers/ForYouController.php | 33 +++++++++++++++++++++ composer.lock | 14 ++++----- routes.php | 8 +++++ templates/views/following.latte | 39 +++++++++++++++++++++++++ templates/views/foryou.latte | 12 ++++++++ templates/views/home.latte | 10 +++++++ 7 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 app/Controllers/FollowingController.php create mode 100644 app/Controllers/ForYouController.php create mode 100644 templates/views/following.latte create mode 100644 templates/views/foryou.latte diff --git a/app/Controllers/FollowingController.php b/app/Controllers/FollowingController.php new file mode 100644 index 0000000..cf122c8 --- /dev/null +++ b/app/Controllers/FollowingController.php @@ -0,0 +1,23 @@ +following(); + $following->feed($cursor); + if ($following->ok()) { + $feed = $following->getFeed(); + Wrappers::latte('following', new FeedTemplate('Following / Discover', $feed)); + } else { + ErrorHandler::showMeta($following->error()); + } + } +} diff --git a/app/Controllers/ForYouController.php b/app/Controllers/ForYouController.php new file mode 100644 index 0000000..9a756ad --- /dev/null +++ b/app/Controllers/ForYouController.php @@ -0,0 +1,33 @@ +foryou(); + $fyp->feed(); + if ($fyp->ok()) { + $feed = $fyp->getFeed(); + Wrappers::latte('foryou', new FeedTemplate('For you', $feed)); + } else { + ErrorHandler::showMeta($fyp->error()); + } + } + + public static function rss() { + $api = Wrappers::api(); + $fyp = $api->foryou(); + $fyp->feed(); + if ($fyp->ok()) { + $feed = $fyp->getFeed(); + Misc::rss('For you'); + Wrappers::latte('rss', new RSSTemplate('For you', 'For you Page', '', Misc::url('/foryou'), $feed->items)); + } + } +} diff --git a/composer.lock b/composer.lock index 38a6943..a61268d 100644 --- a/composer.lock +++ b/composer.lock @@ -589,20 +589,20 @@ }, { "name": "pablouser1/tikscraper", - "version": "v2.6.1.2", + "version": "v2.6.2.0", "source": { "type": "git", "url": "https://github.com/pablouser1/TikScraperPHP.git", - "reference": "2322cb8ffa4d7e6a0ae295048448469f48dbe58e" + "reference": "051f3b4dd5debc05b1d49ab21e6ab831ed04ed9a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/2322cb8ffa4d7e6a0ae295048448469f48dbe58e", - "reference": "2322cb8ffa4d7e6a0ae295048448469f48dbe58e", + "url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/051f3b4dd5debc05b1d49ab21e6ab831ed04ed9a", + "reference": "051f3b4dd5debc05b1d49ab21e6ab831ed04ed9a", "shasum": "" }, "require": { - "guzzlehttp/guzzle": "^7.8", + "guzzlehttp/guzzle": "^7.9", "php": "^8.1", "php-webdriver/webdriver": "^1.12" }, @@ -628,9 +628,9 @@ "description": "Get data from TikTok API", "support": { "issues": "https://github.com/pablouser1/TikScraperPHP/issues", - "source": "https://github.com/pablouser1/TikScraperPHP/tree/v2.6.1.2" + "source": "https://github.com/pablouser1/TikScraperPHP/tree/v2.6.2.0" }, - "time": "2024-08-21T17:09:53+00:00" + "time": "2024-08-28T12:27:55+00:00" }, { "name": "php-webdriver/webdriver", diff --git a/routes.php b/routes.php index 8e71147..2d19e58 100644 --- a/routes.php +++ b/routes.php @@ -72,6 +72,14 @@ $router->get('/music/([^/]+)', 'MusicController@get'); +// For you +$router->mount('/foryou', function () use ($router) { + $router->get('/', 'ForYouController@get'); + $router->get('/rss', 'ForYouController@rss'); +}); + +$router->get('/following', 'FollowingController@get'); + // -- Settings -- // $router->mount('/settings', function () use ($router) { $router->get('/', 'SettingsController@index'); diff --git a/templates/views/following.latte b/templates/views/following.latte new file mode 100644 index 0000000..a8dcc57 --- /dev/null +++ b/templates/views/following.latte @@ -0,0 +1,39 @@ +{layout '../layouts/default.latte'} + +{block header} +

Discover

+{/block} + +{block content} +
+ {foreach $feed->items as $item} +
+ {embed '../components/card.latte'} + {block content} +
+ + {if !empty($item->info->detail->avatarLarger)} +
+
+ +
+
+ {/if} +
+

{$item->info->detail->nickname}

+

{$item->info->detail->uniqueId}

+
+
+
+

{$item->info->detail->signature}

+
+ {/block} + {block footer} + Go + {/block} + {/embed} +
+ {/foreach} +
+ {include '../components/themes/common/controls.latte', feed: $feed} +{/block} diff --git a/templates/views/foryou.latte b/templates/views/foryou.latte new file mode 100644 index 0000000..fb8c62d --- /dev/null +++ b/templates/views/foryou.latte @@ -0,0 +1,12 @@ +{layout '../layouts/default.latte'} + +{var $has_rss = true} + +{block header} +

For you

+

{include '../components/rss.latte'}

+{/block} + +{block content} + {include '../components/feed.latte'} +{/block} diff --git a/templates/views/home.latte b/templates/views/home.latte index 0c40095..25ace9f 100644 --- a/templates/views/home.latte +++ b/templates/views/home.latte @@ -28,4 +28,14 @@ {/block} {/embed} +
+
+

For you

+ Go +
+
+

Following

+ Go +
+
{/block}