forked from mtusi2026/mtusi2026lab5
feat(worker): process attachments with thumbnails and bounded retries
This commit is contained in:
+41
-22
@@ -19,27 +19,27 @@ type GetAttachmentContentRequest struct {
|
||||
}
|
||||
|
||||
type VariantResponse struct {
|
||||
Name string `json:"name"`
|
||||
ContentType string `json:"content_type"`
|
||||
SizeBytes int `json:"size_bytes"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Sha256 string `json:"sha256"`
|
||||
Name model.AttachmentVariantName `json:"name"`
|
||||
ContentType model.ContentType `json:"content_type"`
|
||||
SizeBytes int `json:"size_bytes"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Sha256 string `json:"sha256"`
|
||||
}
|
||||
|
||||
type AttachmentResponse struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
ChatID uuid.UUID `json:"chat_id"`
|
||||
OwnerID uuid.UUID `json:"owner_id"`
|
||||
Filename string `json:"filename"`
|
||||
ContentType string `json:"content_type"`
|
||||
SizeBytes int `json:"size_bytes"`
|
||||
Sha256 string `json:"sha256"`
|
||||
Status string `json:"status"`
|
||||
Variants []VariantResponse `json:"variants"`
|
||||
ErrorCode *string `json:"error_code"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
ChatID uuid.UUID `json:"chat_id"`
|
||||
OwnerID uuid.UUID `json:"owner_id"`
|
||||
Filename string `json:"filename"`
|
||||
ContentType model.ContentType `json:"content_type"`
|
||||
SizeBytes int `json:"size_bytes"`
|
||||
Sha256 string `json:"sha256"`
|
||||
Status model.AttachmentStatus `json:"status"`
|
||||
Variants []VariantResponse `json:"variants"`
|
||||
ErrorCode *string `json:"error_code"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (r CreateAttachmentRequest) Validate() bool {
|
||||
@@ -57,20 +57,39 @@ func (r CreateAttachmentRequest) Validate() bool {
|
||||
}
|
||||
|
||||
func (r GetAttachmentContentRequest) Validate() bool {
|
||||
return r.Variant == "" || r.Variant == "original"
|
||||
switch model.AttachmentVariantName(r.Variant) {
|
||||
case "",
|
||||
model.AttachmentContentOriginal,
|
||||
model.AttachmentVariantNameThumbnail,
|
||||
model.AttachmentVariantNameCrop,
|
||||
model.AttachmentVariantNameOptimized:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func ToAttachmentResponse(a model.Attachment) AttachmentResponse {
|
||||
variants := make([]VariantResponse, 0)
|
||||
variants := make([]VariantResponse, 0, len(a.Variants))
|
||||
for _, v := range a.Variants {
|
||||
variants = append(variants, VariantResponse{
|
||||
Name: v.Name,
|
||||
ContentType: v.ContentType,
|
||||
SizeBytes: v.SizeBytes,
|
||||
Width: v.Width,
|
||||
Height: v.Height,
|
||||
Sha256: v.Sha256,
|
||||
})
|
||||
}
|
||||
return AttachmentResponse{
|
||||
ID: a.ID,
|
||||
ChatID: a.ChatID,
|
||||
OwnerID: a.OwnerID,
|
||||
Filename: a.Filename,
|
||||
ContentType: string(a.ContentType),
|
||||
ContentType: a.ContentType,
|
||||
SizeBytes: a.SizeBytes,
|
||||
Sha256: a.Sha256,
|
||||
Status: string(a.Status),
|
||||
Status: a.Status,
|
||||
Variants: variants,
|
||||
ErrorCode: a.ErrorCode,
|
||||
CreatedAt: a.CreatedAt,
|
||||
|
||||
Reference in New Issue
Block a user