s3地址问题

This commit is contained in:
Jerry Yan 2025-02-28 12:55:38 +08:00
parent a1890c7562
commit 087def8015
2 changed files with 16 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/credentials"
"log"
"path" "path"
"sort" "sort"
"time" "time"
@ -74,11 +75,22 @@ func (s *S3Adapter) GetFileList(dirPath string, relDt time.Time) ([]dto.File, er
if startTime.Equal(stopTime) || stopTime.IsZero() { if startTime.Equal(stopTime) || stopTime.IsZero() {
stopTime = stopTime.Add(time.Second * time.Duration(config.Config.Record.Duration)) 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{ fileList = append(fileList, dto.File{
BasePath: s.StorageConfig.S3.Bucket, BasePath: s.StorageConfig.S3.Bucket,
Name: path.Base(key), Name: path.Base(key),
Path: path.Dir(key), Path: path.Dir(key),
Url: key, Url: request.URL,
StartTime: startTime, StartTime: startTime,
EndTime: stopTime, EndTime: stopTime,
}) })

View File

@ -3,13 +3,15 @@ package util
import ( import (
"ZhenTuLocalPassiveAdapter/config" "ZhenTuLocalPassiveAdapter/config"
"fmt" "fmt"
"path"
"regexp" "regexp"
"strings" "strings"
"time" "time"
) )
func ParseStartStopTime(filePath string, relativeDate time.Time) (time.Time, time.Time, error) { 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 { if len(split) == 0 {
return time.Time{}, time.Time{}, fmt.Errorf("无法解析时间范围") return time.Time{}, time.Time{}, fmt.Errorf("无法解析时间范围")
} }