You've already forked VptPassiveAdapter
feat(api): 添加图像处理配置和服务器端图像处理功能
- 新增 CompressionConfig、ThumbnailConfig 和 ImageProcessingConfig 结构体用于图像处理配置 - 实现 GetEffectiveConfig 方法提供图像处理配置的默认值 - 在 UploadConfig 中添加 ImageProcessing 字段传递服务器配置 - 移除客户端本地缩略图生成功能,改用服务器端处理 - 添加 UploadFaceDataWithProcessing 函数实现带图像处理的上传流程 - 实现 configToImageOptions 函数将服务器配置转换为图像处理选项 - 在 util/image.go 中添加完整的图像处理功能,支持裁切和缩放模式 - 更新依赖添加 golang.org/x/image 用于高质量图像缩放 - 添加 .claude 到 .gitignore 文件
This commit is contained in:
@@ -69,12 +69,64 @@ func ProxyRequest(ctx context.Context, method, path string, body io.Reader, head
|
||||
|
||||
// Upload Proxy Structures
|
||||
|
||||
// CompressionConfig 压缩配置
|
||||
type CompressionConfig struct {
|
||||
Enabled bool `json:"enabled"` // 是否启用压缩
|
||||
Quality int `json:"quality"` // 压缩质量 (1-100)
|
||||
}
|
||||
|
||||
// ThumbnailConfig 缩略图配置
|
||||
type ThumbnailConfig struct {
|
||||
Mode string `json:"mode"` // 缩略图模式: "cut"(裁切) 或 "shrink"(缩放)
|
||||
ShrinkRatio float64 `json:"shrinkRatio"` // 缩放/裁切比例 (0-1)
|
||||
Quality int `json:"quality"` // 缩略图压缩质量 (1-100)
|
||||
}
|
||||
|
||||
// ImageProcessingConfig 图像处理配置
|
||||
type ImageProcessingConfig struct {
|
||||
SourceCompression *CompressionConfig `json:"sourceCompression,omitempty"` // 原图压缩配置
|
||||
Thumbnail *ThumbnailConfig `json:"thumbnail,omitempty"` // 缩略图配置
|
||||
}
|
||||
|
||||
// GetEffectiveConfig 返回有效的图像处理配置(应用默认值)
|
||||
// 默认值:原图不压缩;缩略图裁切模式,比例0.5,质量75
|
||||
func (c *ImageProcessingConfig) GetEffectiveConfig() *ImageProcessingConfig {
|
||||
effective := &ImageProcessingConfig{
|
||||
SourceCompression: &CompressionConfig{
|
||||
Enabled: false, // 默认不压缩原图
|
||||
Quality: 100,
|
||||
},
|
||||
Thumbnail: &ThumbnailConfig{
|
||||
Mode: "cut", // 默认裁切模式
|
||||
ShrinkRatio: 0.5, // 默认比例0.5
|
||||
Quality: 75, // 默认质量75
|
||||
},
|
||||
}
|
||||
|
||||
if c == nil {
|
||||
return effective
|
||||
}
|
||||
|
||||
// 覆盖原图压缩配置
|
||||
if c.SourceCompression != nil {
|
||||
effective.SourceCompression = c.SourceCompression
|
||||
}
|
||||
|
||||
// 覆盖缩略图配置
|
||||
if c.Thumbnail != nil {
|
||||
effective.Thumbnail = c.Thumbnail
|
||||
}
|
||||
|
||||
return effective
|
||||
}
|
||||
|
||||
type UploadConfig struct {
|
||||
TaskID int64 `json:"taskId"`
|
||||
FaceUploadURL string `json:"faceUploadUrl"`
|
||||
ThumbnailUploadURL string `json:"thumbnailUploadUrl"`
|
||||
SourceUploadURL string `json:"sourceUploadUrl"`
|
||||
ExpiresAt time.Time `json:"expiresAt"`
|
||||
TaskID int64 `json:"taskId"`
|
||||
FaceUploadURL string `json:"faceUploadUrl"`
|
||||
ThumbnailUploadURL string `json:"thumbnailUploadUrl"`
|
||||
SourceUploadURL string `json:"sourceUploadUrl"`
|
||||
ExpiresAt time.Time `json:"expiresAt"`
|
||||
ImageProcessing *ImageProcessingConfig `json:"imageProcessing,omitempty"` // 图像处理配置
|
||||
}
|
||||
|
||||
type ProxyResponse struct {
|
||||
|
||||
Reference in New Issue
Block a user