Files
2026-08-19 22:05:49 +08:00

36 lines
922 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package request
import (
"path/filepath"
"strings"
)
type UploadFileRequest struct {
Folder string `json:"folder" validate:"omitempty,oneof=cover avatar article common"`
}
// AllowedUploadExts 上传文件扩展名白名单(扩展名 → 期望的真实 MIME
var AllowedUploadExts = map[string]string{
// 图片
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".gif": "image/gif",
".webp": "image/webp",
// 视频
".mp4": "video/mp4",
".webm": "video/webm",
}
// IsAllowedUploadExt 扩展名是否在白名单内(大小写不敏感)
func IsAllowedUploadExt(ext string) bool {
_, ok := AllowedUploadExts[strings.ToLower(ext)]
return ok
}
// MatchUploadMime 校验实际 MIME 与扩展名匹配
func MatchUploadMime(filename, detectedMime string) bool {
expected, ok := AllowedUploadExts[strings.ToLower(filepath.Ext(filename))]
return ok && detectedMime == expected
}