From: PhiTux Date: Sat, 16 Aug 2025 17:13:30 +0000 (+0200) Subject: added name to export X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=ebf304a96af16d5226acb490d1079aebbd880084;p=DailyTxT.git added name to export --- diff --git a/backend/handlers/additional.go b/backend/handlers/additional.go index 21c5926..ce8d271 100644 --- a/backend/handlers/additional.go +++ b/backend/handlers/additional.go @@ -2278,7 +2278,7 @@ func generateHTML(entries []LogEntry, userID int, derivedKey string, includeTags // Header html.WriteString(`

DailyTxT Export

`) - html.WriteString(fmt.Sprintf(`

Benutzer ID: %d

`, userID)) + html.WriteString(fmt.Sprintf(`

Benutzer: %s

`, utils.GetUsernameByID(userID))) html.WriteString(fmt.Sprintf(`

Exportiert am: %s

`, time.Now().Format("02.01.2006 15:04:05"))) html.WriteString(fmt.Sprintf(`

Anzahl Einträge: %d

`, len(entries))) html.WriteString(`
diff --git a/backend/utils/helpers.go b/backend/utils/helpers.go index 6fee5fd..7b754a7 100644 --- a/backend/utils/helpers.go +++ b/backend/utils/helpers.go @@ -367,3 +367,31 @@ func CopyDir(src, dst string, logger *log.Logger) error { logger.Printf("Copied directory from %s to %s", src, dst) return nil } + +func GetUsernameByID(userID int) string { + // Get users + users, err := GetUsers() + if err != nil { + fmt.Printf("failed to get users: %v", err) + return "" + } + + // Find user by ID + for _, userInterface := range users["users"].([]any) { + user, ok := userInterface.(map[string]any) + if !ok { + continue // Skip if user is not a map + } + id := int(user["user_id"].(float64)) + if id == userID { + if username, ok := user["username"].(string); ok { + return username + } + fmt.Printf("username not found for user ID: %d\n", userID) + return "" + } + } + + fmt.Printf("user not found with ID: %d\n", userID) + return "" +}