修复架构特殊符号的问题
This commit is contained in:
@@ -342,14 +342,6 @@
|
||||
</div>
|
||||
|
||||
<div id="toast" style="display:none;"></div>
|
||||
|
||||
<footer>
|
||||
<a href="https://github.com/sky22333/hub-proxy" target="_blank" class="github-link">
|
||||
<svg height="32" viewBox="0 0 16 16" width="32">
|
||||
<path fill="currentColor" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path>
|
||||
</svg>
|
||||
</a>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bufio"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
@@ -326,8 +327,20 @@ func downloadImage(task *DownloadTask, index int, imgTask *ImageTask, platform s
|
||||
if strings.Contains(platform, "--") {
|
||||
platformArg = platform
|
||||
} else {
|
||||
// 仅指定架构名称的情况
|
||||
platformArg = fmt.Sprintf("--override-os linux --override-arch %s", platform)
|
||||
// 处理特殊架构格式,如 arm/v7
|
||||
if strings.Contains(platform, "/") {
|
||||
parts := strings.Split(platform, "/")
|
||||
if len(parts) == 2 {
|
||||
// 适用于arm/v7这样的格式
|
||||
platformArg = fmt.Sprintf("--override-os linux --override-arch %s --override-variant %s", parts[0], parts[1])
|
||||
} else {
|
||||
// 对于其他带/的格式,直接按原格式处理
|
||||
platformArg = fmt.Sprintf("--override-os linux --override-arch %s", platform)
|
||||
}
|
||||
} else {
|
||||
// 仅指定架构名称的情况
|
||||
platformArg = fmt.Sprintf("--override-os linux --override-arch %s", platform)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,6 +348,8 @@ func downloadImage(task *DownloadTask, index int, imgTask *ImageTask, platform s
|
||||
cmd := fmt.Sprintf("skopeo copy %s docker://%s docker-archive:%s",
|
||||
platformArg, imgTask.Image, outputPath)
|
||||
|
||||
fmt.Printf("执行命令: %s\n", cmd)
|
||||
|
||||
// 执行命令
|
||||
command := exec.Command("sh", "-c", cmd)
|
||||
|
||||
@@ -347,6 +362,14 @@ func downloadImage(task *DownloadTask, index int, imgTask *ImageTask, platform s
|
||||
return
|
||||
}
|
||||
|
||||
stdout, err := command.StdoutPipe()
|
||||
if err != nil {
|
||||
imgTask.Status = string(StatusFailed)
|
||||
imgTask.Error = fmt.Sprintf("无法创建标准输出管道: %v", err)
|
||||
sendImageUpdate(task, index)
|
||||
return
|
||||
}
|
||||
|
||||
if err := command.Start(); err != nil {
|
||||
imgTask.Status = string(StatusFailed)
|
||||
imgTask.Error = fmt.Sprintf("启动命令失败: %v", err)
|
||||
@@ -354,42 +377,89 @@ func downloadImage(task *DownloadTask, index int, imgTask *ImageTask, platform s
|
||||
return
|
||||
}
|
||||
|
||||
// 模拟逐步进度增加,确保用户体验更好
|
||||
go func() {
|
||||
// 每500ms检查一次进度,如果进度没有变化,则稍微增加一点
|
||||
ticker := time.NewTicker(500 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
lastProgress := 0.0
|
||||
stagnantCount := 0
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
// 检查命令是否还在运行
|
||||
if command.ProcessState != nil && command.ProcessState.Exited() {
|
||||
return
|
||||
}
|
||||
|
||||
// 如果进度停滞,小幅增加进度,提高用户体验
|
||||
task.Lock.Lock()
|
||||
currentProgress := imgTask.Progress
|
||||
if currentProgress == lastProgress {
|
||||
stagnantCount++
|
||||
if stagnantCount > 5 && currentProgress < 90 { // 连续5次无变化且未接近完成
|
||||
// 缓慢增加进度,但不超过95%
|
||||
newProgress := currentProgress + 0.5
|
||||
if newProgress > 95 {
|
||||
newProgress = 95
|
||||
}
|
||||
imgTask.Progress = newProgress
|
||||
updateTaskProgress(task)
|
||||
sendImageUpdate(task, index)
|
||||
}
|
||||
} else {
|
||||
stagnantCount = 0
|
||||
lastProgress = currentProgress
|
||||
}
|
||||
task.Lock.Unlock()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// 读取stderr以获取进度信息
|
||||
go func() {
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
n, err := stderr.Read(buf)
|
||||
if n > 0 {
|
||||
output := string(buf[:n])
|
||||
// 解析进度信息 (这里简化处理,假设skopeo输出进度信息)
|
||||
// 实际需要根据skopeo的真实输出格式进行解析
|
||||
if strings.Contains(output, "%") {
|
||||
// 简单解析,实际使用时可能需要更复杂的解析逻辑
|
||||
parts := strings.Split(output, "%")
|
||||
if len(parts) > 0 {
|
||||
numStr := strings.TrimSpace(parts[0])
|
||||
numStr = strings.TrimLeft(numStr, "Copying blob ")
|
||||
numStr = strings.TrimLeft(numStr, "Copying config ")
|
||||
numStr = strings.TrimRight(numStr, " / ")
|
||||
numStr = strings.TrimSpace(numStr)
|
||||
// 尝试提取最后一个数字作为进度
|
||||
fields := strings.Fields(numStr)
|
||||
if len(fields) > 0 {
|
||||
lastField := fields[len(fields)-1]
|
||||
progress := 0.0
|
||||
fmt.Sscanf(lastField, "%f", &progress)
|
||||
if progress > 0 && progress <= 100 {
|
||||
imgTask.Progress = progress
|
||||
updateTaskProgress(task)
|
||||
sendImageUpdate(task, index)
|
||||
}
|
||||
scanner := bufio.NewScanner(stderr)
|
||||
for scanner.Scan() {
|
||||
output := scanner.Text()
|
||||
fmt.Printf("镜像 %s 进度输出: %s\n", imgTask.Image, output)
|
||||
|
||||
// 解析进度信息
|
||||
if strings.Contains(output, "%") {
|
||||
parts := strings.Split(output, "%")
|
||||
if len(parts) > 0 {
|
||||
numStr := strings.TrimSpace(parts[0])
|
||||
numStr = strings.TrimLeft(numStr, "Copying blob ")
|
||||
numStr = strings.TrimLeft(numStr, "Copying config ")
|
||||
numStr = strings.TrimRight(numStr, " / ")
|
||||
numStr = strings.TrimSpace(numStr)
|
||||
|
||||
// 尝试提取最后一个数字作为进度
|
||||
fields := strings.Fields(numStr)
|
||||
if len(fields) > 0 {
|
||||
lastField := fields[len(fields)-1]
|
||||
progress := 0.0
|
||||
fmt.Sscanf(lastField, "%f", &progress)
|
||||
if progress > 0 && progress <= 100 {
|
||||
task.Lock.Lock()
|
||||
imgTask.Progress = progress
|
||||
task.Lock.Unlock()
|
||||
updateTaskProgress(task)
|
||||
sendImageUpdate(task, index)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// 读取stdout
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(stdout)
|
||||
for scanner.Scan() {
|
||||
output := scanner.Text()
|
||||
fmt.Printf("镜像 %s 标准输出: %s\n", imgTask.Image, output)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -409,8 +479,10 @@ func downloadImage(task *DownloadTask, index int, imgTask *ImageTask, platform s
|
||||
}
|
||||
|
||||
// 更新状态为已完成
|
||||
task.Lock.Lock()
|
||||
imgTask.Status = string(StatusCompleted)
|
||||
imgTask.Progress = 100
|
||||
task.Lock.Unlock()
|
||||
updateTaskProgress(task)
|
||||
sendImageUpdate(task, index)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user