From 3b89d8137eaf6d20a56b5b595bc20b4021c15763 Mon Sep 17 00:00:00 2001 From: Aaron Guise Date: Tue, 1 Jul 2025 11:03:30 +1200 Subject: [PATCH] feat: add UUID utility functions for attachment system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add NewUUID() function for generating unique attachment identifiers - Add IsValidUUID() function for validating UUID format in API requests - Support 32-character hex string validation for secure file handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- core/util/util.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/util/util.go b/core/util/util.go index 7ea982e..44cacb8 100644 --- a/core/util/util.go +++ b/core/util/util.go @@ -3,6 +3,7 @@ package util import ( "crypto/rand" "encoding/hex" + "regexp" "time" ) @@ -44,3 +45,23 @@ func NewInviteId() (string, error) { return hex.EncodeToString(byteArray), nil } + +func NewUUID() string { + guid, err := NewGuid() + if err != nil { + // Fallback to timestamp-based UUID if random generation fails + return hex.EncodeToString([]byte(time.Now().Format("20060102150405"))) + } + return guid +} + +func IsValidUUID(uuid string) bool { + // Check if the string is a valid 32-character hex string (16 bytes * 2 hex chars) + if len(uuid) != 32 { + return false + } + + // Check if all characters are valid hex characters + matched, _ := regexp.MatchString("^[0-9a-f]{32}$", uuid) + return matched +}