新增编译脚本和 github 工作流配置文件

This commit is contained in:
2026-01-26 22:48:48 +08:00
parent 50275265ac
commit 950a9aef9d
15 changed files with 416 additions and 83 deletions

View File

@@ -19,8 +19,8 @@ import (
// @Description 根据参数返回今日必应图片流或重定向
// @Tags image
// @Param variant query string false "分辨率 (UHD, 1920x1080, 1366x768)" default(UHD)
// @Param format query string false "格式 (jpg, webp)" default(jpg)
// @Produce image/jpeg,image/webp
// @Param format query string false "格式 (jpg)" default(jpg)
// @Produce image/jpeg
// @Success 200 {file} binary
// @Router /image/today [get]
func GetToday(c *gin.Context) {
@@ -54,7 +54,7 @@ func GetTodayMeta(c *gin.Context) {
// @Tags image
// @Param variant query string false "分辨率" default(UHD)
// @Param format query string false "格式" default(jpg)
// @Produce image/jpeg,image/webp
// @Produce image/jpeg
// @Success 200 {file} binary
// @Router /image/random [get]
func GetRandom(c *gin.Context) {
@@ -89,7 +89,7 @@ func GetRandomMeta(c *gin.Context) {
// @Param date path string true "日期 (yyyy-mm-dd)"
// @Param variant query string false "分辨率" default(UHD)
// @Param format query string false "格式" default(jpg)
// @Produce image/jpeg,image/webp
// @Produce image/jpeg
// @Success 200 {file} binary
// @Router /image/date/{date} [get]
func GetByDate(c *gin.Context) {

View File

@@ -6,10 +6,10 @@ import (
"BingPaper/internal/util"
"fmt"
"github.com/glebarez/sqlite"
"go.uber.org/zap"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)

View File

@@ -18,8 +18,6 @@ import (
"BingPaper/internal/repo"
"BingPaper/internal/storage"
"BingPaper/internal/util"
"github.com/chai2010/webp"
"github.com/disintegration/imaging"
"go.uber.org/zap"
)
@@ -146,19 +144,6 @@ func (f *Fetcher) processImage(ctx context.Context, bingImg BingImage) error {
util.Logger.Error("Failed to save variant", zap.String("variant", v.name), zap.Error(err))
}
// 保存 WebP (可选或默认)
webpBuf := new(bytes.Buffer)
var webpImg image.Image
if v.width == 0 {
webpImg = srcImg
} else {
webpImg = imaging.Fill(srcImg, v.width, v.height, imaging.Center, imaging.Lanczos)
}
if err := webp.Encode(webpBuf, webpImg, &webp.Options{Quality: 80}); err == nil {
if err := f.saveVariant(ctx, &dbImg, v.name, "webp", webpBuf.Bytes()); err != nil {
util.Logger.Error("Failed to save webp variant", zap.String("variant", v.name), zap.Error(err))
}
}
}
// 保存今日额外文件
@@ -221,14 +206,6 @@ func (f *Fetcher) saveDailyFiles(srcImg image.Image, originalData []byte) {
}
os.MkdirAll(filepath.Join(localRoot, "static"), 0755)
// daily.webp (quality 80)
webpPath := filepath.Join(localRoot, "static", "daily.webp")
fWebp, _ := os.Create(webpPath)
if fWebp != nil {
webp.Encode(fWebp, srcImg, &webp.Options{Quality: 80})
fWebp.Close()
}
// daily.jpeg (quality 95)
jpegPath := filepath.Join(localRoot, "static", "daily.jpeg")
fJpeg, _ := os.Create(jpegPath)