hi-server/internal/logic/common/getappversionlogic.go
shanshanzhong 1d81df6664
Some checks failed
Build docker and publish / build (20.15.1) (push) Has been cancelled
add:添加短链接服务
2026-01-24 00:32:08 -08:00

64 lines
1.7 KiB
Go

package common
import (
"context"
"encoding/json"
"github.com/perfect-panel/server/internal/model/client"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/logger"
)
type GetAppVersionLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// NewGetAppVersionLogic 获取 App 版本信息
func NewGetAppVersionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAppVersionLogic {
return &GetAppVersionLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// GetAppVersion 根据平台返回最新版本信息
func (l *GetAppVersionLogic) GetAppVersion(req *types.GetAppVersionRequest) (resp *types.ApplicationVersion, err error) {
// Query the latest version for the platform
var version client.ApplicationVersion
err = l.svcCtx.DB.Model(&client.ApplicationVersion{}).
Where("platform = ? AND is_default = 1", req.Platform).
Order("id desc").First(&version).Error
if err != nil {
l.Errorf("[GetAppVersion] get version error: %v", err)
// Return empty or default if not found
return &types.ApplicationVersion{
Version: "unknown",
MinVersion: "unknown",
ForceUpdate: false,
Description: map[string]string{},
IsDefault: false,
}, nil
}
resp = &types.ApplicationVersion{
Id: version.Id,
Platform: version.Platform,
Version: version.Version,
MinVersion: version.MinVersion,
ForceUpdate: version.ForceUpdate,
Description: make(map[string]string),
Url: version.Url,
IsDefault: version.IsDefault,
IsInReview: version.IsInReview,
CreatedAt: version.CreatedAt.Unix(),
}
_ = json.Unmarshal(version.Description, &resp.Description)
return resp, nil
}