91 lines
2.1 KiB
Go
91 lines
2.1 KiB
Go
package domain
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// AttachmentStatus is the lifecycle of an attachment. Only ready attachments
|
|
// are exposed to members; pending rows exist while the object is being written,
|
|
// failed rows are reserved for later labs.
|
|
type AttachmentStatus string
|
|
|
|
const (
|
|
AttachmentPending AttachmentStatus = "pending"
|
|
AttachmentReady AttachmentStatus = "ready"
|
|
AttachmentFailed AttachmentStatus = "failed"
|
|
)
|
|
|
|
func (s AttachmentStatus) Valid() bool {
|
|
switch s {
|
|
case AttachmentPending, AttachmentReady, AttachmentFailed:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Attachment describes the original object. ObjectKey is internal: it never
|
|
// leaves the service and must not be mapped into an API response.
|
|
type Attachment struct {
|
|
ID uuid.UUID
|
|
ChatID uuid.UUID
|
|
OwnerID uuid.UUID
|
|
Filename string
|
|
ContentType string
|
|
SizeBytes int64
|
|
SHA256 string
|
|
Status AttachmentStatus
|
|
ErrorCode *string
|
|
ObjectKey string
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
// AttachmentDraft is a fully validated attachment awaiting persistence.
|
|
type AttachmentDraft struct {
|
|
ID uuid.UUID
|
|
ChatID uuid.UUID
|
|
OwnerID uuid.UUID
|
|
ObjectKey string
|
|
Filename string
|
|
ContentType string
|
|
SizeBytes int64
|
|
SHA256 string
|
|
}
|
|
|
|
// AttachmentState is the minimal projection used while validating message
|
|
// attachments in a transaction.
|
|
type AttachmentState struct {
|
|
ID uuid.UUID
|
|
Status AttachmentStatus
|
|
}
|
|
|
|
// AttachmentKey is the minimal projection used by the orphan sweeper.
|
|
type AttachmentKey struct {
|
|
ID uuid.UUID
|
|
ObjectKey string
|
|
Status AttachmentStatus
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
// PresignRequest is the validated client intent for a direct upload.
|
|
type PresignRequest struct {
|
|
ChatID uuid.UUID
|
|
OwnerID uuid.UUID
|
|
Filename string
|
|
ContentType string
|
|
SizeBytes int64
|
|
SHA256 string
|
|
}
|
|
|
|
// PresignResult is returned by the server and never contains credentials.
|
|
type PresignResult struct {
|
|
AttachmentID uuid.UUID
|
|
UploadURL string
|
|
ExpiresAt time.Time
|
|
SizeBytes int64
|
|
SHA256 string
|
|
}
|