move github api call out of routing, into action

This commit is contained in:
Alex Grintsvayg 2016-11-18 10:07:37 -05:00
parent 66c6573db6
commit 0c70d3b9e7
4 changed files with 29 additions and 7 deletions

View file

@ -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');

View file

@ -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':

View file

@ -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');

View file

@ -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'];