添加endpoint,测试s3
This commit is contained in:
parent
9bf07d3127
commit
f22753aed6
17
config.yaml
17
config.yaml
@ -3,15 +3,22 @@ api:
|
|||||||
baseUrl: "http://127.0.0.1:8030/vpt/v1/scenic/3946669713328836608"
|
baseUrl: "http://127.0.0.1:8030/vpt/v1/scenic/3946669713328836608"
|
||||||
record:
|
record:
|
||||||
storage:
|
storage:
|
||||||
type: "local"
|
|
||||||
path: "/root/opt/"
|
path: "/root/opt/"
|
||||||
|
type: "s3"
|
||||||
|
s3:
|
||||||
|
region: us-east-1
|
||||||
|
endpoint: http://192.168.55.101:9000
|
||||||
|
bucket: opt
|
||||||
|
prefix:
|
||||||
|
akId: 5vzfDiMztKO6VLvygoeX
|
||||||
|
akSec: Ot77u2kdVTm8zfQgExFrsm7xlGecxsiR6jk1idXM
|
||||||
duration: 60
|
duration: 60
|
||||||
devices:
|
devices:
|
||||||
- deviceNo: "34020000001322200001"
|
- deviceNo: "34020000001322200001"
|
||||||
name: "192.168.55.201"
|
name: "192.168.55.201"
|
||||||
path: "/root/opt/34020000001322200001/"
|
path: "/root/opt/34020000001322200001/"
|
||||||
fileName:
|
fileName:
|
||||||
timeSplit: "-"
|
timeSplit: "_"
|
||||||
dateSeparator: "-"
|
dateSeparator: ""
|
||||||
fileExt: "dav"
|
fileExt: "ts"
|
||||||
unFinExt: "dav_"
|
unFinExt: "ts"
|
@ -16,11 +16,12 @@ type StorageConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type S3Config struct {
|
type S3Config struct {
|
||||||
Region string `mapstructure:"region"`
|
Region string `mapstructure:"region"`
|
||||||
Bucket string `mapstructure:"bucket"`
|
Endpoint string `mapstructure:"endpoint"`
|
||||||
Prefix string `mapstructure:"prefix"`
|
Bucket string `mapstructure:"bucket"`
|
||||||
AkId string `mapstructure:"akId"`
|
Prefix string `mapstructure:"prefix"`
|
||||||
AkSec string `mapstructure:"akSec"`
|
AkId string `mapstructure:"akId"`
|
||||||
|
AkSec string `mapstructure:"akSec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeviceMapping struct {
|
type DeviceMapping struct {
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
awsConfig "github.com/aws/aws-sdk-go-v2/config"
|
|
||||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,10 +22,20 @@ type S3Adapter struct {
|
|||||||
|
|
||||||
func (s *S3Adapter) getClient() (*s3.Client, error) {
|
func (s *S3Adapter) getClient() (*s3.Client, error) {
|
||||||
if s.s3Client == nil {
|
if s.s3Client == nil {
|
||||||
|
const defaultRegion = "us-east-1"
|
||||||
|
resolver := aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
|
||||||
|
return aws.Endpoint{
|
||||||
|
PartitionID: "aws",
|
||||||
|
URL: s.StorageConfig.S3.Endpoint, // or where ever you ran minio
|
||||||
|
SigningRegion: defaultRegion,
|
||||||
|
HostnameImmutable: true,
|
||||||
|
}, nil
|
||||||
|
})
|
||||||
creds := credentials.NewStaticCredentialsProvider(s.StorageConfig.S3.AkId, s.StorageConfig.S3.AkSec, "")
|
creds := credentials.NewStaticCredentialsProvider(s.StorageConfig.S3.AkId, s.StorageConfig.S3.AkSec, "")
|
||||||
cfg, err := awsConfig.LoadDefaultConfig(context.TODO(), awsConfig.WithCredentialsProvider(creds))
|
cfg := aws.Config{
|
||||||
if err != nil {
|
Credentials: creds,
|
||||||
return nil, err
|
Region: defaultRegion,
|
||||||
|
EndpointResolver: resolver,
|
||||||
}
|
}
|
||||||
s.s3Client = s3.NewFromConfig(cfg)
|
s.s3Client = s3.NewFromConfig(cfg)
|
||||||
}
|
}
|
||||||
@ -43,7 +52,11 @@ func (s *S3Adapter) GetFileList(dirPath string, relDt time.Time) ([]dto.File, er
|
|||||||
Prefix: aws.String(path.Join(s.StorageConfig.S3.Prefix, dirPath)),
|
Prefix: aws.String(path.Join(s.StorageConfig.S3.Prefix, dirPath)),
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := s.s3Client.ListObjectsV2(context.TODO(), listObjectsInput)
|
client, err := s.getClient()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result, err := client.ListObjectsV2(context.TODO(), listObjectsInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -51,23 +64,24 @@ func (s *S3Adapter) GetFileList(dirPath string, relDt time.Time) ([]dto.File, er
|
|||||||
var fileList []dto.File
|
var fileList []dto.File
|
||||||
for _, object := range result.Contents {
|
for _, object := range result.Contents {
|
||||||
key := *object.Key
|
key := *object.Key
|
||||||
if util.IsVideoFile(path.Base(key)) {
|
if !util.IsVideoFile(path.Base(key)) {
|
||||||
startTime, stopTime, err := util.ParseStartStopTime(path.Base(key), relDt)
|
continue
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if startTime.Equal(stopTime) || stopTime.IsZero() {
|
|
||||||
stopTime = stopTime.Add(time.Second * time.Duration(config.Config.Record.Duration))
|
|
||||||
}
|
|
||||||
fileList = append(fileList, dto.File{
|
|
||||||
BasePath: s.StorageConfig.S3.Bucket,
|
|
||||||
Name: path.Base(key),
|
|
||||||
Path: path.Dir(key),
|
|
||||||
Url: key,
|
|
||||||
StartTime: startTime,
|
|
||||||
EndTime: stopTime,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
startTime, stopTime, err := util.ParseStartStopTime(path.Base(key), relDt)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if startTime.Equal(stopTime) || stopTime.IsZero() {
|
||||||
|
stopTime = stopTime.Add(time.Second * time.Duration(config.Config.Record.Duration))
|
||||||
|
}
|
||||||
|
fileList = append(fileList, dto.File{
|
||||||
|
BasePath: s.StorageConfig.S3.Bucket,
|
||||||
|
Name: path.Base(key),
|
||||||
|
Path: path.Dir(key),
|
||||||
|
Url: key,
|
||||||
|
StartTime: startTime,
|
||||||
|
EndTime: stopTime,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
sort.Slice(fileList, func(i, j int) bool {
|
sort.Slice(fileList, func(i, j int) bool {
|
||||||
return fileList[i].StartTime.Before(fileList[j].StartTime)
|
return fileList[i].StartTime.Before(fileList[j].StartTime)
|
||||||
|
@ -6,5 +6,5 @@ func IsVideoFile(name string) bool {
|
|||||||
if name == "" {
|
if name == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return name[len(name)-len(config.Config.FileName.FileExt):] == config.Config.FileName.FileExt || name[len(name)-len(config.Config.FileName.UnfinishedFileExt):] == config.Config.FileName.UnfinishedFileExt
|
return (name[len(name)-len(config.Config.FileName.FileExt):] == config.Config.FileName.FileExt) || (name[len(name)-len(config.Config.FileName.UnfinishedFileExt):] == config.Config.FileName.UnfinishedFileExt)
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,16 @@ import (
|
|||||||
|
|
||||||
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)
|
split := strings.Split(filePath, config.Config.FileName.TimeSplit)
|
||||||
if len(split) != 2 {
|
if len(split) == 0 {
|
||||||
return time.Time{}, time.Time{}, fmt.Errorf("无法解析时间范围")
|
return time.Time{}, time.Time{}, fmt.Errorf("无法解析时间范围")
|
||||||
}
|
}
|
||||||
startTime, err := ParseTime(split[0], relativeDate)
|
startTime, err := ParseTime(split[0], relativeDate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return time.Time{}, time.Time{}, err
|
return time.Time{}, time.Time{}, err
|
||||||
}
|
}
|
||||||
|
if len(split) == 1 {
|
||||||
|
return startTime, startTime, nil
|
||||||
|
}
|
||||||
stopTime, err := ParseTime(split[1], relativeDate)
|
stopTime, err := ParseTime(split[1], relativeDate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return startTime, startTime, nil
|
return startTime, startTime, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user