Files
RenewCMS/internal/domain/image/imageDomain.go
T

50 lines
1.1 KiB
Go

package image
import (
"errors"
"io"
"sort"
"time"
)
var ErrImageNotFound = errors.New("image not found")
var ErrImageTypeNotAllowed = errors.New("the file must be a PNG, JPEG, WEBP, or SVG image")
var ErrImageTooLarge = errors.New("the file exceeds the maximum upload size")
const MaxImageSize int64 = 10485760
var allowedContentTypes = map[string]bool{
"image/png": true,
"image/jpeg": true,
"image/webp": true,
"image/svg+xml": true,
}
func IsAllowedContentType(contentType string) bool {
return allowedContentTypes[contentType]
}
func AllowedContentTypes() []string {
types := make([]string, 0, len(allowedContentTypes))
for contentType := range allowedContentTypes {
types = append(types, contentType)
}
sort.Strings(types)
return types
}
type ImageInput struct {
Content io.Reader
Filename string
Size int64
ContentType string
}
type Image struct {
ID uint32 `json:"id"`
Path string `json:"path"`
ArticleID uint32 `json:"article_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}