修复tag页面

This commit is contained in:
NewName
2025-05-20 16:16:12 +08:00
parent fb572974ce
commit 8cf5243134
2 changed files with 52 additions and 9 deletions

View File

@@ -528,13 +528,24 @@
return;
}
console.log('搜索结果:', results);
results.forEach(result => {
console.log('处理结果:', result);
const card = document.createElement('div');
card.className = 'result-card';
const stars = result.star_count ? `${formatNumber(result.star_count)}` : '';
const pulls = result.pull_count ? `⬇️ ${formatNumber(result.pull_count)}` : '';
const repoName = result.namespace ? `${result.namespace}/${result.name}` : result.name;
const name = result.name || '';
const namespace = result.namespace || '';
const description = result.description || '暂无描述';
const starCount = result.star_count || 0;
const pullCount = result.pull_count || 0;
const lastUpdated = result.last_updated || new Date();
const stars = starCount ? `${formatNumber(starCount)}` : '';
const pulls = pullCount ? `⬇️ ${formatNumber(pullCount)}` : '';
const repoName = namespace ? `${namespace}/${name}` : name;
const officialBadge = result.is_official ? '<span class="badge badge-official">官方</span>' : '';
const orgBadge = result.organization ? `<span class="badge badge-organization">By ${result.organization}</span>` : '';
@@ -544,10 +555,10 @@
${officialBadge}
${orgBadge}
</div>
<div class="result-description">${result.description || '暂无描述'}</div>
<div class="result-description">${description}</div>
<div class="result-meta">
<span>${stars} ${pulls}</span>
<span>更新于 ${formatTimeAgo(result.last_updated)}</span>
<span>更新于 ${formatTimeAgo(lastUpdated)}</span>
</div>
`;

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"sync"
@@ -126,6 +127,13 @@ func searchDockerHub(ctx context.Context, query string, page, pageSize int) (*Se
return nil, err
}
// 添加调试日志
fmt.Printf("搜索结果: 总数=%d, 结果数=%d\n", result.Count, len(result.Results))
for i, repo := range result.Results {
fmt.Printf("仓库[%d]: 名称=%s, 命名空间=%s, 描述=%s, 是否官方=%v\n",
i, repo.Name, repo.Namespace, repo.Description, repo.IsOfficial)
}
setCacheResult(cacheKey, &result)
return &result, nil
}
@@ -148,27 +156,47 @@ func getRepositoryTags(ctx context.Context, namespace, name string, page, pageSi
params.Set("page", fmt.Sprintf("%d", page))
params.Set("page_size", fmt.Sprintf("%d", pageSize))
req, err := http.NewRequestWithContext(ctx, "GET", baseURL+"?"+params.Encode(), nil)
fullURL := baseURL + "?" + params.Encode()
fmt.Printf("请求标签URL: %s\n", fullURL)
req, err := http.NewRequestWithContext(ctx, "GET", fullURL, nil)
if err != nil {
return nil, err
fmt.Printf("创建标签请求失败: %v\n", err)
return nil, fmt.Errorf("创建标签请求失败: %v", err)
}
// 添加必要的请求头
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
fmt.Printf("发送标签请求失败: %v\n", err)
return nil, fmt.Errorf("发送标签请求失败: %v", err)
}
defer resp.Body.Close()
// 检查响应状态码
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
fmt.Printf("获取标签失败: 状态码=%d, 响应体=%s\n", resp.StatusCode, string(body))
return nil, fmt.Errorf("获取标签失败: 状态码=%d", resp.StatusCode)
}
var result struct {
Count int `json:"count"`
Next string `json:"next"`
Previous string `json:"previous"`
Results []TagInfo `json:"results"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return nil, err
fmt.Printf("解析标签响应失败: %v\n", err)
return nil, fmt.Errorf("解析标签响应失败: %v", err)
}
fmt.Printf("获取到标签: 总数=%d, 结果数=%d\n", result.Count, len(result.Results))
setCacheResult(cacheKey, result.Results)
return result.Results, nil
}
@@ -200,6 +228,10 @@ func RegisterSearchRoute(r *gin.Engine) {
r.GET("/tags/:namespace/:name", func(c *gin.Context) {
namespace := c.Param("namespace")
name := c.Param("name")
// 打印请求参数
fmt.Printf("获取标签请求: namespace=%s, name=%s\n", namespace, name)
page := 1
pageSize := 100
if p := c.Query("page"); p != "" {