Kaynağa Gözat

feat(login): use user_agent from config instead of default

ayn2op 1 yıl önce
ebeveyn
işleme
6f85ff6093
2 değiştirilmiş dosya ile 8 ekleme ve 5 silme
  1. 1 1
      cmd/app.go
  2. 7 4
      internal/login/form.go

+ 1 - 1
cmd/app.go

@@ -43,7 +43,7 @@ func newApp(cfg *config.Config) *App {
 
 func (app *App) show(token string) error {
 	if token == "" {
-		loginForm := login.NewForm(app.Application, func(token string) {
+		loginForm := login.NewForm(app.cfg, app.Application, func(token string) {
 			if err := app.show(token); err != nil {
 				slog.Error("failed to show app", "err", err)
 				return

+ 7 - 4
internal/login/form.go

@@ -5,6 +5,7 @@ import (
 	"log/slog"
 	"net/http"
 
+	"github.com/ayn2op/discordo/internal/config"
 	"github.com/ayn2op/discordo/internal/consts"
 	"github.com/diamondburned/arikawa/v3/api"
 	"github.com/diamondburned/arikawa/v3/utils/httputil"
@@ -16,16 +17,18 @@ type DoneFn = func(token string)
 
 type Form struct {
 	*tview.Pages
-	form *tview.Form
+	cfg  *config.Config
 	app  *tview.Application
+	form *tview.Form
 	done DoneFn
 }
 
-func NewForm(app *tview.Application, done DoneFn) *Form {
+func NewForm(cfg *config.Config, app *tview.Application, done DoneFn) *Form {
 	f := &Form{
 		Pages: tview.NewPages(),
-		form:  tview.NewForm(),
+		cfg:   cfg,
 		app:   app,
+		form:  tview.NewForm(),
 		done:  done,
 	}
 
@@ -48,7 +51,7 @@ func (f *Form) login() {
 	// Create an API client without an authentication token.
 	client := api.NewClient("")
 	// Spoof the user agent of a web browser.
-	client.UserAgent = consts.UserAgent
+	client.UserAgent = f.cfg.Identify.UserAgent
 
 	body := httputil.WithJSONBody(struct {
 		Email    string `json:"login"`