feat(attachments): add upload, metadata and content endpoints
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"mtusi2026-messenger/internal/model"
|
||||
)
|
||||
|
||||
type CreateAttachmentRequest struct {
|
||||
Filename string
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
func (r CreateAttachmentRequest) Validate() bool {
|
||||
if n := utf8.RuneCountInString(r.Filename); n < 1 || n > 255 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, ch := range r.Filename {
|
||||
if ch == '/' || ch == '\\' || ch == 0 || unicode.IsControl(ch) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func ToAttachmentResponse(a model.Attachment) AttachmentResponse {
|
||||
variants := make([]VariantResponse, 0)
|
||||
return AttachmentResponse{
|
||||
ID: a.ID,
|
||||
ChatID: a.ChatID,
|
||||
OwnerID: a.OwnerID,
|
||||
Filename: a.Filename,
|
||||
ContentType: string(a.ContentType),
|
||||
SizeBytes: a.SizeBytes,
|
||||
Sha256: a.Sha256,
|
||||
Status: string(a.Status),
|
||||
Variants: variants,
|
||||
ErrorCode: a.ErrorCode,
|
||||
CreatedAt: a.CreatedAt,
|
||||
UpdatedAt: a.UpdatedAt,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user