From 7a42856d328e627e0821e63164fba31bfbd2a137 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Fri, 13 Sep 2019 15:07:46 -0400 Subject: [PATCH] add snapshot redirect --- controller/Controller.class.php | 2 ++ controller/action/DownloadActions.class.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/controller/Controller.class.php b/controller/Controller.class.php index 502c97fb..97a9d126 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -143,6 +143,8 @@ class Controller $router->post('/i18n/set-culture', 'i18nActions::setCulture'); + $router->get('/snapshot/{type}', 'DownloadActions::executeDownloadSnapshot'); + $permanentRedirectsPath = ROOT_DIR . '/data/redirect/permanent.yaml'; $tempRedirectsPath = ROOT_DIR . '/data/redirect/temporary.yaml'; diff --git a/controller/action/DownloadActions.class.php b/controller/action/DownloadActions.class.php index 32075da5..892094bf 100644 --- a/controller/action/DownloadActions.class.php +++ b/controller/action/DownloadActions.class.php @@ -15,6 +15,23 @@ class DownloadActions extends Actions return Controller::redirect(GitHub::getRepoReleaseUrl($repo, OS::getOsForExtension($ext), $allowPrerelease) ?: '/get', 302); } + public static function executeDownloadSnapshot(string $type) + { + if (!in_array($type, ['blockchain', 'wallet'])) { + return ['page/404']; + } + + $bucketName = "snapshots.lbry.com"; + $bucket = S3::getBucket($bucketName, "$type/"); + + if (!count($bucket)) { + return ['page/404']; + } + + ksort($bucket); + + return Controller::redirect("http://$bucketName/" . array_keys($bucket)[0], 302); + } /* * this is a quick fix to add android, prob not proper design */