Patching system, video by id

This commit is contained in:
Pablo Ferreiro 2022-01-08 16:03:57 +01:00
parent 38fa75402b
commit c6b0f1e812
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
19 changed files with 305 additions and 60 deletions

View file

@ -1,18 +1,19 @@
<?php
use Steampixel\Route;
const VALID_TIKTOK_DOMAINS = [
"tiktokcdn.com", "tiktokcdn-us.com", "tiktok.com"
];
/**
* Check if an url has a valid domain
* @param string $url URL you want to check
* @return bool
*/
function isValidDomain(string $url): bool {
$valid_domains = [
"tiktokcdn.com", "tiktokcdn-us.com", "tiktok.com"
];
$host = parse_url($url, PHP_URL_HOST);
$host_split = explode('.', $host);
return count($host_split) === 3 && in_array($host_split[1] . '.' . $host_split[2], $valid_domains);
return count($host_split) === 3 && in_array($host_split[1] . '.' . $host_split[2], VALID_TIKTOK_DOMAINS);
}
Route::add('/stream', function () {

View file

@ -10,6 +10,11 @@ Route::add('/', function () {
$latte->render(Misc::getView('home'));
});
Route::add('/about', function () {
$latte = Misc::latte();
$latte->render(Misc::getView('about'));
});
Route::add("/trending", function () {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
@ -44,6 +49,17 @@ Route::add("/@([^/]+)", function (string $username) {
}
});
Route::add('/video/(\d+)', function (string $video_id) {
$latte = Misc::latte();
$api = Misc::api();
$item = $api->getVideoByID($video_id);
if ($item) {
$latte->render(Misc::getView('video'), ['item' => $item]);
} else {
return 'ERROR!';
}
});
Route::add('/tag/(\w+)', function (string $name) {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {