| 123456789101112131415161718192021222324252627282930313233343536373839 |
- package minio
- import (
- "bytes"
- "context"
- "fmt"
- "io"
- "path"
- "strings"
- minioUtil "fwh-toolbox-server/utils/minio"
- )
- const faultRecordPrefix = "fault-record/"
- // FaultRecordObjectKey fault-record/<env>/<gatewaySn>/<fileName>
- func FaultRecordObjectKey(env, gatewaySn, fileName string) (string, error) {
- for _, s := range []string{env, gatewaySn, fileName} {
- if s == "" || strings.ContainsAny(s, "/\\") || s == "." || s == ".." {
- return "", fmt.Errorf("invalid object key segment %q", s)
- }
- }
- return faultRecordPrefix + path.Join(env, gatewaySn, fileName), nil
- }
- // PutFaultRecordFile 保存下载到的原始录波压缩包
- func PutFaultRecordFile(ctx context.Context, key string, data []byte) error {
- return minioUtil.UploadFromReader(bytes.NewReader(data), int64(len(data)), key, "application/octet-stream")
- }
- // ReadFaultRecordFile 读取原始录波压缩包
- func ReadFaultRecordFile(ctx context.Context, key string) ([]byte, error) {
- obj, err := minioUtil.GetObject(key)
- if err != nil {
- return nil, err
- }
- defer obj.Close()
- return io.ReadAll(obj)
- }
|