邀请
This commit is contained in:
@@ -32,7 +32,7 @@ func (l *GetDownloadLinkLogic) GetDownloadLink(req *types.GetDownloadLinkRequest
|
||||
host := l.svcCtx.Config.Site.Host
|
||||
if host == "" {
|
||||
// 保底域名
|
||||
host = "tapi.airoport.co"
|
||||
host = "api.airoport.co"
|
||||
}
|
||||
|
||||
// 2. 版本号 (后续可以从数据库或配置中读取)
|
||||
@@ -53,8 +53,13 @@ func (l *GetDownloadLinkLogic) GetDownloadLink(req *types.GetDownloadLinkRequest
|
||||
ext = ".bin"
|
||||
}
|
||||
|
||||
// 4. 构建文件名: 平台-版本号-ic_邀请码.扩展名
|
||||
filename := fmt.Sprintf("%s-%s-ic_%s%s", req.Platform, version, req.InviteCode, ext)
|
||||
// 4. 构建文件名: 平台-版本号[-ic_邀请码].扩展名
|
||||
var filename string
|
||||
if req.InviteCode != "" {
|
||||
filename = fmt.Sprintf("%s-%s-ic_%s%s", req.Platform, version, req.InviteCode, ext)
|
||||
} else {
|
||||
filename = fmt.Sprintf("%s-%s%s", req.Platform, version, ext)
|
||||
}
|
||||
|
||||
// 5. 构建完整 URL (Nginx 会拦截此路径进行虚拟更名处理)
|
||||
url := fmt.Sprintf("https://%s/v1/common/client/download/file/%s", host, filename)
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/perfect-panel/server/internal/config"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetDownloadLinkLogic_GetDownloadLink(t *testing.T) {
|
||||
svcCtx := &svc.ServiceContext{
|
||||
Config: config.Config{
|
||||
Site: config.SiteConfig{
|
||||
Host: "test.example.com",
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := context.Background()
|
||||
l := NewGetDownloadLinkLogic(ctx, svcCtx)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
req *types.GetDownloadLinkRequest
|
||||
wantSubStr []string // strings that should be in the URL
|
||||
notSubStr []string // strings that should NOT be in the URL
|
||||
}{
|
||||
{
|
||||
name: "With Invite Code",
|
||||
req: &types.GetDownloadLinkRequest{
|
||||
Platform: "windows",
|
||||
InviteCode: "TESTCODE",
|
||||
},
|
||||
wantSubStr: []string{"-ic_TESTCODE.exe"},
|
||||
notSubStr: []string{},
|
||||
},
|
||||
{
|
||||
name: "Without Invite Code",
|
||||
req: &types.GetDownloadLinkRequest{
|
||||
Platform: "mac",
|
||||
InviteCode: "",
|
||||
},
|
||||
wantSubStr: []string{".dmg"},
|
||||
notSubStr: []string{"-ic", "ic_"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
resp, err := l.GetDownloadLink(tt.req)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
|
||||
for _, s := range tt.wantSubStr {
|
||||
assert.Contains(t, resp.Url, s)
|
||||
}
|
||||
for _, s := range tt.notSubStr {
|
||||
assert.NotContains(t, resp.Url, s)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user