导出系统
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m50s

This commit is contained in:
Break
2026-06-15 15:28:29 +08:00
parent 2f0b24ce88
commit 7ec84fbc0f
17 changed files with 939 additions and 260 deletions

View File

@@ -73,7 +73,7 @@ func (p *S3Provider) Upload(ctx context.Context, key string, reader io.Reader, c
return nil
}
func (p *S3Provider) Download(ctx context.Context, key string, writer io.Writer) error {
func (p *S3Provider) Download(ctx context.Context, key string) (io.ReadCloser, error) {
input := &s3.GetObjectInput{
Bucket: aws.String(p.bucket),
Key: aws.String(key),
@@ -82,17 +82,11 @@ func (p *S3Provider) Download(ctx context.Context, key string, writer io.Writer)
result, err := p.client.GetObjectWithContext(ctx, input)
if err != nil {
if strings.Contains(err.Error(), "NoSuchKey") {
return fmt.Errorf("文件不存在: %s", key)
return nil, fmt.Errorf("文件不存在: %s", key)
}
return fmt.Errorf("下载文件失败: %w", err)
return nil, fmt.Errorf("下载文件失败: %w", err)
}
defer result.Body.Close()
_, err = io.Copy(writer, result.Body)
if err != nil {
return fmt.Errorf("写入文件内容失败: %w", err)
}
return nil
return result.Body, nil
}
func (p *S3Provider) DownloadToTemp(ctx context.Context, key string) (string, func(), error) {
@@ -111,11 +105,19 @@ func (p *S3Provider) DownloadToTemp(ctx context.Context, key string) (string, fu
_ = os.Remove(tempPath)
}
if err := p.Download(ctx, key, tempFile); err != nil {
reader, err := p.Download(ctx, key)
if err != nil {
tempFile.Close()
cleanup()
return "", nil, err
}
defer reader.Close()
if _, err := io.Copy(tempFile, reader); err != nil {
tempFile.Close()
cleanup()
return "", nil, fmt.Errorf("写入文件内容失败: %w", err)
}
if err := tempFile.Close(); err != nil {
cleanup()