That... Could have gone better

This commit is contained in:
Pablo Ferreiro 2022-03-11 23:18:26 +01:00
parent 605e204453
commit c62df9d631
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
11 changed files with 32 additions and 39 deletions

View file

@ -24,6 +24,11 @@ class JSONCache {
return false; 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) { public function set(string $cache_key, mixed $data, $timeout = 3600) {
file_put_contents($this->cache_path . '/' . $cache_key . '.json', json_encode([ file_put_contents($this->cache_path . '/' . $cache_key . '.json', json_encode([
'data' => $data, 'data' => $data,

View file

@ -27,7 +27,11 @@ class RedisCache {
return null; return null;
} }
public function set(string $cache_key, array $data, $timeout = 3600) { public function exists(string $cache_key): bool {
$this->client->set($cache_key, json_encode($data), $timeout); return $this->client->exists($cache_key);
}
public function set(string $cache_key, string $data, $timeout = 3600) {
$this->client->set($cache_key, $data, $timeout);
} }
} }

View file

@ -10,7 +10,7 @@ class TagController {
static public function get(string $name) { static public function get(string $name) {
$cursor = Misc::getCursor(); $cursor = Misc::getCursor();
$api = Misc::api(); $api = Misc::api();
$feed = $api->getChallengeFeed($name, $cursor); $feed = $api->getHashtagFeed($name, $cursor);
if ($feed->meta->success) { if ($feed->meta->success) {
$latte = Misc::latte(); $latte = Misc::latte();
$latte->render(Misc::getView('tag'), new FeedTemplate('Tag', $feed)); $latte->render(Misc::getView('tag'), new FeedTemplate('Tag', $feed));
@ -21,9 +21,9 @@ class TagController {
static public function rss(string $name) { static public function rss(string $name) {
$api = Misc::api(); $api = Misc::api();
$feed = $api->getChallengeFeed($name); $feed = $api->getHashtagFeed($name);
if ($feed->meta->success) { 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 // Setup headers
RSS::setHeaders('tag.rss'); RSS::setHeaders('tag.rss');
echo $feed; echo $feed;

View file

@ -18,7 +18,7 @@ class UserController {
exit; exit;
} }
$latte = Misc::latte(); $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 { } else {
ErrorHandler::show($feed->meta); ErrorHandler::show($feed->meta);
} }
@ -28,7 +28,7 @@ class UserController {
$api = Misc::api(); $api = Misc::api();
$feed = $api->getUserFeed($username); $feed = $api->getUserFeed($username);
if ($feed->meta->success) { 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 // Setup headers
RSS::setHeaders('user.rss'); RSS::setHeaders('user.rss');
echo $feed; echo $feed;

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": "2.0.0.1", "version": "2.0.0.2",
"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",

2
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": "ee56c4949779c846be760de720c1eaf6", "content-hash": "2e80bafe776f5af404ce602d03f554b6",
"packages": [ "packages": [
{ {
"name": "bramus/router", "name": "bramus/router",

View file

@ -1,9 +1,9 @@
{layout '../layouts/default.latte'} {layout '../layouts/default.latte'}
{block header} {block header}
<p class="title">{$feed->info->detail->music->title}</p> <p class="title">{$feed->info->detail->title}</p>
<p class="subtitle">{$feed->info->detail->music->desc}</p> <p class="subtitle">{$feed->info->detail->desc}</p>
<p>Videos: {number($feed->info->detail->stats->videoCount)}</p> <p>Videos: {number($feed->info->stats->videoCount)}</p>
{/block} {/block}
{block content} {block content}

View file

@ -1,10 +1,10 @@
{layout '../layouts/default.latte'} {layout '../layouts/default.latte'}
{block header} {block header}
<p class="title">{$feed->info->detail->challenge->title}</p> <p class="title">{$feed->info->detail->title}</p>
<p class="subtitle">{$feed->info->detail->challenge->desc}</p> <p class="subtitle">{$feed->info->detail->desc}</p>
<p>Videos: {number($feed->info->detail->stats->videoCount)} / Views: {number($feed->info->detail->stats->viewCount)}</p> <p>Videos: {number($feed->info->stats->videoCount)} / Views: {number($feed->info->stats->viewCount)}</p>
<a href="{path('tag/' . $feed->info->detail->challenge->title . '/rss')}">RSS</a> <a href="{path('tag/' . $feed->info->detail->title . '/rss')}">RSS</a>
{/block} {/block}
{block content} {block content}

View file

@ -2,7 +2,7 @@
{block header} {block header}
<p class="title">Trending</p> <p class="title">Trending</p>
<a href="{path('trending/rss')}">RSS</a> <a href="{path('/trending/rss')}">RSS</a>
{/block} {/block}
{block content} {block content}

View file

@ -2,13 +2,13 @@
{block header} {block header}
<figure class="figure is-96x96"> <figure class="figure is-96x96">
<img src="{path('/stream?url=' . urlencode($feed->info->detail->user->avatarThumb))}" /> <img src="{path('/stream?url=' . urlencode($feed->info->detail->avatarThumb))}" />
</figure> </figure>
<p class="title">{$feed->info->detail->user->uniqueId}'s profile</p> <p class="title">{$feed->info->detail->uniqueId}'s profile</p>
<p class="subtitle">{$feed->info->detail->user->signature}</p> <p class="subtitle">{$feed->info->detail->signature}</p>
<p>Following: {number($feed->info->detail->stats->followingCount)} / Followers: {number($feed->info->detail->stats->followerCount)}</p> <p>Following: {number($feed->info->stats->followingCount)} / Followers: {number($feed->info->stats->followerCount)}</p>
<p>Hearts: {number($feed->info->detail->stats->heartCount)} / Videos: {$feed->info->detail->stats->videoCount}</p> <p>Hearts: {number($feed->info->stats->heartCount)} / Videos: {$feed->info->stats->videoCount}</p>
<a href="{path('/@' . $feed->info->detail->user->uniqueId . '/rss')}">RSS</a> <a href="{path('/@' . $feed->info->detail->uniqueId . '/rss')}">RSS</a>
{/block} {/block}
{block content} {block content}

View file

@ -4,18 +4,12 @@
{do $item = $feed->items[0]} {do $item = $feed->items[0]}
<div class="columns is-centered is-vcentered"> <div class="columns is-centered is-vcentered">
<div class="column"> <div class="column">
<<<<<<< HEAD
<video controls poster="{path('/stream?url=' . urlencode($item->video->originCover))}"> <video controls poster="{path('/stream?url=' . urlencode($item->video->originCover))}">
<source src="{path('/stream?url=' . urlencode($item->video->playAddr))}" type="video/mp4" /> <source src="{path('/stream?url=' . urlencode($item->video->playAddr))}" type="video/mp4" />
=======
<video controls poster="{path('/stream?url=' . urlencode($item->items[0]->video->originCover))}">
<source src="{path('/stream?url=' . urlencode($item->items[0]->video->playAddr))}" type="video/mp4" />
>>>>>>> master
</video> </video>
</div> </div>
<div class="column has-text-centered"> <div class="column has-text-centered">
<div class="box"> <div class="box">
<<<<<<< HEAD
<p class="title">Video by <a href="{path('/@'.$feed->info->detail->uniqueId)}">{$feed->info->detail->uniqueId}</a></p> <p class="title">Video by <a href="{path('/@'.$feed->info->detail->uniqueId)}">{$feed->info->detail->uniqueId}</a></p>
<p class="subtitle">{$item->desc}</p> <p class="subtitle">{$item->desc}</p>
<p>Played {number($feed->info->stats->playCount)} times</p> <p>Played {number($feed->info->stats->playCount)} times</p>
@ -34,16 +28,6 @@
</div> </div>
<p>{$item->music->title}</p> <p>{$item->music->title}</p>
<audio src="{path('/stream?url=' . urlencode($item->music->playUrl))}" controls preload="none"></audio> <audio src="{path('/stream?url=' . urlencode($item->music->playUrl))}" controls preload="none"></audio>
=======
<p class="title">Video by <a href="{path('/@'.$item->info->detail->user->uniqueId)}">{$item->info->detail->user->uniqueId}</a></p>
<p class="subtitle">{$item->items[0]->desc}</p>
<p>Played {number($item->info->detail->stats->playCount)} times</p>
<p>Shared {number($item->info->detail->stats->shareCount)} times / {number($item->info->detail->stats->commentCount)} comments</p>
<hr />
<a href="{path('/stream?url=' . urlencode($item->items[0]->video->playAddr) . '&download=1')}" class="button is-info">Download video</a>
<p>{$item->items[0]->music->title}</p>
<audio src="{path('/stream?url=' . urlencode($item->items[0]->music->playUrl))}" controls preload="none"></audio>
>>>>>>> master
</div> </div>
</div> </div>
</div> </div>