Add type declarations, fix function reference

This commit is contained in:
Chris Novakovic 2022-07-31 17:20:38 +01:00
parent e7ee03e3cc
commit 8d8fe43431

View file

@ -13,9 +13,9 @@ class RedirectController {
$term = trim($_GET['term']); $term = trim($_GET['term']);
switch ($_GET['type']) { switch ($_GET['type']) {
case 'url': case 'url':
$endpoint = to_endpoint($term); $endpoint = self::to_endpoint($term);
if (!$endpoint) { if (!$endpoint) {
ErrorHandler::show('Invalid or unknown TikTok URL format'); echo 'Invalid or unknown TikTok URL format';
return; return;
} }
break; break;
@ -51,7 +51,7 @@ class RedirectController {
/** /**
* to_endpoint maps a TikTok URL into a ProxiTok-compatible endpoint URL. * to_endpoint maps a TikTok URL into a ProxiTok-compatible endpoint URL.
*/ */
static private function to_endpoint($url) { static private function to_endpoint(string $url): string {
if (preg_match('%^https://vm\.tiktok\.com/([A-Za-z0-9]+)%', $url, $m)) { if (preg_match('%^https://vm\.tiktok\.com/([A-Za-z0-9]+)%', $url, $m)) {
// Short video URL // Short video URL
return '/@placeholder/video/' . $m[1]; return '/@placeholder/video/' . $m[1];