From 59ea2645db827335a0689d2fb7aeeef4e52af52b Mon Sep 17 00:00:00 2001 From: mhsanaei Date: Thu, 18 Sep 2025 13:56:04 +0200 Subject: new: subJsonEnable after this subEnable by default is true and subJsonEnable is false --- web/service/setting.go | 21 +++++++++++++++++---- web/service/tgbot.go | 30 +++++++++++++++++++----------- 2 files changed, 36 insertions(+), 15 deletions(-) (limited to 'web/service') diff --git a/web/service/setting.go b/web/service/setting.go index a54eaea7..39961ad5 100644 --- a/web/service/setting.go +++ b/web/service/setting.go @@ -50,7 +50,8 @@ var defaultValueMap = map[string]string{ "tgLang": "en-US", "twoFactorEnable": "false", "twoFactorToken": "", - "subEnable": "false", + "subEnable": "true", + "subJsonEnable": "false", "subTitle": "", "subListen": "", "subPort": "2096", @@ -427,6 +428,10 @@ func (s *SettingService) GetSubEnable() (bool, error) { return s.getBool("subEnable") } +func (s *SettingService) GetSubJsonEnable() (bool, error) { + return s.getBool("subJsonEnable") +} + func (s *SettingService) GetSubTitle() (string, error) { return s.getString("subTitle") } @@ -575,6 +580,7 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) { "defaultKey": func() (any, error) { return s.GetKeyFile() }, "tgBotEnable": func() (any, error) { return s.GetTgbotEnabled() }, "subEnable": func() (any, error) { return s.GetSubEnable() }, + "subJsonEnable": func() (any, error) { return s.GetSubJsonEnable() }, "subTitle": func() (any, error) { return s.GetSubTitle() }, "subURI": func() (any, error) { return s.GetSubURI() }, "subJsonURI": func() (any, error) { return s.GetSubJsonURI() }, @@ -593,7 +599,14 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) { result[key] = value } - if result["subEnable"].(bool) && (result["subURI"].(string) == "" || result["subJsonURI"].(string) == "") { + subEnable := result["subEnable"].(bool) + subJsonEnable := false + if v, ok := result["subJsonEnable"]; ok { + if b, ok2 := v.(bool); ok2 { + subJsonEnable = b + } + } + if (subEnable && result["subURI"].(string) == "") || (subJsonEnable && result["subJsonURI"].(string) == "") { subURI := "" subTitle, _ := s.GetSubTitle() subPort, _ := s.GetSubPort() @@ -619,13 +632,13 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) { } else { subURI += fmt.Sprintf("%s:%d", subDomain, subPort) } - if result["subURI"].(string) == "" { + if subEnable && result["subURI"].(string) == "" { result["subURI"] = subURI + subPath } if result["subTitle"].(string) == "" { result["subTitle"] = subTitle } - if result["subJsonURI"].(string) == "" { + if subJsonEnable && result["subJsonURI"].(string) == "" { result["subJsonURI"] = subURI + subJsonPath } } diff --git a/web/service/tgbot.go b/web/service/tgbot.go index f21af6cc..dd6ac196 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -2093,6 +2093,7 @@ func (t *Tgbot) buildSubscriptionURLs(email string) (string, string, error) { subPort, _ := t.settingService.GetSubPort() subPath, _ := t.settingService.GetSubPath() subJsonPath, _ := t.settingService.GetSubJsonPath() + subJsonEnable, _ := t.settingService.GetSubJsonEnable() subKeyFile, _ := t.settingService.GetSubKeyFile() subCertFile, _ := t.settingService.GetSubCertFile() @@ -2137,6 +2138,9 @@ func (t *Tgbot) buildSubscriptionURLs(email string) (string, string, error) { subURL := fmt.Sprintf("%s://%s%s%s", scheme, host, subPath, client.SubID) subJsonURL := fmt.Sprintf("%s://%s%s%s", scheme, host, subJsonPath, client.SubID) + if !subJsonEnable { + subJsonURL = "" + } return subURL, subJsonURL, nil } @@ -2146,8 +2150,10 @@ func (t *Tgbot) sendClientSubLinks(chatId int64, email string) { t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.errorOperation")+"\r\n"+err.Error()) return } - msg := "Subscription URL:\r\n" + subURL + "\r\n\r\n" + - "JSON URL:\r\n" + subJsonURL + "" + msg := "Subscription URL:\r\n" + subURL + "" + if subJsonURL != "" { + msg += "\r\n\r\nJSON URL:\r\n" + subJsonURL + "" + } inlineKeyboard := tu.InlineKeyboard( tu.InlineKeyboardRow( tu.InlineKeyboardButton(t.I18nBot("subscription.individualLinks")).WithCallbackData(t.encodeQuery("client_individual_links "+email)), @@ -2271,15 +2277,17 @@ func (t *Tgbot) sendClientQRLinks(chatId int64, email string) { t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.errorOperation")+"\r\n"+err.Error()) } - // Send JSON URL QR (filename: subjson.png) - if png, err := createQR(subJsonURL, 320); err == nil { - document := tu.Document( - tu.ID(chatId), - tu.FileFromBytes(png, "subjson.png"), - ) - _, _ = bot.SendDocument(context.Background(), document) - } else { - t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.errorOperation")+"\r\n"+err.Error()) + // Send JSON URL QR (filename: subjson.png) when available + if subJsonURL != "" { + if png, err := createQR(subJsonURL, 320); err == nil { + document := tu.Document( + tu.ID(chatId), + tu.FileFromBytes(png, "subjson.png"), + ) + _, _ = bot.SendDocument(context.Background(), document) + } else { + t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.errorOperation")+"\r\n"+err.Error()) + } } // Also generate a few individual links' QRs (first up to 5) -- cgit v1.2.3