From 087def801502a59eef6f0d3599e5647fbe7bcb99 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Fri, 28 Feb 2025 12:55:38 +0800 Subject: [PATCH] =?UTF-8?q?s3=E5=9C=B0=E5=9D=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fs/s3_adapter.go | 14 +++++++++++++- util/parse_time.go | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fs/s3_adapter.go b/fs/s3_adapter.go index 5f59937..286fe10 100644 --- a/fs/s3_adapter.go +++ b/fs/s3_adapter.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "github.com/aws/aws-sdk-go-v2/credentials" + "log" "path" "sort" "time" @@ -74,11 +75,22 @@ func (s *S3Adapter) GetFileList(dirPath string, relDt time.Time) ([]dto.File, er if startTime.Equal(stopTime) || stopTime.IsZero() { stopTime = stopTime.Add(time.Second * time.Duration(config.Config.Record.Duration)) } + presignClient := s3.NewPresignClient(client) + request, err := presignClient.PresignGetObject(context.TODO(), &s3.GetObjectInput{ + Bucket: aws.String(s.StorageConfig.S3.Bucket), + Key: aws.String(key), + }, func(presignOptions *s3.PresignOptions) { + presignOptions.Expires = 10 * time.Minute + }) + if err != nil { + log.Println("Error presigning GetObject request:", err) + continue + } fileList = append(fileList, dto.File{ BasePath: s.StorageConfig.S3.Bucket, Name: path.Base(key), Path: path.Dir(key), - Url: key, + Url: request.URL, StartTime: startTime, EndTime: stopTime, }) diff --git a/util/parse_time.go b/util/parse_time.go index 678f713..c8efc85 100644 --- a/util/parse_time.go +++ b/util/parse_time.go @@ -3,13 +3,15 @@ package util import ( "ZhenTuLocalPassiveAdapter/config" "fmt" + "path" "regexp" "strings" "time" ) func ParseStartStopTime(filePath string, relativeDate time.Time) (time.Time, time.Time, error) { - split := strings.Split(filePath, config.Config.FileName.TimeSplit) + _, file := path.Split(filePath) + split := strings.Split(file, config.Config.FileName.TimeSplit) if len(split) == 0 { return time.Time{}, time.Time{}, fmt.Errorf("无法解析时间范围") }