736 lines
23 KiB
HTML
736 lines
23 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="description" content="Docker镜像搜索">
|
|
<meta name="keywords" content="Docker,镜像搜索,docker search">
|
|
<meta name="color-scheme" content="dark light">
|
|
<title>Docker镜像搜索</title>
|
|
<link rel="icon" href="./favicon.ico">
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://font.sec.miui.com/font/css?family=MiSans:400,700:MiSans">
|
|
<style>
|
|
:root {
|
|
--color: #ffffff;
|
|
--fontcolor: #333;
|
|
--inputcolor: #f5f5f5;
|
|
--inputcolor-font: #333;
|
|
--card-bg: #f8f9fa;
|
|
--border-color: #dee2e6;
|
|
}
|
|
|
|
@media (prefers-color-scheme: dark) {
|
|
:root {
|
|
--color: #53535338;
|
|
--fontcolor: #b8b8b8;
|
|
--inputcolor: #012333;
|
|
--inputcolor-font: #969696d8;
|
|
--card-bg: #012333;
|
|
--border-color: #2d3338;
|
|
}
|
|
}
|
|
|
|
body {
|
|
background-color: var(--color);
|
|
background-image: url('./bj.svg');
|
|
background-position: center;
|
|
background-repeat: no-repeat;
|
|
background-size: cover;
|
|
background-attachment: fixed;
|
|
color: var(--fontcolor);
|
|
font-family: 'Misans', Arial, sans-serif;
|
|
padding: 30px;
|
|
min-height: 100vh;
|
|
margin: 0;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
padding: 20px;
|
|
}
|
|
|
|
h1 {
|
|
color: var(--fontcolor);
|
|
font-weight: bold;
|
|
margin-bottom: 30px;
|
|
text-align: center;
|
|
}
|
|
|
|
.search-container {
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.form-control {
|
|
background-color: var(--inputcolor);
|
|
color: var(--inputcolor-font);
|
|
border-radius: 20px;
|
|
padding: 10px 20px;
|
|
}
|
|
|
|
.form-control:focus {
|
|
background-color: var(--inputcolor);
|
|
color: var(--inputcolor-font);
|
|
}
|
|
|
|
.search-button {
|
|
border-radius: 20px;
|
|
padding: 10px 30px;
|
|
background-color: #39c5bc;
|
|
color: white;
|
|
border: none;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.search-button:hover {
|
|
transform: scale(1.05);
|
|
background-color: #2ea8a0;
|
|
}
|
|
|
|
.result-card {
|
|
background-color: var(--card-bg);
|
|
border-radius: 10px;
|
|
padding: 20px;
|
|
margin-bottom: 20px;
|
|
transition: all 0.3s ease;
|
|
cursor: pointer;
|
|
border: 1px solid var(--border-color);
|
|
}
|
|
|
|
.result-card:hover {
|
|
transform: translateY(-5px);
|
|
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
.result-title {
|
|
font-size: 1.2rem;
|
|
font-weight: bold;
|
|
margin-bottom: 10px;
|
|
color: #39c5bc;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.result-description {
|
|
color: var(--fontcolor);
|
|
margin-bottom: 15px;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.result-meta {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
font-size: 0.9rem;
|
|
color: var(--fontcolor);
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.back-button {
|
|
position: fixed;
|
|
top: 20px;
|
|
left: 20px;
|
|
padding: 2px 8px;
|
|
background-color: #f5f5f5;
|
|
border: 0px solid #eeeeee;
|
|
color: #333;
|
|
border-radius: 10px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
font-size: 14px;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.back-button:hover {
|
|
background-color: #39c5bc;
|
|
color: white;
|
|
transform: scale(1.05);
|
|
text-decoration: none;
|
|
}
|
|
|
|
.loading {
|
|
text-align: center;
|
|
padding: 20px;
|
|
display: none;
|
|
}
|
|
|
|
.loading-spinner {
|
|
width: 40px;
|
|
height: 40px;
|
|
border: 4px solid #f3f3f3;
|
|
border-top: 4px solid #39c5bc;
|
|
border-radius: 50%;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
#toast {
|
|
position: fixed;
|
|
top: 10%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
background-color: #39c5bcde;
|
|
color: white;
|
|
padding: 15px 20px;
|
|
border-radius: 10px;
|
|
font-size: 90%;
|
|
z-index: 1000;
|
|
display: none;
|
|
}
|
|
|
|
.pagination {
|
|
display: flex;
|
|
justify-content: center;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.pagination button {
|
|
margin: 0 5px;
|
|
padding: 5px 15px;
|
|
border: none;
|
|
border-radius: 5px;
|
|
background-color: #39c5bc;
|
|
color: white;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.pagination button:disabled {
|
|
background-color: #cccccc;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.pagination button:hover:not(:disabled) {
|
|
transform: scale(1.05);
|
|
background-color: #2ea8a0;
|
|
}
|
|
|
|
.badge {
|
|
padding: 4px 8px;
|
|
border-radius: 4px;
|
|
font-size: 0.8rem;
|
|
font-weight: normal;
|
|
}
|
|
|
|
.badge-official {
|
|
background-color: #39c5bc;
|
|
color: white;
|
|
}
|
|
|
|
.badge-organization {
|
|
background-color: #6c757d;
|
|
color: white;
|
|
}
|
|
|
|
.tag-list {
|
|
margin-top: 20px;
|
|
display: none;
|
|
}
|
|
|
|
.tag-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 20px;
|
|
padding: 20px;
|
|
background-color: var(--card-bg);
|
|
border-radius: 10px;
|
|
border: 1px solid var(--border-color);
|
|
}
|
|
|
|
.tag-info {
|
|
flex: 1;
|
|
}
|
|
|
|
.tag-title {
|
|
font-size: 1.5rem;
|
|
margin-bottom: 10px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.tag-description {
|
|
color: var(--fontcolor);
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.tag-pull-command {
|
|
background-color: var(--inputcolor);
|
|
padding: 10px 15px;
|
|
border-radius: 5px;
|
|
font-family: monospace;
|
|
margin-top: 10px;
|
|
position: relative;
|
|
}
|
|
|
|
.copy-button {
|
|
position: absolute;
|
|
right: 5px;
|
|
top: 5px;
|
|
background: #39c5bc;
|
|
color: white;
|
|
border: none;
|
|
padding: 2px 8px;
|
|
border-radius: 3px;
|
|
cursor: pointer;
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.tag-item {
|
|
background-color: var(--card-bg);
|
|
border: 1px solid var(--border-color);
|
|
border-radius: 10px;
|
|
padding: 15px;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.tag-name {
|
|
font-size: 1.1rem;
|
|
font-weight: bold;
|
|
margin-bottom: 10px;
|
|
color: #39c5bc;
|
|
}
|
|
|
|
.tag-meta {
|
|
font-size: 0.9rem;
|
|
color: var(--fontcolor);
|
|
opacity: 0.8;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.tag-architectures {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 10px;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.arch-item {
|
|
background-color: var(--inputcolor);
|
|
padding: 5px 10px;
|
|
border-radius: 5px;
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.vulnerability-indicator {
|
|
display: inline-flex;
|
|
gap: 5px;
|
|
margin-left: 10px;
|
|
}
|
|
|
|
.vulnerability-dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
border-radius: 50%;
|
|
display: inline-block;
|
|
}
|
|
|
|
.vulnerability-critical { background-color: #dc3545; }
|
|
.vulnerability-high { background-color: #fd7e14; }
|
|
.vulnerability-medium { background-color: #ffc107; }
|
|
.vulnerability-low { background-color: #28a745; }
|
|
.vulnerability-unknown { background-color: #6c757d; }
|
|
|
|
.search-results {
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.back-to-search {
|
|
margin-bottom: 20px;
|
|
color: #39c5bc;
|
|
cursor: pointer;
|
|
display: none;
|
|
}
|
|
|
|
.back-to-search:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
.meta-item {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
margin-right: 15px;
|
|
color: var(--fontcolor);
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.badge-automated {
|
|
background-color: #28a745;
|
|
color: white;
|
|
margin-left: 5px;
|
|
}
|
|
|
|
.tag-meta {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 15px;
|
|
margin: 10px 0;
|
|
font-size: 0.9rem;
|
|
color: var(--fontcolor);
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.vulnerability-indicator {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 5px;
|
|
margin-left: 10px;
|
|
}
|
|
|
|
.arch-item {
|
|
background-color: var(--inputcolor);
|
|
padding: 5px 10px;
|
|
border-radius: 5px;
|
|
font-size: 0.8rem;
|
|
cursor: help;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<a href="/" class="back-button">返回</a>
|
|
<div class="container">
|
|
<h1>Docker镜像搜索</h1>
|
|
|
|
<div class="search-container">
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" id="searchInput" placeholder="输入镜像名称搜索...">
|
|
<div class="input-group-append">
|
|
<button class="btn search-button" id="searchButton">搜索</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="loading">
|
|
<div class="loading-spinner"></div>
|
|
<p>正在加载...</p>
|
|
</div>
|
|
|
|
<div class="back-to-search">← 返回搜索结果</div>
|
|
|
|
<div class="search-results">
|
|
<div id="searchResults"></div>
|
|
|
|
<div class="pagination">
|
|
<button id="prevPage" disabled>上一页</button>
|
|
<button id="nextPage" disabled>下一页</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="tag-list" id="tagList"></div>
|
|
</div>
|
|
|
|
<div id="toast"></div>
|
|
|
|
<script>
|
|
let currentPage = 1;
|
|
let totalPages = 1;
|
|
let currentQuery = '';
|
|
let currentRepo = null;
|
|
|
|
document.getElementById('searchButton').addEventListener('click', () => {
|
|
currentPage = 1;
|
|
performSearch();
|
|
});
|
|
|
|
document.getElementById('searchInput').addEventListener('keypress', (e) => {
|
|
if (e.key === 'Enter') {
|
|
currentPage = 1;
|
|
performSearch();
|
|
}
|
|
});
|
|
|
|
document.getElementById('prevPage').addEventListener('click', () => {
|
|
if (currentPage > 1) {
|
|
currentPage--;
|
|
performSearch();
|
|
}
|
|
});
|
|
|
|
document.getElementById('nextPage').addEventListener('click', () => {
|
|
if (currentPage < totalPages) {
|
|
currentPage++;
|
|
performSearch();
|
|
}
|
|
});
|
|
|
|
document.querySelector('.back-to-search').addEventListener('click', () => {
|
|
showSearchResults();
|
|
});
|
|
|
|
function showLoading() {
|
|
document.querySelector('.loading').style.display = 'block';
|
|
}
|
|
|
|
function hideLoading() {
|
|
document.querySelector('.loading').style.display = 'none';
|
|
}
|
|
|
|
function showToast(message) {
|
|
const toast = document.getElementById('toast');
|
|
toast.textContent = message;
|
|
toast.style.display = 'block';
|
|
setTimeout(() => {
|
|
toast.style.display = 'none';
|
|
}, 3000);
|
|
}
|
|
|
|
function updatePagination() {
|
|
const prevButton = document.getElementById('prevPage');
|
|
const nextButton = document.getElementById('nextPage');
|
|
|
|
prevButton.disabled = currentPage <= 1;
|
|
nextButton.disabled = currentPage >= totalPages;
|
|
}
|
|
|
|
function showSearchResults() {
|
|
document.querySelector('.search-results').style.display = 'block';
|
|
document.querySelector('.tag-list').style.display = 'none';
|
|
document.querySelector('.back-to-search').style.display = 'none';
|
|
document.querySelector('.search-container').style.display = 'block';
|
|
}
|
|
|
|
function showTagList() {
|
|
document.querySelector('.search-results').style.display = 'none';
|
|
document.querySelector('.tag-list').style.display = 'block';
|
|
document.querySelector('.back-to-search').style.display = 'block';
|
|
document.querySelector('.search-container').style.display = 'none';
|
|
}
|
|
|
|
async function performSearch() {
|
|
const query = document.getElementById('searchInput').value.trim();
|
|
if (!query) {
|
|
showToast('请输入搜索关键词');
|
|
return;
|
|
}
|
|
|
|
currentQuery = query;
|
|
showLoading();
|
|
|
|
try {
|
|
console.log('执行搜索:', query);
|
|
const response = await fetch(`/search?q=${encodeURIComponent(query)}`);
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
throw new Error(data.error || '搜索请求失败');
|
|
}
|
|
|
|
console.log('搜索响应:', data);
|
|
displayResults(data.results);
|
|
} catch (error) {
|
|
console.error('搜索错误:', error);
|
|
showToast(error.message || '搜索失败,请稍后重试');
|
|
} finally {
|
|
hideLoading();
|
|
}
|
|
}
|
|
|
|
function formatNumber(num) {
|
|
if (num >= 1000000000) {
|
|
return (num / 1000000000).toFixed(1) + 'B+';
|
|
}
|
|
if (num >= 1000000) {
|
|
return (num / 1000000).toFixed(1) + 'M+';
|
|
}
|
|
if (num >= 1000) {
|
|
return (num / 1000).toFixed(1) + 'K+';
|
|
}
|
|
return num.toString();
|
|
}
|
|
|
|
function formatTimeAgo(dateString) {
|
|
const date = new Date(dateString);
|
|
const now = new Date();
|
|
const diffTime = Math.abs(now - date);
|
|
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
|
|
|
if (diffDays === 1) return '昨天';
|
|
if (diffDays < 7) return `${diffDays}天前`;
|
|
if (diffDays < 30) return `${Math.floor(diffDays / 7)}周前`;
|
|
if (diffDays < 365) return `${Math.floor(diffDays / 30)}个月前`;
|
|
return `${Math.floor(diffDays / 365)}年前`;
|
|
}
|
|
|
|
function displayResults(results) {
|
|
const resultsContainer = document.getElementById('searchResults');
|
|
resultsContainer.innerHTML = '';
|
|
|
|
if (!results || results.length === 0) {
|
|
resultsContainer.innerHTML = '<div class="text-center">未找到相关镜像</div>';
|
|
return;
|
|
}
|
|
|
|
console.log('显示搜索结果:', results);
|
|
|
|
results.forEach(result => {
|
|
const card = document.createElement('div');
|
|
card.className = 'result-card';
|
|
|
|
// 确保所有字段都有值
|
|
const name = result.repo_name || '';
|
|
const description = result.short_description || '暂无描述';
|
|
const starCount = result.star_count || 0;
|
|
const pullCount = result.pull_count || 0;
|
|
const repoOwner = result.repo_owner || '';
|
|
const repoName = name;
|
|
const officialBadge = result.is_official ? '<span class="badge badge-official">官方</span>' : '';
|
|
const automatedBadge = result.is_automated ? '<span class="badge badge-automated">自动构建</span>' : '';
|
|
|
|
console.log('处理仓库:', {
|
|
name,
|
|
repoOwner,
|
|
repoName,
|
|
isOfficial: result.is_official,
|
|
isAutomated: result.is_automated
|
|
});
|
|
|
|
card.innerHTML = `
|
|
<div class="result-title">
|
|
${repoName}
|
|
${officialBadge}
|
|
</div>
|
|
<div class="result-description">${description}</div>
|
|
<div class="result-meta">
|
|
<span>
|
|
${starCount > 0 ? `<span class="meta-item">⭐ ${formatNumber(starCount)}</span>` : ''}
|
|
${pullCount > 0 ? `<span class="meta-item">⬇️ ${formatNumber(pullCount)}</span>` : ''}
|
|
</span>
|
|
<span class="meta-item">更新于 ${formatTimeAgo(result.last_updated)}</span>
|
|
</div>
|
|
`;
|
|
|
|
card.addEventListener('click', () => {
|
|
console.log('点击仓库:', name, repoOwner);
|
|
currentRepo = result;
|
|
loadTags(repoOwner, name);
|
|
});
|
|
|
|
resultsContainer.appendChild(card);
|
|
});
|
|
}
|
|
|
|
async function loadTags(namespace, name) {
|
|
showLoading();
|
|
try {
|
|
console.log('加载标签:', namespace, name);
|
|
if (!name) {
|
|
showToast('镜像名称不能为空');
|
|
return;
|
|
}
|
|
|
|
const response = await fetch(`/tags/${namespace}/${name}`);
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
throw new Error(data.error || '获取标签信息失败');
|
|
}
|
|
|
|
console.log('标签数据:', data);
|
|
displayTags(data);
|
|
showTagList();
|
|
} catch (error) {
|
|
console.error('加载标签错误:', error);
|
|
showToast(error.message || '获取标签信息失败,请稍后重试');
|
|
} finally {
|
|
hideLoading();
|
|
}
|
|
}
|
|
|
|
function displayTags(tags) {
|
|
const tagList = document.getElementById('tagList');
|
|
const repoName = currentRepo.namespace ? `${currentRepo.namespace}/${currentRepo.name}` : currentRepo.name;
|
|
|
|
let header = `
|
|
<div class="tag-header">
|
|
<div class="tag-info">
|
|
<div class="tag-title">
|
|
${repoName}
|
|
${currentRepo.is_official ? '<span class="badge badge-official">官方</span>' : ''}
|
|
</div>
|
|
<div class="tag-description">${currentRepo.description || '暂无描述'}</div>
|
|
<div class="tag-meta">
|
|
${currentRepo.star_count > 0 ? `<span class="meta-item">⭐ ${formatNumber(currentRepo.star_count)}</span>` : ''}
|
|
${currentRepo.pull_count > 0 ? `<span class="meta-item">⬇️ ${formatNumber(currentRepo.pull_count)}</span>` : ''}
|
|
<span class="meta-item">更新于 ${formatTimeAgo(currentRepo.last_updated)}</span>
|
|
</div>
|
|
<div class="tag-pull-command">
|
|
docker pull ${repoName}
|
|
<button class="copy-button" onclick="copyToClipboard('docker pull ${repoName}')">复制</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
let tagsHtml = tags.map(tag => {
|
|
const vulnIndicators = Object.entries(tag.vulnerabilities || {})
|
|
.map(([level, count]) => count > 0 ? `<span class="vulnerability-dot vulnerability-${level.toLowerCase()}" title="${level}: ${count}"></span>` : '')
|
|
.join('');
|
|
|
|
const images = tag.images || [];
|
|
const architectures = images.map(img => {
|
|
const arch = `${img.os}/${img.architecture}${img.variant ? '/' + img.variant : ''}`;
|
|
const size = formatSize(img.size);
|
|
return `<div class="arch-item" title="大小: ${size}">${arch}</div>`;
|
|
}).join('');
|
|
|
|
return `
|
|
<div class="tag-item">
|
|
<div class="tag-name">
|
|
${tag.name}
|
|
${vulnIndicators ? `<div class="vulnerability-indicator">${vulnIndicators}</div>` : ''}
|
|
</div>
|
|
<div class="tag-meta">
|
|
<span>最后更新: ${formatTimeAgo(tag.last_updated)}</span>
|
|
${tag.last_pusher ? `<span>由 ${tag.last_pusher} 推送</span>` : ''}
|
|
${tag.full_size ? `<span>大小: ${formatSize(tag.full_size)}</span>` : ''}
|
|
</div>
|
|
<div class="tag-pull-command">
|
|
docker pull ${repoName}:${tag.name}
|
|
<button class="copy-button" onclick="copyToClipboard('docker pull ${repoName}:${tag.name}')">复制</button>
|
|
</div>
|
|
${architectures ? `<div class="tag-architectures">${architectures}</div>` : ''}
|
|
</div>
|
|
`;
|
|
}).join('');
|
|
|
|
tagList.innerHTML = header + tagsHtml;
|
|
}
|
|
|
|
function formatSize(bytes) {
|
|
const units = ['B', 'KB', 'MB', 'GB'];
|
|
let size = bytes;
|
|
let unitIndex = 0;
|
|
|
|
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
size /= 1024;
|
|
unitIndex++;
|
|
}
|
|
|
|
return `${size.toFixed(2)} ${units[unitIndex]}`;
|
|
}
|
|
|
|
function copyToClipboard(text) {
|
|
navigator.clipboard.writeText(text).then(() => {
|
|
showToast('已复制到剪贴板');
|
|
}).catch(() => {
|
|
showToast('复制失败');
|
|
});
|
|
}
|
|
|
|
// 初始加载
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const initialQuery = urlParams.get('q');
|
|
if (initialQuery) {
|
|
document.getElementById('searchInput').value = initialQuery;
|
|
performSearch();
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |