From 2f8aa1d7ee529fe4d24b6f6d926460eab244d1ee Mon Sep 17 00:00:00 2001 From: flippancy <757410523@qq.com> Date: Sun, 16 Nov 2025 23:57:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8D=E5=90=8C=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=9B=BE=E7=89=87=E6=8F=90=E4=BA=A4=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=E6=8E=92=E5=BA=8F=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#294)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复不同类型图片提交的情况下排序的问题 * fix:去掉索引,按顺序检查图片下载然后加入新的数组 --- pkg/downloader/processor.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/pkg/downloader/processor.go b/pkg/downloader/processor.go index e7a8603..b2fcda8 100644 --- a/pkg/downloader/processor.go +++ b/pkg/downloader/processor.go @@ -22,29 +22,25 @@ func NewImageProcessor() *ImageProcessor { // 支持两种输入格式: // 1. URL格式 (http/https开头) - 自动下载到本地 // 2. 本地文件路径 - 直接使用 +// 保持原始图片顺序,如果下载失败直接返回错误 func (p *ImageProcessor) ProcessImages(images []string) ([]string, error) { - var localPaths []string - var urlsToDownload []string + localPaths := make([]string, 0, len(images)) - // 分离URL和本地路径 + // 按顺序处理每张图片 for _, image := range images { if IsImageURL(image) { - urlsToDownload = append(urlsToDownload, image) + // URL图片:立即下载,失败直接返回错误 + localPath, err := p.downloader.DownloadImage(image) + if err != nil { + return nil, fmt.Errorf("下载图片失败 %s: %w", image, err) + } + localPaths = append(localPaths, localPath) } else { - // 本地路径直接添加 + // 本地路径直接使用 localPaths = append(localPaths, image) } } - // 批量下载URL图片 - if len(urlsToDownload) > 0 { - downloadedPaths, err := p.downloader.DownloadImages(urlsToDownload) - if err != nil { - return nil, fmt.Errorf("failed to download images: %w", err) - } - localPaths = append(localPaths, downloadedPaths...) - } - if len(localPaths) == 0 { return nil, fmt.Errorf("no valid images found") }