From 2adb1c5c802b6234860ff5e751b9cc8f9b799552 Mon Sep 17 00:00:00 2001 From: 0xCA Date: Thu, 28 Dec 2023 05:53:23 +0500 Subject: [PATCH] Handle paused configs correctly - Removed unnecessary qr generation --- handler/routes.go | 7 +------ store/jsondb/jsondb.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/handler/routes.go b/handler/routes.go index 1914cc5..75a6eea 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -581,12 +581,7 @@ func SendTelegramClient(db store.IStore) echo.HandlerFunc { var payload clientIdUseridPayload c.Bind(&payload) - qrCodeSettings := model.QRCodeSettings{ - Enabled: true, - IncludeDNS: true, - IncludeMTU: true, - } - clientData, err := db.GetClientByID(payload.ID, qrCodeSettings) + clientData, err := db.GetClientByID(payload.ID, model.QRCodeSettings{Enabled: false}) if err != nil { log.Errorf("Cannot generate client id %s config file for downloading: %v", payload.ID, err) return c.JSON(http.StatusNotFound, jsonHTTPResponse{false, "Client not found"}) diff --git a/store/jsondb/jsondb.go b/store/jsondb/jsondb.go index ff8d1bb..03b5b62 100644 --- a/store/jsondb/jsondb.go +++ b/store/jsondb/jsondb.go @@ -169,7 +169,7 @@ func (o *JsonDB) Init() error { } for _, cl := range clients { client := cl.Client - if len(client.TgUserid) > 3 { + if client.Enabled && len(client.TgUserid) > 0 { if userid, err := strconv.ParseInt(client.TgUserid, 10, 64); err == nil { util.UpdateTgToClientID(userid, client.ID) } @@ -329,10 +329,16 @@ func (o *JsonDB) GetClientByID(clientID string, qrCodeSettings model.QRCodeSetti func (o *JsonDB) SaveClient(client model.Client) error { clientPath := path.Join(path.Join(o.dbPath, "clients"), client.ID+".json") output := o.conn.Write("clients", client.ID, client) - if output == nil && len(client.TgUserid) > 3 { - if userid, err := strconv.ParseInt(client.TgUserid, 10, 64); err == nil { - util.UpdateTgToClientID(userid, client.ID) + if output == nil { + if client.Enabled && len(client.TgUserid) > 0 { + if userid, err := strconv.ParseInt(client.TgUserid, 10, 64); err == nil { + util.UpdateTgToClientID(userid, client.ID) + } + } else { + util.RemoveTgToClientID(client.ID) } + } else { + util.RemoveTgToClientID(client.ID) } err := util.ManagePerms(clientPath) if err != nil {