From 3772eabd99b10a525ef2bb98f25cc93d22cf60d7 Mon Sep 17 00:00:00 2001 From: Pablo Ferreiro Date: Sun, 6 Feb 2022 14:22:23 +0100 Subject: [PATCH] Removed Following (use RSS), allow unix for Redis --- .env.example | 5 +-- .github/workflows/tag.yaml | 25 +++++++++++++ README.md | 3 +- app/Cache/RedisCache.php | 2 +- app/Controllers/FollowingController.php | 15 -------- app/Controllers/SettingsController.php | 31 ---------------- app/Helpers/Following.php | 37 ------------------- app/Helpers/Misc.php | 20 +++++++---- app/Models/FollowingTemplate.php | 14 -------- app/Models/SettingsTemplate.php | 3 -- components/card.latte | 11 ++++++ components/feed.latte | 12 +++---- components/head.latte | 3 ++ components/navbar.latte | 1 - components/settings/following.latte | 24 ------------- composer.json | 2 +- composer.lock | 10 +++--- routes.php | 2 -- views/about.latte | 26 ++++++++++++-- views/discover.latte | 41 ++++++++++----------- views/following.latte | 10 ------ views/home.latte | 48 +++++++++++++++---------- views/settings.latte | 4 --- 23 files changed, 144 insertions(+), 205 deletions(-) create mode 100644 .github/workflows/tag.yaml delete mode 100644 app/Controllers/FollowingController.php delete mode 100644 app/Helpers/Following.php delete mode 100644 app/Models/FollowingTemplate.php create mode 100644 components/card.latte delete mode 100644 components/settings/following.latte delete mode 100644 views/following.latte diff --git a/.env.example b/.env.example index 89d2d42..60a168d 100644 --- a/.env.example +++ b/.env.example @@ -4,8 +4,9 @@ # API_CACHE=redis # Cache engine for TikTok Api, (more info on README) # Redis cache, used on Helpers\CacheEngines\RedisCache (CHOOSE ONE) -# REDIS_URL=redis://:password@host:port # If using password -# REDIS_URL=redis://host:port # If not using password +# REDIS_HOST=localhost # Host or path to unix socket +# REDIS_PORT=6379 # Set to -1 to use unix socket +# REDIS_PASSWORD=example # Leave commented for no password # JSON cache, used on Helpers\CacheEngines\JSONCache # API_CACHE_JSON=/tmp/proxitok_api # Path for JSON API Cache, leave commented for ./cache/api diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml new file mode 100644 index 0000000..08d39a9 --- /dev/null +++ b/.github/workflows/tag.yaml @@ -0,0 +1,25 @@ +name: Create Tag + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Get version + id: version + uses: notiz-dev/github-action-json-property@release + with: + path: 'composer.json' + prop_path: 'version' + - name: Create Release + uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag: v${{steps.version.outputs.prop}} + allowUpdates: true diff --git a/README.md b/README.md index 4ce1e66..5bc31e9 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,11 @@ location /proxitok/.env { * Add a NoJS version / Make the whole program without required JS * Better error handling * Make video on /video fit screen and don't overflow -* Allow custom Region/Language +* i18n ## Credits * [TikTok-API-PHP](https://github.com/ssovit/TikTok-API-PHP) (Currently using my personal fork) +* [Latte](https://github.com/nette/latte) * [bramus/router](https://github.com/bramus/router) * [PHP dotenv](https://github.com/vlucas/phpdotenv) * [Bulma](https://github.com/jgthms/bulma) and [Bulmaswatch](https://github.com/jenil/bulmaswatch) diff --git a/app/Cache/RedisCache.php b/app/Cache/RedisCache.php index de4466c..55a6dca 100644 --- a/app/Cache/RedisCache.php +++ b/app/Cache/RedisCache.php @@ -27,7 +27,7 @@ class RedisCache { return null; } - public function set(string $cache_key, mixed $data, $timeout = 3600) { + public function set(string $cache_key, array $data, $timeout = 3600) { $this->client->set($cache_key, json_encode($data), $timeout); } } diff --git a/app/Controllers/FollowingController.php b/app/Controllers/FollowingController.php deleted file mode 100644 index b235bc6..0000000 --- a/app/Controllers/FollowingController.php +++ /dev/null @@ -1,15 +0,0 @@ -render(Misc::getView('following'), new FollowingTemplate($users, $feed)); - } -} diff --git a/app/Controllers/SettingsController.php b/app/Controllers/SettingsController.php index f5c6ba5..f47561f 100644 --- a/app/Controllers/SettingsController.php +++ b/app/Controllers/SettingsController.php @@ -3,7 +3,6 @@ namespace App\Controllers; use App\Helpers\Misc; use App\Helpers\Cookies; -use App\Helpers\Following; use App\Models\SettingsTemplate; class SettingsController { @@ -21,34 +20,4 @@ class SettingsController { $url = Misc::url('/settings'); header("Location: {$url}"); } - - static public function following() { - $following = Following::getUsers(); - if (!isset($_POST['mode']) || empty($_POST['mode'])) { - die('You need to send a mode'); - } - - switch ($_POST['mode']) { - case 'add': - // Add following - array_push($following, $_POST['account']); - break; - case 'remove': - // Remove following - $index = array_search($_POST['account'], $following); - if ($index !== false) { - unset($following[$index]); - } - break; - default: - // Invalid - die('Invalid mode'); - } - - // Build string - $following_string = implode(',', $following); - Cookies::set('following', $following_string); - $url = Misc::url('/settings'); - header("Location: {$url}"); - } } diff --git a/app/Helpers/Following.php b/app/Helpers/Following.php deleted file mode 100644 index f796dae..0000000 --- a/app/Helpers/Following.php +++ /dev/null @@ -1,37 +0,0 @@ -getUserFeed($user); - if ($user_feed) { - $max = count($user_feed->items) > $max_items_per_user ? $max_items_per_user : count($user_feed->items); - for ($i = 0; $i < $max; $i++) { - $item = $user_feed->items[$i]; - array_push($items, $item); - } - } - } - } - - $feed = (object) [ - 'items' => $items, - 'hasMore' => false - ]; - return $feed; - } -}; diff --git a/app/Helpers/Misc.php b/app/Helpers/Misc.php index af0590e..4bceddf 100644 --- a/app/Helpers/Misc.php +++ b/app/Helpers/Misc.php @@ -43,14 +43,20 @@ class Misc { $cacheEngine = new JSONCache(); break; case 'redis': - if (!isset($_ENV['REDIS_URL'])) { - throw new \Exception('You need to set REDIS_URL to use Redis Cache!'); + if (!(isset($_ENV['REDIS_URL']) || isset($_ENV['REDIS_HOST'], $_ENV['REDIS_PORT']))) { + throw new \Exception('You need to set REDIS_URL or REDIS_HOST and REDIS_PORT to use Redis Cache!'); } - $url = parse_url($_ENV['REDIS_URL']); - $host = $url['host']; - $port = $url['port']; - $password = $url['pass'] ?? null; + if (isset($_ENV['REDIS_URL'])) { + $url = parse_url($_ENV['REDIS_URL']); + $host = $url['host']; + $port = $url['port']; + $password = $url['pass'] ?? null; + } else { + $host = $_ENV['REDIS_HOST']; + $port = (int) $_ENV['REDIS_PORT']; + $password = isset($_ENV['REDIS_PASSWORD']) ? $_ENV['REDIS_PASSWORD'] : null; + } $cacheEngine = new RedisCache($host, $port, $password); break; } @@ -77,7 +83,7 @@ class Misc { return \Composer\InstalledVersions::getVersion('pablouser1/proxitok'); }); // https://stackoverflow.com/a/36365553 - $latte->addFunction('number', function (int $x) { + $latte->addFunction('number', function (float $x) { if($x > 1000) { $x_number_format = number_format($x); $x_array = explode(',', $x_number_format); diff --git a/app/Models/FollowingTemplate.php b/app/Models/FollowingTemplate.php deleted file mode 100644 index cdaa127..0000000 --- a/app/Models/FollowingTemplate.php +++ /dev/null @@ -1,14 +0,0 @@ -following = $following; - } -} diff --git a/app/Models/SettingsTemplate.php b/app/Models/SettingsTemplate.php index 495d883..b0abb63 100644 --- a/app/Models/SettingsTemplate.php +++ b/app/Models/SettingsTemplate.php @@ -2,18 +2,15 @@ namespace App\Models; use App\Helpers\Cookies; -use App\Helpers\Following; /** * Exclusive for /settings */ class SettingsTemplate extends BaseTemplate { public array $proxy_elements = []; - public array $following = []; function __construct() { parent::__construct('Settings'); $this->proxy_elements = Cookies::PROXY; - $this->following = Following::getUsers(); } } diff --git a/components/card.latte b/components/card.latte new file mode 100644 index 0000000..508af23 --- /dev/null +++ b/components/card.latte @@ -0,0 +1,11 @@ +
+
+

{block title}{/block}

+
+
+ {block content}{/block} +
+
+ {block footer}{/block} +
+
diff --git a/components/feed.latte b/components/feed.latte index 383197f..fb0d89c 100644 --- a/components/feed.latte +++ b/components/feed.latte @@ -17,13 +17,11 @@ {/foreach}
- First - Back - {if $feed->hasMore} - Next - {else} - Next - {/if} + {if isset($_GET['cursor']) && $_GET['cursor'] != 0} + First + Back + {/if} + Next
diff --git a/components/head.latte b/components/head.latte index 5098883..240b59f 100644 --- a/components/head.latte +++ b/components/head.latte @@ -2,6 +2,9 @@ + + + {$title} - ProxiTok diff --git a/components/navbar.latte b/components/navbar.latte index dd0f134..9a4e143 100644 --- a/components/navbar.latte +++ b/components/navbar.latte @@ -10,7 +10,6 @@