mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-09 15:15:08 +02:00
Add client-side code to ask for feedback when uninstalling
This commit is contained in:
@ -42,12 +42,6 @@ type UsageData struct {
|
|||||||
Version string `json:"version"`
|
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 {
|
func getRequiredQueryParam(r *http.Request, queryParam string) string {
|
||||||
val := r.URL.Query().Get(queryParam)
|
val := r.URL.Query().Get(queryParam)
|
||||||
if val == "" {
|
if val == "" {
|
||||||
@ -404,7 +398,7 @@ func OpenDB() (*gorm.DB, error) {
|
|||||||
db.AutoMigrate(&UsageData{})
|
db.AutoMigrate(&UsageData{})
|
||||||
db.AutoMigrate(&shared.DumpRequest{})
|
db.AutoMigrate(&shared.DumpRequest{})
|
||||||
db.AutoMigrate(&shared.DeletionRequest{})
|
db.AutoMigrate(&shared.DeletionRequest{})
|
||||||
db.AutoMigrate(&Feedback{})
|
db.AutoMigrate(&shared.Feedback{})
|
||||||
db.Exec("PRAGMA journal_mode = WAL")
|
db.Exec("PRAGMA journal_mode = WAL")
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
@ -620,7 +614,7 @@ func feedbackHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
var feedback Feedback
|
var feedback shared.Feedback
|
||||||
err = json.Unmarshal(data, &feedback)
|
err = json.Unmarshal(data, &feedback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("feedbackHandler: body=%#v, err=%v", data, err))
|
panic(fmt.Sprintf("feedbackHandler: body=%#v, err=%v", data, err))
|
||||||
|
@ -2,12 +2,16 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/ddworken/hishtory/client/data"
|
||||||
"github.com/ddworken/hishtory/client/hctx"
|
"github.com/ddworken/hishtory/client/hctx"
|
||||||
"github.com/ddworken/hishtory/client/lib"
|
"github.com/ddworken/hishtory/client/lib"
|
||||||
|
"github.com/ddworken/hishtory/shared"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,6 +19,7 @@ var uninstallCmd = &cobra.Command{
|
|||||||
Use: "uninstall",
|
Use: "uninstall",
|
||||||
Short: "Completely uninstall hiSHtory and remove your shell history",
|
Short: "Completely uninstall hiSHtory and remove your shell history",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
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]")
|
fmt.Printf("Are you sure you want to uninstall hiSHtory and delete all locally saved history data [y/N]")
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
resp, err := reader.ReadString('\n')
|
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))
|
fmt.Printf("Aborting uninstall per user response of %#v\n", strings.TrimSpace(resp))
|
||||||
return
|
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))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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...
|
||||||
|
@ -85,3 +85,9 @@ func (m *MessageIdentifiers) Scan(value interface{}) error {
|
|||||||
func (m MessageIdentifiers) Value() (driver.Value, error) {
|
func (m MessageIdentifiers) Value() (driver.Value, error) {
|
||||||
return json.Marshal(m)
|
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"`
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user