Repository navigation
Expand file tree
/
Copy pathimages.html
More file actions
187 lines (174 loc) · 5.65 KB
/
Copy pathimages.html
File metadata and controls
187 lines (174 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>S3 镜像下载页</title>
<style>
body {
font-family: "Segoe UI", Arial, sans-serif;
margin: 40px;
background: #fafafa;
}
#main-container {
border: 2px dotted #ccc;
padding: 30px;
max-width: 900px;
margin: auto;
background: #fff;
}
.build-box {
border: 2px solid #444;
margin-bottom: 20px;
background: #fff;
padding: 15px 25px;
}
.build-row {
display: flex;
justify-content: space-between;
align-items: flex-start;
}
.build-meta {
font-size: 18px;
}
.downloads-list {
margin-top: 10px;
}
.downloads-list a {
margin-right: 15px;
color: #b23b3b;
text-decoration: underline;
font-size: 16px;
}
.downloads-title {
font-weight: bold;
margin-bottom: 3px;
}
.downloads-title,
.downloads-list {
text-align: right;
}
</style>
</head>
<body>
<div id="main-container">
<h2>Latest build: <span id="latest-build">loading...</span></h2>
<div id="build-list"></div>
</div>
<script>
const SOURCES = [
{
name: "MinIO",
url: "http://43.248.129.240:9000",
buckets: [
{ name: "cloud", bucket: "hostbee-cloud-images" },
{ name: "cloud-cn", bucket: "hostbee-cloud-images-cn" },
],
},
];
const buildListDiv = document.getElementById("build-list");
const latestBuildSpan = document.getElementById("latest-build");
// 你要列出的镜像类型
const FILE_TYPES = [{ name: ".img", desc: "" }];
async function fetchText(url) {
const resp = await fetch(url, { cache: "no-store" });
if (!resp.ok) throw new Error("Network");
return (await resp.text()).trim();
}
async function fetchLatestBuild() {
for (const src of SOURCES) {
// 遍历每个源(如 MinIO、R2)
for (const bucketObj of src.buckets) {
// 遍历当前源下的每个桶
const url = `${src.url}/${bucketObj.bucket}/LATEST_BUILD.txt`;
try {
const txt = await fetchText(url);
return txt; // 成功获取后立即返回
} catch (e) {
console.warn(
`获取 ${src.name} / ${bucketObj.name} 的 LATEST_BUILD 失败`,
e
);
continue; // 当前桶失败,尝试下一个桶
}
}
}
console.error("所有源均无法获取 LATEST_BUILD");
return null; // 所有源都失败时返回 null
}
async function fetchBuildFiles(src, bucketObj, latestBuild) {
// 列出 weekly/DATE_ATTEMPT/ 目录下的文件
const url = `${src.url}/${
bucketObj.bucket
}/?list-type=2&prefix=${latestBuild.replace(/^\//, "")}`;
const resp = await fetch(url);
const xml = await resp.text();
const parser = new DOMParser();
const xmldoc = parser.parseFromString(xml, "application/xml");
const contents = Array.from(xmldoc.querySelectorAll("Contents"));
return contents
.map((item) => item.querySelector("Key").textContent)
.filter(
(key) =>
key.startsWith("weekly/") &&
!key.endsWith("/") &&
key.endsWith(".img")
);
}
async function main() {
let latestBuild = await fetchLatestBuild();
latestBuildSpan.textContent = latestBuild || "未找到最新构建";
let buildFilesMap = {};
try {
for (const src of SOURCES) {
for (const bucketObj of src.buckets) {
const files = await fetchBuildFiles(src, bucketObj, latestBuild);
if (files.length > 0) {
files.forEach((file) => {
const fileName = file.split("/").pop();
if (!buildFilesMap[fileName]) buildFilesMap[fileName] = [];
buildFilesMap[fileName].push({
url: `${src.url}/${bucketObj.bucket}/${file}`,
src: src.name,
bucket: bucketObj.bucket,
});
});
}
}
}
} catch (e) {
alert(`获取文件列表失败: ${e.message}`);
}
// 渲染每个 .img 文件为一个 build box
buildListDiv.innerHTML = "";
Object.keys(buildFilesMap).forEach((fileName) => {
buildListDiv.appendChild(
renderBuildBox(fileName, buildFilesMap[fileName])
);
});
}
function renderBuildBox(fileName, filesList) {
const buildBox = document.createElement("div");
buildBox.className = "build-box";
let downloadLinks = filesList
.map(
(f) =>
`<a href="${f.url}" target="_blank">(${f.src})/${f.bucket}/${fileName}</a>`
)
.join("<br>");
buildBox.innerHTML = `
<div class="build-row">
<div class="build-meta">
镜像文件: ${fileName}
</div>
<div>
<div class="downloads-title">下载链接</div>
<div class="downloads-list">${downloadLinks}</div>
</div>
</div>
`;
return buildBox;
}
main();
</script>
</body>
</html>