From 2e722a9ac9e91f8b71086c54364a810ab994fc72 Mon Sep 17 00:00:00 2001 From: Rekryt Date: Mon, 28 Oct 2024 13:56:09 +0300 Subject: [PATCH] feat: add "save as file" checkbox --- src/App/Controller/AbstractController.php | 2 +- src/App/Controller/AbstractIPListController.php | 6 ++++++ src/App/Template/IndexTemplate.php | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/App/Controller/AbstractController.php b/src/App/Controller/AbstractController.php index acee4f6..2f72cd2 100644 --- a/src/App/Controller/AbstractController.php +++ b/src/App/Controller/AbstractController.php @@ -29,7 +29,7 @@ abstract class AbstractController implements ControllerInterface { abstract public function getBody(): string; public function setHeaders(array $headers): AbstractController { - $this->headers = $headers; + $this->headers = array_merge($this->headers ?? [], $headers); return $this; } diff --git a/src/App/Controller/AbstractIPListController.php b/src/App/Controller/AbstractIPListController.php index 965f121..51722ac 100644 --- a/src/App/Controller/AbstractIPListController.php +++ b/src/App/Controller/AbstractIPListController.php @@ -27,6 +27,12 @@ abstract class AbstractIPListController extends AbstractController { $this->logger = App::getLogger(); $this->service = IPListService::getInstance(); + + $isFileSave = !!($this->request->getQueryParameter('filesave') ?? ''); + if ($isFileSave) { + $ext = in_array($this->request->getQueryParameter('format'), ['json', 'amnezia']) ? 'json' : 'txt'; + $this->setHeaders(['content-disposition' => 'attachment; filename="ip-list.' . $ext . '"']); + } } /** diff --git a/src/App/Template/IndexTemplate.php b/src/App/Template/IndexTemplate.php index c09f64a..50428b6 100644 --- a/src/App/Template/IndexTemplate.php +++ b/src/App/Template/IndexTemplate.php @@ -591,6 +591,7 @@ use OpenCCK\App\Controller\MainController; display: flex; flex-wrap: wrap; justify-content: center; + margin-bottom: 10px; } .main-formItemComment { flex: 0 0 100%; @@ -611,6 +612,7 @@ use OpenCCK\App\Controller\MainController; line-height: 1; font-size: 14px; font-weight: normal; + cursor: pointer; } @@ -664,6 +666,10 @@ use OpenCCK\App\Controller\MainController; Only wildcard domains +