修复tag页面
This commit is contained in:
@@ -528,13 +528,24 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('搜索结果:', results);
|
||||||
|
|
||||||
results.forEach(result => {
|
results.forEach(result => {
|
||||||
|
console.log('处理结果:', result);
|
||||||
|
|
||||||
const card = document.createElement('div');
|
const card = document.createElement('div');
|
||||||
card.className = 'result-card';
|
card.className = 'result-card';
|
||||||
|
|
||||||
const stars = result.star_count ? `⭐ ${formatNumber(result.star_count)}` : '';
|
const name = result.name || '';
|
||||||
const pulls = result.pull_count ? `⬇️ ${formatNumber(result.pull_count)}` : '';
|
const namespace = result.namespace || '';
|
||||||
const repoName = result.namespace ? `${result.namespace}/${result.name}` : result.name;
|
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 officialBadge = result.is_official ? '<span class="badge badge-official">官方</span>' : '';
|
||||||
const orgBadge = result.organization ? `<span class="badge badge-organization">By ${result.organization}</span>` : '';
|
const orgBadge = result.organization ? `<span class="badge badge-organization">By ${result.organization}</span>` : '';
|
||||||
|
|
||||||
@@ -544,10 +555,10 @@
|
|||||||
${officialBadge}
|
${officialBadge}
|
||||||
${orgBadge}
|
${orgBadge}
|
||||||
</div>
|
</div>
|
||||||
<div class="result-description">${result.description || '暂无描述'}</div>
|
<div class="result-description">${description}</div>
|
||||||
<div class="result-meta">
|
<div class="result-meta">
|
||||||
<span>${stars} ${pulls}</span>
|
<span>${stars} ${pulls}</span>
|
||||||
<span>更新于 ${formatTimeAgo(result.last_updated)}</span>
|
<span>更新于 ${formatTimeAgo(lastUpdated)}</span>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -126,6 +127,13 @@ func searchDockerHub(ctx context.Context, query string, page, pageSize int) (*Se
|
|||||||
return nil, err
|
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)
|
setCacheResult(cacheKey, &result)
|
||||||
return &result, nil
|
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", fmt.Sprintf("%d", page))
|
||||||
params.Set("page_size", fmt.Sprintf("%d", pageSize))
|
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 {
|
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)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
fmt.Printf("发送标签请求失败: %v\n", err)
|
||||||
|
return nil, fmt.Errorf("发送标签请求失败: %v", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
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 {
|
var result struct {
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
Next string `json:"next"`
|
Next string `json:"next"`
|
||||||
Previous string `json:"previous"`
|
Previous string `json:"previous"`
|
||||||
Results []TagInfo `json:"results"`
|
Results []TagInfo `json:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
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)
|
setCacheResult(cacheKey, result.Results)
|
||||||
return result.Results, nil
|
return result.Results, nil
|
||||||
}
|
}
|
||||||
@@ -200,6 +228,10 @@ func RegisterSearchRoute(r *gin.Engine) {
|
|||||||
r.GET("/tags/:namespace/:name", func(c *gin.Context) {
|
r.GET("/tags/:namespace/:name", func(c *gin.Context) {
|
||||||
namespace := c.Param("namespace")
|
namespace := c.Param("namespace")
|
||||||
name := c.Param("name")
|
name := c.Param("name")
|
||||||
|
|
||||||
|
// 打印请求参数
|
||||||
|
fmt.Printf("获取标签请求: namespace=%s, name=%s\n", namespace, name)
|
||||||
|
|
||||||
page := 1
|
page := 1
|
||||||
pageSize := 100
|
pageSize := 100
|
||||||
if p := c.Query("page"); p != "" {
|
if p := c.Query("page"); p != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user