From 4215001ab78ebcb5f3844f4bda36364951d18be4 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 23 Jun 2026 08:58:59 +0000 Subject: [PATCH] feat: test_mode toggle in admin + cache bump v10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - test_mode + test_phone columns in sms_campaign_settings (DB) - Script reads test_mode from DB settings, not env vars - Admin panel: toggle Test/Production mode with visual indicator - test_mode=true (default): SMS only to test_phone - test_mode=false: SMS to real customers - Service worker cache v9 → v10 (fixes white screen) --- public/service-worker.js | 4 +-- scripts/sms_first_campaign.py | 16 ++++++++++-- src/components/admin/SmsCampaignPanel.jsx | 32 +++++++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/public/service-worker.js b/public/service-worker.js index d6f2361..0f32750 100644 --- a/public/service-worker.js +++ b/public/service-worker.js @@ -1,8 +1,8 @@ const isLocalhost = self.location.hostname === "localhost" || self.location.hostname === "127.0.0.1"; if (!isLocalhost) { - const STATIC_CACHE = "construction-delivery-static-v9"; - const RUNTIME_CACHE = "construction-delivery-runtime-v9"; + const STATIC_CACHE = "construction-delivery-static-v10"; + const RUNTIME_CACHE = "construction-delivery-runtime-v10"; const APP_SHELL_URLS = ["/", "/index.html", "/manifest.webmanifest", "/icons/icon-192.png", "/icons/icon-512.png"]; self.addEventListener("install", (event) => { diff --git a/scripts/sms_first_campaign.py b/scripts/sms_first_campaign.py index 345d142..c4cd983 100644 --- a/scripts/sms_first_campaign.py +++ b/scripts/sms_first_campaign.py @@ -46,6 +46,10 @@ SMS_STATUS_URL = "https://sms.ru/sms/status" LOG_FILE = "/var/log/supersam-sms-first.log" +# ТЕСТОВЫЙ РЕЖИМ — управляется из админки (sms_campaign_settings.test_mode) +# По умолчанию ВКЛЮЧЕН — SMS идут только на test_phone +# Мегаадмин выключает через админку → SMS идут реальным клиентам + # Коды, которые означают "в процессе" (ждём дальше) IN_TRANSIT_CODES = {"100", "101", "102"} # Код доставки @@ -87,6 +91,8 @@ def load_settings(conn): "enabled": True, "telegram_chat_id": "25164483", "sms_api_id": SMS_API_ID, + "test_mode": True, + "test_phone": "79788382260", } return dict(row) @@ -287,8 +293,14 @@ def step_send_new(conn, settings): sms_text = f"Ваш заказ готов. Согласуйте дату доставки по ссылке: {delivery_link}" - log.info(f"Sending SMS to {name} ({phone})") - sms_id, raw, code = send_sms(phone, sms_text, api_id) + # ТЕСТОВЫЙ РЕЖИМ: подменяем номер на тестовый + send_phone = phone + if settings.get("test_mode", True): + send_phone = settings.get("test_phone", "79788382260") + log.info(f"TEST MODE: sending to {send_phone} instead of {phone}") + + log.info(f"Sending SMS to {name} (orig={phone}, send={send_phone})") + sms_id, raw, code = send_sms(send_phone, sms_text, api_id) if sms_id: log_id = insert_sms_log(conn, diff --git a/src/components/admin/SmsCampaignPanel.jsx b/src/components/admin/SmsCampaignPanel.jsx index 8099dfb..10e06dd 100644 --- a/src/components/admin/SmsCampaignPanel.jsx +++ b/src/components/admin/SmsCampaignPanel.jsx @@ -178,6 +178,38 @@ export const SmsCampaignPanel = () => { ✓ Сохранено )} + + {/* Test / Production mode toggle */} +
+ + {settings.test_mode && ( +
+ updateSetting("test_phone", v)} + /> +
+ )} +