Skip to content

Commit

Permalink
feat: Initial Analytics stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tankerkiller125 committed Oct 4, 2024
1 parent 9b7b00e commit 5e5d12c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
42 changes: 42 additions & 0 deletions backend/app/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/shirou/gopsutil/v4/host"

Check failure on line 8 in backend/app/api/main.go

View workflow job for this annotation

GitHub Actions / Backend Server Tests / Go

ST1019: package "github.com/shirou/gopsutil/v4/host" is being imported more than once (stylecheck)
"net/http"
"os"
"path/filepath"
Expand All @@ -19,6 +21,7 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/rs/zerolog/pkgerrors"
_ "github.com/shirou/gopsutil/v4/host"

Check failure on line 24 in backend/app/api/main.go

View workflow job for this annotation

GitHub Actions / Backend Server Tests / Go

ST1019(related information): other import of "github.com/shirou/gopsutil/v4/host" (stylecheck)
"github.com/sysadminsmedia/homebox/backend/internal/core/currencies"
"github.com/sysadminsmedia/homebox/backend/internal/core/services"
"github.com/sysadminsmedia/homebox/backend/internal/core/services/reporting/eventbus"
Expand Down Expand Up @@ -72,6 +75,45 @@ func run(cfg *config.Config) error {
app := new(cfg)
app.setupLogger()

if cfg.Options.AllowAnalytics {
type analyticsData struct {
Domain string `json:"domain"`
Name string `json:"name"`
Url string `json:"url"`

Check failure on line 82 in backend/app/api/main.go

View workflow job for this annotation

GitHub Actions / Backend Server Tests / Go

ST1003: struct field Url should be URL (stylecheck)
Props map[string]interface{} `json:"props"`
}
hostData, _ := host.Info()
analytics := analyticsData{
Domain: "homebox.software",
Url: "https://homebox.software",
Name: "stats",
Props: map[string]interface{}{
"os": hostData.OS,
"platform": hostData.Platform,
"platform_family": hostData.PlatformFamily,
"platform_version": hostData.PlatformVersion,
"kernel_arch": hostData.KernelArch,
},
}
jsonBody, err := json.Marshal(analytics)
if err != nil {
log.Error().Err(err).Msg("failed to marshal analytics data")
}
bodyReader := bytes.NewReader(jsonBody)
req, err := http.NewRequest("POST", "https://a.sysadmins.zone/api/event", bodyReader)

Check failure on line 103 in backend/app/api/main.go

View workflow job for this annotation

GitHub Actions / Backend Server Tests / Go

ineffectual assignment to err (ineffassign)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 OPR/71.0.3770.284")
client := &http.Client{
Timeout: 10 * time.Second,
}
res, err := client.Do(req)

Check failure on line 109 in backend/app/api/main.go

View workflow job for this annotation

GitHub Actions / Backend Server Tests / Go

response body must be closed (bodyclose)
if err != nil {
return err
}
log.Info().Msgf("Analytics Response: %v", res)
log.Info().Msgf("Analytics Response: %v", json.NewEncoder(os.Stdout).Encode(analytics))
}

// =========================================================================
// Initialize Database & Repos

Expand Down
1 change: 1 addition & 0 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/swaggo/swag v1.16.3
github.com/yeqown/go-qrcode/v2 v2.2.4
github.com/yeqown/go-qrcode/writer/standard v1.2.4
github.com/shirou/gopsutil/v4 v4.24.9
golang.org/x/crypto v0.28.0
modernc.org/sqlite v1.33.1
)
Expand Down
4 changes: 4 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil/v4 v4.24.9 h1:KIV+/HaHD5ka5f570RZq+2SaeFsb/pq+fp2DGNWYoOI=
github.com/shirou/gopsutil/v4 v4.24.9/go.mod h1:3fkaHNeYsUFCGZ8+9vZVWtbyM1k2eRnlL+bWO8Bxa/Q=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
1 change: 1 addition & 0 deletions backend/internal/sys/config/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Options struct {
AllowRegistration bool `yaml:"disable_registration" conf:"default:true"`
AutoIncrementAssetID bool `yaml:"auto_increment_asset_id" conf:"default:true"`
CurrencyConfig string `yaml:"currencies"`
AllowAnalytics bool `yaml:"allow_analytics" conf:"default:true"`
}

type DebugConf struct {
Expand Down
1 change: 0 additions & 1 deletion frontend/components/Form/TextField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
{{ typeof value === "string" && (maxLength || minLength) ? `${value.length}/${maxLength}` : "" }}
</span>
</label>
{{ value }}
<input
ref="input"
v-model="value"
Expand Down

0 comments on commit 5e5d12c

Please sign in to comment.