diff --git a/controller/Controller.class.php b/controller/Controller.class.php index 55d38dcf..e05b7fa5 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -121,11 +121,9 @@ class Controller '/deck.pdf' => 'https://www.dropbox.com/s/0xj4vgucsbi8rtv/lbry-deck.pdf?dl=1', '/pln.pdf' => 'https://www.dropbox.com/s/uevjrwnyr672clj/lbry-pln.pdf?dl=1', '/plan.pdf' => 'https://www.dropbox.com/s/uevjrwnyr672clj/lbry-pln.pdf?dl=1', - '/get/lbry.dmg' => GitHub::getDownloadUrl(OS::OS_OSX) ?: '/get', - '/get/lbry.deb' => GitHub::getDownloadUrl(OS::OS_LINUX) ?: '/get', - '/get/lbry.msi' => GitHub::getDownloadUrl(OS::OS_WINDOWS) ?: '/get', ]; + foreach ([302 => $tempRedirects, 301 => $permanentRedirects] as $code => $redirects) { foreach ($redirects as $src => $target) @@ -134,6 +132,8 @@ class Controller } } + $router->any('/get/lbry.{ext:c}', 'DownloadActions::executeGetRedirect'); + $router->get([ContentActions::URL_NEWS . '/{slug:c}?', 'news'], 'ContentActions::executeNews'); $router->get([ContentActions::URL_FAQ . '/{slug:c}?', 'faq'], 'ContentActions::executeFaq'); $router->get([ContentActions::URL_BOUNTY . '/{slug:c}?', 'bounty'], 'ContentActions::executeBounty'); diff --git a/controller/Request.class.php b/controller/Request.class.php index 7a2f0a8a..e0ad6a3c 100644 --- a/controller/Request.class.php +++ b/controller/Request.class.php @@ -76,7 +76,7 @@ class Request public static function getRoutingUri() { - $host = preg_replace('/^www\./', '', $_SERVER['HTTP_HOST']); + $host = preg_replace('/^www\./', '', static::getHost()); switch($host) { case 'betteryoutube.com': diff --git a/controller/action/DownloadActions.class.php b/controller/action/DownloadActions.class.php index a0493649..aec59589 100644 --- a/controller/action/DownloadActions.class.php +++ b/controller/action/DownloadActions.class.php @@ -2,6 +2,27 @@ class DownloadActions extends Actions { + public static function executeGetRedirect(string $ext) + { + $uri = null; + switch ($ext) + { + case 'deb': + $uri = GitHub::getDownloadUrl(OS::OS_LINUX); + break; + + case 'dmg': + $uri = GitHub::getDownloadUrl(OS::OS_OSX); + break; + + case 'msi': + $uri = GitHub::getDownloadUrl(OS::OS_WINDOWS); + break; + } + + return Controller::redirect($target ?: '/get', 302); + } + public static function executeGet() { $email = Request::getParam('e'); diff --git a/lib/thirdparty/Github.class.php b/lib/thirdparty/Github.class.php index bc43d369..4ec5e7b6 100644 --- a/lib/thirdparty/Github.class.php +++ b/lib/thirdparty/Github.class.php @@ -14,10 +14,11 @@ class Github $releaseData = static::get('/repos/lbryio/lbry/releases/latest', $cache); foreach ($releaseData['assets'] as $asset) { + $ext = substr($asset['name'], -4); if ( - ($os == OS::OS_LINUX && in_array($asset['content_type'], ['application/x-debian-package', 'application/x-deb'])) || - ($os == OS::OS_OSX && in_array($asset['content_type'], ['application/x-diskcopy', 'application/x-apple-diskimage'])) || - ($os == OS::OS_WINDOWS && substr($asset['name'], -4) == '.msi') + ($os == OS::OS_LINUX && ($ext == '.deb' || in_array($asset['content_type'], ['application/x-debian-package', 'application/x-deb']))) || + ($os == OS::OS_OSX && ($ext == '.dmg' || in_array($asset['content_type'], ['application/x-diskcopy', 'application/x-apple-diskimage']))) || + ($os == OS::OS_WINDOWS && $ext == '.msi') ) { return $asset['browser_download_url'];