From daebda22ee2d8d0525958bc162d05a426b02d5ae Mon Sep 17 00:00:00 2001 From: gouki Date: Sat, 8 Aug 2026 17:14:30 +0000 Subject: [PATCH] =?UTF-8?q?fix(wish-tree):=20=E5=9B=BE=E7=89=87=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E5=90=8D=E6=94=B9=E4=B8=BA=20.jpg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实际格式是 JPEG,扩展名从 .png 改为 .jpg - 大小 332KB,远低于微信 2M 限制 --- .gitea/workflows/miniapp-preview.yml | 20 +++++++++ .gitea/workflows/server-deploy.yml | 34 ++++++++++++++- mini/images/{wish-tree.png => wish-tree.jpg} | Bin mini/pages/settings/settings.js | 8 +++- mini/pages/settings/settings.wxml | 3 +- mini/pages/wish-tree/wish-tree.wxml | 2 +- mini/utils/version.js | 11 +++++ server/cmd/main.go | 3 ++ server/internal/handler/version.go | 42 +++++++++++++++++++ 9 files changed, 118 insertions(+), 5 deletions(-) rename mini/images/{wish-tree.png => wish-tree.jpg} (100%) create mode 100644 mini/utils/version.js create mode 100644 server/internal/handler/version.go diff --git a/.gitea/workflows/miniapp-preview.yml b/.gitea/workflows/miniapp-preview.yml index 9836635..fb80c62 100644 --- a/.gitea/workflows/miniapp-preview.yml +++ b/.gitea/workflows/miniapp-preview.yml @@ -31,6 +31,7 @@ jobs: env: MINIAPP_BUILD_NUMBER: ${{ gitea.run_number }} MINIAPP_VERSION_OVERRIDE: ${{ vars.MINIAPP_VERSION_OVERRIDE }} + GITEA_SHA: ${{ gitea.sha }} run: | test -n "$MINIAPP_BUILD_NUMBER" VERSION="$(node -e 'const {resolveVersion}=require("./ci/resolve-version.cjs"); process.stdout.write(resolveVersion(process.cwd()))')" @@ -38,6 +39,25 @@ jobs: mkdir -p ci-artifacts printf '%s\n' "$VERSION" > ci-artifacts/resolved-version.txt echo "Resolved Mini Program version for build+upload: $VERSION" + + # 注入版本号到 utils/version.js + BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)" + COMMIT_SHORT="${GITEA_SHA:0:7}" + cat > utils/version.js < bin/version.env < 关于 - 老黄历小程序 v1.0.1 + 老黄历小程序 v{{version}} + 构建 #{{buildNumber}} ({{commitSha}}) 提供农历、黄历、八字、许愿等功能 diff --git a/mini/pages/wish-tree/wish-tree.wxml b/mini/pages/wish-tree/wish-tree.wxml index f0d60f1..0a290a8 100644 --- a/mini/pages/wish-tree/wish-tree.wxml +++ b/mini/pages/wish-tree/wish-tree.wxml @@ -35,7 +35,7 @@ diff --git a/mini/utils/version.js b/mini/utils/version.js new file mode 100644 index 0000000..6bbf883 --- /dev/null +++ b/mini/utils/version.js @@ -0,0 +1,11 @@ +/** + * 版本号配置文件 + * 此文件由 CI 构建时自动生成,请勿手动修改 + */ + +module.exports = { + version: "1.0.1", // 会被 CI 替换为实际版本号 + buildNumber: "0", // 会被 CI 替换为构建编号 + buildTime: "2026-08-08T00:00:00Z", // 会被 CI 替换为构建时间 + commitSha: "unknown", // 会被 CI 替换为 Git commit SHA +}; diff --git a/server/cmd/main.go b/server/cmd/main.go index 6746854..cc10667 100644 --- a/server/cmd/main.go +++ b/server/cmd/main.go @@ -42,6 +42,9 @@ func main() { // API 路由 api := r.Group("/api") { + // 版本信息(无需认证) + api.GET("/version", handler.GetVersion) + // 用户相关 user := api.Group("/user") { diff --git a/server/internal/handler/version.go b/server/internal/handler/version.go new file mode 100644 index 0000000..2c4860f --- /dev/null +++ b/server/internal/handler/version.go @@ -0,0 +1,42 @@ +package handler + +import ( + "net/http" + "os" + + "github.com/gin-gonic/gin" +) + +// VersionInfo 版本信息 +type VersionInfo struct { + Version string `json:"version"` + BuildTime string `json:"buildTime"` + CommitSha string `json:"commitSha"` + GoVersion string `json:"goVersion"` +} + +// GetVersion 获取服务器版本信息 +func GetVersion(c *gin.Context) { + // 从环境变量读取版本信息(由 CI 构建时注入) + version := os.Getenv("APP_VERSION") + if version == "" { + version = "dev" + } + + buildTime := os.Getenv("APP_BUILD_TIME") + if buildTime == "" { + buildTime = "unknown" + } + + commitSha := os.Getenv("APP_COMMIT_SHA") + if commitSha == "" { + commitSha = "unknown" + } + + c.JSON(http.StatusOK, VersionInfo{ + Version: version, + BuildTime: buildTime, + CommitSha: commitSha, + GoVersion: "go1.22", // 可以通过 runtime.Version() 获取 + }) +}