Project structure change
This commit is contained in:
parent
bd1642957c
commit
837f126021
29 changed files with 298 additions and 254 deletions
15
app/Controllers/FollowingController.php
Normal file
15
app/Controllers/FollowingController.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Helpers\Following;
|
||||
use App\Helpers\Misc;
|
||||
use App\Models\FollowingTemplate;
|
||||
|
||||
class FollowingController {
|
||||
static public function get() {
|
||||
$users = Following::getUsers();
|
||||
$feed = Following::getAll($users);
|
||||
$latte = Misc::latte();
|
||||
$latte->render(Misc::getView('following'), new FollowingTemplate($users, $feed));
|
||||
}
|
||||
}
|
||||
21
app/Controllers/MusicController.php
Normal file
21
app/Controllers/MusicController.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Helpers\ErrorHandler;
|
||||
use App\Helpers\Misc;
|
||||
use App\Models\FeedTemplate;
|
||||
|
||||
class MusicController {
|
||||
static public function get(string $music_id) {
|
||||
$cursor = Misc::getCursor();
|
||||
|
||||
$api = Misc::api();
|
||||
$feed = $api->getMusicFeed($music_id, $cursor);
|
||||
if ($feed->meta->success) {
|
||||
$latte = Misc::latte();
|
||||
$latte->render(Misc::getView('music'), new FeedTemplate('Music', $feed));
|
||||
} else {
|
||||
ErrorHandler::show($feed->meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
app/Controllers/ProxyController.php
Normal file
35
app/Controllers/ProxyController.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
class ProxyController {
|
||||
const VALID_TIKTOK_DOMAINS = [
|
||||
"tiktokcdn.com", "tiktokcdn-us.com", "tiktok.com"
|
||||
];
|
||||
|
||||
static private function isValidDomain(string $url) {
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
$host_split = explode('.', $host);
|
||||
return count($host_split) === 3 && in_array($host_split[1] . '.' . $host_split[2], self::VALID_TIKTOK_DOMAINS);
|
||||
}
|
||||
|
||||
static public function stream() {
|
||||
if (!isset($_GET['url'])) {
|
||||
die('You need to send a url!');
|
||||
}
|
||||
|
||||
$url = $_GET['url'];
|
||||
if (!filter_var($url, FILTER_VALIDATE_URL) || !self::isValidDomain($url)) {
|
||||
die('Not a valid URL');
|
||||
}
|
||||
|
||||
if (isset($_GET['download'])) {
|
||||
// Download
|
||||
$downloader = new \Sovit\TikTok\Download();
|
||||
$downloader->url($url, "tiktok-video", 'mp4');
|
||||
} else {
|
||||
// Stream
|
||||
$streamer = new \Sovit\TikTok\Stream();
|
||||
$streamer->stream($url);
|
||||
}
|
||||
}
|
||||
}
|
||||
54
app/Controllers/SettingsController.php
Normal file
54
app/Controllers/SettingsController.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Helpers\Misc;
|
||||
use App\Helpers\Cookies;
|
||||
use App\Helpers\Following;
|
||||
use App\Models\SettingsTemplate;
|
||||
|
||||
class SettingsController {
|
||||
static public function index() {
|
||||
$latte = Misc::latte();
|
||||
$latte->render(Misc::getView('settings'), new SettingsTemplate());
|
||||
}
|
||||
|
||||
static public function proxy() {
|
||||
if (in_array(Cookies::PROXY, $_POST)) {
|
||||
foreach (Cookies::PROXY as $proxy_element) {
|
||||
Cookies::set($proxy_element, $_POST[$proxy_element]);
|
||||
}
|
||||
}
|
||||
http_response_code(302);
|
||||
$url = Misc::env('APP_URL', '');
|
||||
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);
|
||||
header('Location: ../settings');
|
||||
}
|
||||
}
|
||||
32
app/Controllers/TagController.php
Normal file
32
app/Controllers/TagController.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Helpers\ErrorHandler;
|
||||
use App\Helpers\Misc;
|
||||
use App\Helpers\RSS;
|
||||
use App\Models\FeedTemplate;
|
||||
|
||||
class TagController {
|
||||
static public function get(string $name) {
|
||||
$cursor = Misc::getCursor();
|
||||
$api = Misc::api();
|
||||
$feed = $api->getChallengeFeed($name, $cursor);
|
||||
if ($feed->meta->success) {
|
||||
$latte = Misc::latte();
|
||||
$latte->render(Misc::getView('tag'), new FeedTemplate('Tag', $feed));
|
||||
} else {
|
||||
ErrorHandler::show($feed->meta);
|
||||
}
|
||||
}
|
||||
|
||||
static public function rss(string $name) {
|
||||
$api = Misc::api();
|
||||
$feed = $api->getChallengeFeed($name);
|
||||
if ($feed->meta->success) {
|
||||
$feed = RSS::build("/tag/{$name}", "{$name} Tag", $feed->info->detail->challenge->desc, $feed->items);
|
||||
// Setup headers
|
||||
RSS::setHeaders('tag.rss');
|
||||
echo $feed;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
app/Controllers/TrendingController.php
Normal file
32
app/Controllers/TrendingController.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Helpers\Misc;
|
||||
use App\Models\FeedTemplate;
|
||||
use App\Helpers\ErrorHandler;
|
||||
use App\Helpers\RSS;
|
||||
|
||||
class TrendingController {
|
||||
static public function get() {
|
||||
$cursor = Misc::getCursor();
|
||||
$api = Misc::api();
|
||||
$feed = $api->getTrendingFeed($cursor);
|
||||
if ($feed->meta->success) {
|
||||
$latte = Misc::latte();
|
||||
$latte->render(Misc::getView('trending'), new FeedTemplate('Trending', $feed));
|
||||
} else {
|
||||
ErrorHandler::show($feed->meta);
|
||||
}
|
||||
}
|
||||
|
||||
static public function rss() {
|
||||
$api = Misc::api();
|
||||
$feed = $api->getTrendingFeed();
|
||||
if ($feed->meta->success) {
|
||||
$feed = RSS::build('/trending', 'Trending', 'Tiktok trending', $feed->items);
|
||||
// Setup headers
|
||||
RSS::setHeaders('trending.rss');
|
||||
echo $feed;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
app/Controllers/UserController.php
Normal file
36
app/Controllers/UserController.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Helpers\ErrorHandler;
|
||||
use App\Helpers\Misc;
|
||||
use App\Helpers\RSS;
|
||||
use App\Models\FeedTemplate;
|
||||
|
||||
class UserController {
|
||||
static public function get(string $username) {
|
||||
$cursor = Misc::getCursor();
|
||||
$api = Misc::api();
|
||||
$feed = $api->getUserFeed($username, $cursor);
|
||||
if ($feed->meta->success) {
|
||||
if ($feed->info->detail->user->privateAccount) {
|
||||
http_response_code(400);
|
||||
echo 'Private account detected! Not supported';
|
||||
}
|
||||
$latte = Misc::latte();
|
||||
$latte->render(Misc::getView('user'), new FeedTemplate($feed->info->detail->user->nickname, $feed));
|
||||
} else {
|
||||
ErrorHandler::show($feed->meta);
|
||||
}
|
||||
}
|
||||
|
||||
static public function rss(string $username) {
|
||||
$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);
|
||||
// Setup headers
|
||||
RSS::setHeaders('user.rss');
|
||||
echo $feed;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
app/Controllers/VideoController.php
Normal file
19
app/Controllers/VideoController.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Helpers\ErrorHandler;
|
||||
use App\Helpers\Misc;
|
||||
use App\Models\ItemTemplate;
|
||||
|
||||
class VideoController {
|
||||
static public function get(string $video_id) {
|
||||
$api = Misc::api();
|
||||
$item = $api->getVideoByID($video_id);
|
||||
if ($item->meta->success) {
|
||||
$latte = Misc::latte();
|
||||
$latte->render(Misc::getView('video'), new ItemTemplate($item->info->detail->user->nickname, $item));
|
||||
} else {
|
||||
ErrorHandler::show($item->meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue