webp fix v1

This commit is contained in:
tamakyi
2026-10-15 11:41:19 +08:00
parent 6ffc87e4a8
commit e4457e3da4
15 changed files with 1297 additions and 39 deletions
+12 -1
View File
@@ -14,6 +14,15 @@ import (
// MaxUploadBytes 与真实实现保持一致(8MB 单图上限,bodylimit 中间件依赖此值语义)。
const MaxUploadBytes = 8 * 1024 * 1024
// EncodeSpec 与真实实现的编码档位结构保持字段一致。
type EncodeSpec struct {
MaxSide int
Quality float32
}
// GeneralEncodeSpec 与真实实现保持一致(route/question 引用)。
var GeneralEncodeSpec = EncodeSpec{MaxSide: 1600, Quality: 80}
func UploadPictureToS3(file multipart.File, fileHeader *multipart.FileHeader) (string, error) {
return "", nil
}
@@ -26,6 +35,8 @@ func UploadBackgroundToS3(file multipart.File, fileHeader *multipart.FileHeader)
return "", nil
}
func ConvertStaticImageToWebP(r io.Reader) ([]byte, error) { return nil, nil }
func ConvertStaticImageToWebP(r io.Reader, spec EncodeSpec) ([]byte, error) { return nil, nil }
func ConvertGifToAnimatedWebP(gifData []byte) ([]byte, error) { return nil, nil }
func isSupportedImage(data []byte) bool { return true }
+10 -3
View File
@@ -1,6 +1,7 @@
// webpstub(package webp)是 chai2010/webp 的本地编译桩:仅用于在缺少 libwebp 的
// Windows 沙箱中通过 `go build -overlay` 对依赖 internal/storage 的包做完整
// 类型检查。API 只覆盖项目实际用到的 Encode/Options。
// Windows 沙箱中通过 `go build -overlay` 替换 chai2010/webp 的全部源文件,
// 从而让真实的 internal/storage/s3.go(而非桩)参与完整类型检查。
// 仅覆盖项目实际用到的 API。
package webp
import (
@@ -8,13 +9,19 @@ import (
"io"
)
// Options 与 github.com/chai2010/webp 的 Options 字段保持兼容(项目仅用 Quality)。
// Options 与 github.com/chai2010/webp 的 Options 字段保持兼容。
type Options struct {
Lossless bool
Quality float32
Exact bool
}
// Encode 是 webp.Encode 的签名兼容桩(类型检查期间不会被真正调用)。
func Encode(w io.Writer, m image.Image, o *Options) error {
return nil
}
// DecodeConfig / Decode 保留解码入口签名,供 s3.go 的 image.Decode 分派路径类型检查。
func DecodeConfig(r io.Reader) (image.Config, error) { return image.Config{}, nil }
func Decode(r io.Reader) (image.Image, error) { return nil, nil }