forked from mtusi2026/mtusi2026lab7
36 lines
978 B
Go
36 lines
978 B
Go
package model
|
||
|
||
import (
|
||
"github.com/google/uuid"
|
||
"strings"
|
||
"time"
|
||
"unicode"
|
||
"unicode/utf8"
|
||
)
|
||
|
||
const MaxImageBytes int64 = 10 * 1024 * 1024
|
||
const MaxImagePixels int64 = 40_000_000
|
||
|
||
type Attachment struct {
|
||
ID, ChatID, OwnerID uuid.UUID
|
||
Filename, ContentType, SHA256, Status string
|
||
SizeBytes int64
|
||
CreatedAt, UpdatedAt time.Time
|
||
PipelineVersion int32
|
||
ErrorCode string
|
||
Variants []Variant
|
||
StagingExpired, StagingCleaned bool
|
||
}
|
||
|
||
func ValidateFilename(name string) error {
|
||
if !utf8.ValidString(name) || utf8.RuneCountInString(name) < 1 || utf8.RuneCountInString(name) > 255 || strings.TrimSpace(name) == "" {
|
||
return invalidf("filename: 1–255 characters required")
|
||
}
|
||
for _, r := range name {
|
||
if r == '/' || r == '\\' || unicode.IsControl(r) {
|
||
return invalidf("filename: invalid character")
|
||
}
|
||
}
|
||
return nil
|
||
}
|