diff --git a/migrations/sqlite3/4_machine_column.sql b/migrations/sqlite3/4_machine_column.sql new file mode 100644 index 0000000..1b8aac2 --- /dev/null +++ b/migrations/sqlite3/4_machine_column.sql @@ -0,0 +1,11 @@ +-- +migrate Up +-- SQL in section 'Up' is executed when this migration is applied + +alter table users + add `machine` varchar(255); + +-- +migrate Down +-- SQL section 'Down' is executed when this migration is rolled back + +alter table users + drop column `machine`; \ No newline at end of file diff --git a/models/heartbeat.go b/models/heartbeat.go index 62893a6..c1cb872 100644 --- a/models/heartbeat.go +++ b/models/heartbeat.go @@ -20,6 +20,7 @@ type Heartbeat struct { IsWrite bool `json:"is_write"` Editor string `json:"editor"` OperatingSystem string `json:"operating_system"` + Machine string `json:"machine"` Time CustomTime `json:"time" gorm:"type:timestamp; default:CURRENT_TIMESTAMP; index:idx_time,idx_time_user"` languageRegex *regexp.Regexp } diff --git a/routes/heartbeat.go b/routes/heartbeat.go index 2eab400..dfa96ec 100644 --- a/routes/heartbeat.go +++ b/routes/heartbeat.go @@ -31,6 +31,7 @@ func (h *HeartbeatHandler) ApiPost(w http.ResponseWriter, r *http.Request) { var heartbeats []*models.Heartbeat user := r.Context().Value(models.UserKey).(*models.User) opSys, editor, _ := utils.ParseUserAgent(r.Header.Get("User-Agent")) + machineName := r.Header.Get("X-Machine-Name") dec := json.NewDecoder(r.Body) if err := dec.Decode(&heartbeats); err != nil { @@ -42,6 +43,7 @@ func (h *HeartbeatHandler) ApiPost(w http.ResponseWriter, r *http.Request) { for _, hb := range heartbeats { hb.OperatingSystem = opSys hb.Editor = editor + hb.Machine = machineName hb.User = user hb.UserID = user.ID hb.Augment(h.config.CustomLanguages) diff --git a/version.txt b/version.txt index 5849151..d263485 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.7.5 \ No newline at end of file +1.7.6 \ No newline at end of file