From c62df9d631a5653d55d4150f81e6ca4cd3c0aca0 Mon Sep 17 00:00:00 2001 From: Pablo Ferreiro Date: Fri, 11 Mar 2022 23:18:26 +0100 Subject: [PATCH] That... Could have gone better --- app/Cache/JSONCache.php | 5 +++++ app/Cache/RedisCache.php | 8 ++++++-- app/Controllers/TagController.php | 6 +++--- app/Controllers/UserController.php | 4 ++-- composer.json | 2 +- composer.lock | 2 +- views/music.latte | 6 +++--- views/tag.latte | 8 ++++---- views/trending.latte | 2 +- views/user.latte | 12 ++++++------ views/video.latte | 16 ---------------- 11 files changed, 32 insertions(+), 39 deletions(-) diff --git a/app/Cache/JSONCache.php b/app/Cache/JSONCache.php index 7b16c60..3930a64 100644 --- a/app/Cache/JSONCache.php +++ b/app/Cache/JSONCache.php @@ -24,6 +24,11 @@ class JSONCache { return false; } + public function exists(string $cache_key): bool { + $filename = $this->cache_path . '/' . $cache_key . '.json'; + return is_file($filename); + } + public function set(string $cache_key, mixed $data, $timeout = 3600) { file_put_contents($this->cache_path . '/' . $cache_key . '.json', json_encode([ 'data' => $data, diff --git a/app/Cache/RedisCache.php b/app/Cache/RedisCache.php index 55a6dca..82063a0 100644 --- a/app/Cache/RedisCache.php +++ b/app/Cache/RedisCache.php @@ -27,7 +27,11 @@ class RedisCache { return null; } - public function set(string $cache_key, array $data, $timeout = 3600) { - $this->client->set($cache_key, json_encode($data), $timeout); + public function exists(string $cache_key): bool { + return $this->client->exists($cache_key); + } + + public function set(string $cache_key, string $data, $timeout = 3600) { + $this->client->set($cache_key, $data, $timeout); } } diff --git a/app/Controllers/TagController.php b/app/Controllers/TagController.php index 5ed8c26..077b628 100644 --- a/app/Controllers/TagController.php +++ b/app/Controllers/TagController.php @@ -10,7 +10,7 @@ class TagController { static public function get(string $name) { $cursor = Misc::getCursor(); $api = Misc::api(); - $feed = $api->getChallengeFeed($name, $cursor); + $feed = $api->getHashtagFeed($name, $cursor); if ($feed->meta->success) { $latte = Misc::latte(); $latte->render(Misc::getView('tag'), new FeedTemplate('Tag', $feed)); @@ -21,9 +21,9 @@ class TagController { static public function rss(string $name) { $api = Misc::api(); - $feed = $api->getChallengeFeed($name); + $feed = $api->getHashtagFeed($name); if ($feed->meta->success) { - $feed = RSS::build("/tag/{$name}", "{$name} Tag", $feed->info->detail->challenge->desc, $feed->items); + $feed = RSS::build("/tag/{$name}", "{$name} Tag", $feed->info->detail->desc, $feed->items); // Setup headers RSS::setHeaders('tag.rss'); echo $feed; diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 47c106f..3912f7d 100644 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -18,7 +18,7 @@ class UserController { exit; } $latte = Misc::latte(); - $latte->render(Misc::getView('user'), new FeedTemplate($feed->info->detail->user->nickname, $feed)); + $latte->render(Misc::getView('user'), new FeedTemplate($feed->info->detail->nickname, $feed)); } else { ErrorHandler::show($feed->meta); } @@ -28,7 +28,7 @@ class UserController { $api = Misc::api(); $feed = $api->getUserFeed($username); if ($feed->meta->success) { - $feed = RSS::build('/@'.$username, $feed->info->detail->user->nickname, $feed->info->detail->user->signature, $feed->items); + $feed = RSS::build('/@'.$username, $feed->info->detail->nickname, $feed->info->detail->signature, $feed->items); // Setup headers RSS::setHeaders('user.rss'); echo $feed; diff --git a/composer.json b/composer.json index 44e84b1..5ff0c67 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "pablouser1/proxitok", "description": "An alternative frontend for TikTok", - "version": "2.0.0.1", + "version": "2.0.0.2", "license": "AGPL-3.0-or-later", "type": "project", "homepage": "https://github.com/pablouser1/ProxiTok", diff --git a/composer.lock b/composer.lock index bfca1fb..a343fb5 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": "ee56c4949779c846be760de720c1eaf6", + "content-hash": "2e80bafe776f5af404ce602d03f554b6", "packages": [ { "name": "bramus/router", diff --git a/views/music.latte b/views/music.latte index 99cea03..04b6806 100644 --- a/views/music.latte +++ b/views/music.latte @@ -1,9 +1,9 @@ {layout '../layouts/default.latte'} {block header} -

{$feed->info->detail->music->title}

-

{$feed->info->detail->music->desc}

-

Videos: {number($feed->info->detail->stats->videoCount)}

+

{$feed->info->detail->title}

+

{$feed->info->detail->desc}

+

Videos: {number($feed->info->stats->videoCount)}

{/block} {block content} diff --git a/views/tag.latte b/views/tag.latte index 9313214..fc39f04 100644 --- a/views/tag.latte +++ b/views/tag.latte @@ -1,10 +1,10 @@ {layout '../layouts/default.latte'} {block header} -

{$feed->info->detail->challenge->title}

-

{$feed->info->detail->challenge->desc}

-

Videos: {number($feed->info->detail->stats->videoCount)} / Views: {number($feed->info->detail->stats->viewCount)}

- RSS +

{$feed->info->detail->title}

+

{$feed->info->detail->desc}

+

Videos: {number($feed->info->stats->videoCount)} / Views: {number($feed->info->stats->viewCount)}

+ RSS {/block} {block content} diff --git a/views/trending.latte b/views/trending.latte index 7bed5ef..7be2963 100644 --- a/views/trending.latte +++ b/views/trending.latte @@ -2,7 +2,7 @@ {block header}

Trending

- RSS + RSS {/block} {block content} diff --git a/views/user.latte b/views/user.latte index bb47b5b..7e2b56c 100644 --- a/views/user.latte +++ b/views/user.latte @@ -2,13 +2,13 @@ {block header}
- +
-

{$feed->info->detail->user->uniqueId}'s profile

-

{$feed->info->detail->user->signature}

-

Following: {number($feed->info->detail->stats->followingCount)} / Followers: {number($feed->info->detail->stats->followerCount)}

-

Hearts: {number($feed->info->detail->stats->heartCount)} / Videos: {$feed->info->detail->stats->videoCount}

- RSS +

{$feed->info->detail->uniqueId}'s profile

+

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

+

Following: {number($feed->info->stats->followingCount)} / Followers: {number($feed->info->stats->followerCount)}

+

Hearts: {number($feed->info->stats->heartCount)} / Videos: {$feed->info->stats->videoCount}

+ RSS {/block} {block content} diff --git a/views/video.latte b/views/video.latte index 2692f9e..4c117d6 100644 --- a/views/video.latte +++ b/views/video.latte @@ -4,18 +4,12 @@ {do $item = $feed->items[0]}
-<<<<<<< HEAD
-<<<<<<< HEAD

Video by {$feed->info->detail->uniqueId}

{$item->desc}

Played {number($feed->info->stats->playCount)} times

@@ -34,16 +28,6 @@

{$item->music->title}

-======= -

Video by {$item->info->detail->user->uniqueId}

-

{$item->items[0]->desc}

-

Played {number($item->info->detail->stats->playCount)} times

-

Shared {number($item->info->detail->stats->shareCount)} times / {number($item->info->detail->stats->commentCount)} comments

-
- Download video -

{$item->items[0]->music->title}

- ->>>>>>> master