Add client-side code to ask for feedback when uninstalling

This commit is contained in:
David Dworken 2022-11-16 21:54:05 -08:00
parent 48c77d88f7
commit d4efc62df1
No known key found for this signature in database
4 changed files with 27 additions and 10 deletions

View File

@ -42,12 +42,6 @@ type UsageData struct {
Version string `json:"version"`
}
type Feedback struct {
UserId string `json:"user_id" gorm:"not null"`
Date time.Time `json:"date" gorm:"not null"`
Feedback string `json:"feedback"`
}
func getRequiredQueryParam(r *http.Request, queryParam string) string {
val := r.URL.Query().Get(queryParam)
if val == "" {
@ -404,7 +398,7 @@ func OpenDB() (*gorm.DB, error) {
db.AutoMigrate(&UsageData{})
db.AutoMigrate(&shared.DumpRequest{})
db.AutoMigrate(&shared.DeletionRequest{})
db.AutoMigrate(&Feedback{})
db.AutoMigrate(&shared.Feedback{})
db.Exec("PRAGMA journal_mode = WAL")
return db, nil
}
@ -620,7 +614,7 @@ func feedbackHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
panic(err)
}
var feedback Feedback
var feedback shared.Feedback
err = json.Unmarshal(data, &feedback)
if err != nil {
panic(fmt.Sprintf("feedbackHandler: body=%#v, err=%v", data, err))

View File

@ -2,12 +2,16 @@ package cmd
import (
"bufio"
"encoding/json"
"fmt"
"os"
"strings"
"time"
"github.com/ddworken/hishtory/client/data"
"github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/lib"
"github.com/ddworken/hishtory/shared"
"github.com/spf13/cobra"
)
@ -15,6 +19,7 @@ var uninstallCmd = &cobra.Command{
Use: "uninstall",
Short: "Completely uninstall hiSHtory and remove your shell history",
Run: func(cmd *cobra.Command, args []string) {
ctx := hctx.MakeContext()
fmt.Printf("Are you sure you want to uninstall hiSHtory and delete all locally saved history data [y/N]")
reader := bufio.NewReader(os.Stdin)
resp, err := reader.ReadString('\n')
@ -23,7 +28,18 @@ var uninstallCmd = &cobra.Command{
fmt.Printf("Aborting uninstall per user response of %#v\n", strings.TrimSpace(resp))
return
}
lib.CheckFatalError(lib.Uninstall(hctx.MakeContext()))
fmt.Printf("Do you have any feedback on why you're uninstallying hiSHtory? Type any feedback and then hit enter.\nFeedback: ")
feedbackTxt, err := reader.ReadString('\n')
lib.CheckFatalError(err)
feedback := shared.Feedback{
Date: time.Now(),
Feedback: feedbackTxt,
UserId: data.UserId(hctx.GetConf(ctx).UserSecret),
}
reqBody, err := json.Marshal(feedback)
lib.CheckFatalError(err)
_, _ = lib.ApiPost("/api/v1/feedback", "application/json", reqBody)
lib.CheckFatalError(lib.Uninstall(ctx))
},
}

View File

@ -1 +1,2 @@
Are you sure you want to uninstall hiSHtory and delete all locally saved history data [y/N]Successfully uninstalled hishtory, please restart your terminal...
Are you sure you want to uninstall hiSHtory and delete all locally saved history data [y/N]Do you have any feedback on why you're uninstallying hiSHtory? Type any feedback and then hit enter.
Feedback: Successfully uninstalled hishtory, please restart your terminal...

View File

@ -85,3 +85,9 @@ func (m *MessageIdentifiers) Scan(value interface{}) error {
func (m MessageIdentifiers) Value() (driver.Value, error) {
return json.Marshal(m)
}
type Feedback struct {
UserId string `json:"user_id" gorm:"not null"`
Date time.Time `json:"date" gorm:"not null"`
Feedback string `json:"feedback"`
}