Browse Source

Merge branch 'zouap_static' of git.openi.org.cn:OpenI/aiforge into zouap_static

pull/3226/head
chenshihai 2 years ago
parent
commit
fac42b68ab
3 changed files with 64 additions and 16 deletions
  1. +17
    -0
      modules/storage/minio_ext.go
  2. +3
    -3
      modules/storage/obs.go
  3. +44
    -13
      routers/repo/attachment.go

+ 17
- 0
modules/storage/minio_ext.go View File

@@ -267,6 +267,23 @@ func MinioCopyFiles(bucketName string, srcPath string, destPath string, Files []
return fileTotalSize, nil return fileTotalSize, nil
} }


func MinioCopyAFile(srcBucketName, srcObjectName, destBucketName, destObjectName string) (int64, error) {
_, core, err := getClients()
var fileTotalSize int64
fileTotalSize = 0
if err != nil {
log.Error("getClients failed:", err.Error())
return fileTotalSize, err
}
meta, err := core.StatObject(srcBucketName, srcObjectName, miniov6.StatObjectOptions{})
if err != nil {
log.Info("Get file error:" + err.Error())
}
core.CopyObject(srcBucketName, srcObjectName, destBucketName, destObjectName, meta.UserMetadata)
fileTotalSize = meta.Size
return fileTotalSize, nil
}

func MinioPathCopy(bucketName string, srcPath string, destPath string) (int64, error) { func MinioPathCopy(bucketName string, srcPath string, destPath string) (int64, error) {
_, core, err := getClients() _, core, err := getClients()
var fileTotalSize int64 var fileTotalSize int64


+ 3
- 3
modules/storage/obs.go View File

@@ -294,7 +294,7 @@ func ObsCopyManyFile(srcBucket string, srcPath string, destBucket string, destPa
log.Info("Get File error, error=" + err.Error()) log.Info("Get File error, error=" + err.Error())
continue continue
} }
obsCopyFile(srcBucket, srcKey, destBucket, destKey)
ObsCopyFile(srcBucket, srcKey, destBucket, destKey)
fileTotalSize += out.ContentLength fileTotalSize += out.ContentLength
} }


@@ -318,7 +318,7 @@ func ObsCopyAllFile(srcBucket string, srcPath string, destBucket string, destPat
index++ index++
for _, val := range output.Contents { for _, val := range output.Contents {
destKey := destPath + val.Key[length:] destKey := destPath + val.Key[length:]
obsCopyFile(srcBucket, val.Key, destBucket, destKey)
ObsCopyFile(srcBucket, val.Key, destBucket, destKey)
fileTotalSize += val.Size fileTotalSize += val.Size
} }
if output.IsTruncated { if output.IsTruncated {
@@ -337,7 +337,7 @@ func ObsCopyAllFile(srcBucket string, srcPath string, destBucket string, destPat
return fileTotalSize, nil return fileTotalSize, nil
} }


func obsCopyFile(srcBucket string, srcKeyName string, destBucket string, destKeyName string) error {
func ObsCopyFile(srcBucket string, srcKeyName string, destBucket string, destKeyName string) error {
input := &obs.CopyObjectInput{} input := &obs.CopyObjectInput{}
input.Bucket = destBucket input.Bucket = destBucket
input.Key = destKeyName input.Key = destKeyName


+ 44
- 13
routers/repo/attachment.go View File

@@ -551,6 +551,7 @@ func GetSuccessChunks(ctx *context.Context) {
typeCloudBrain := ctx.QueryInt("type") typeCloudBrain := ctx.QueryInt("type")
fileName := ctx.Query("file_name") fileName := ctx.Query("file_name")
scene := ctx.Query("scene") scene := ctx.Query("scene")
modeluuid := ctx.Query("modeluuid")
log.Info("scene=" + scene) log.Info("scene=" + scene)
var chunks string var chunks string


@@ -664,24 +665,50 @@ func GetSuccessChunks(ctx *context.Context) {
} }
if scene == Attachment_model { if scene == Attachment_model {
//使用description存储模型信息 //使用description存储模型信息
modeluuid := attach.Description
dbmodeluuid := attach.Description
modelname := "" modelname := ""
if modeluuid != "" {
model, err := models.QueryModelById(modeluuid)
if dbmodeluuid != modeluuid {
model, err := models.QueryModelById(dbmodeluuid)
if err == nil {
modelname = model.Name
}
//copy
srcObjectName := fileChunk.ObjectName
destObjectName := getObjectName(fileName, modeluuid)
if typeCloudBrain == models.TypeCloudBrainOne {
bucketName := setting.Attachment.Minio.Bucket
storage.MinioCopyAFile(bucketName, srcObjectName, bucketName, destObjectName)
} else {
bucketName := setting.Bucket
storage.ObsCopyFile(bucketName, srcObjectName, bucketName, destObjectName)
}
UpdateModelSize(modeluuid)
ctx.JSON(200, map[string]string{
"uuid": fileChunk.UUID,
"uploaded": strconv.Itoa(fileChunk.IsUploaded),
"uploadID": fileChunk.UploadID,
"chunks": string(chunks),
"attachID": strconv.Itoa(int(attachID)),
"fileName": attach.Name,
})
return
} else {
model, err := models.QueryModelById(dbmodeluuid)
if err == nil { if err == nil {
modelname = model.Name modelname = model.Name
} }
ctx.JSON(200, map[string]string{
"uuid": fileChunk.UUID,
"uploaded": strconv.Itoa(fileChunk.IsUploaded),
"uploadID": fileChunk.UploadID,
"chunks": string(chunks),
"attachID": strconv.Itoa(int(attachID)),
"modeluuid": dbmodeluuid,
"fileName": attach.Name,
"modelName": modelname,
})
return
} }
ctx.JSON(200, map[string]string{
"uuid": fileChunk.UUID,
"uploaded": strconv.Itoa(fileChunk.IsUploaded),
"uploadID": fileChunk.UploadID,
"chunks": string(chunks),
"attachID": strconv.Itoa(int(attachID)),
"modeluuid": modeluuid,
"fileName": attach.Name,
"modelName": modelname,
})
} else { } else {
dataset, err := models.GetDatasetByID(attach.DatasetID) dataset, err := models.GetDatasetByID(attach.DatasetID)
if err != nil { if err != nil {
@@ -702,6 +729,10 @@ func GetSuccessChunks(ctx *context.Context) {
} }
} }


func getObjectName(filename string, modeluuid string) string {
return strings.TrimPrefix(path.Join(Model_prefix, path.Join(modeluuid[0:1], modeluuid[1:2], modeluuid, filename)), "/")
}

func getMinioInitObjectName(scene string, uuid, modeluuid string, filename string) string { func getMinioInitObjectName(scene string, uuid, modeluuid string, filename string) string {
if scene == Attachment_model { if scene == Attachment_model {
return strings.TrimPrefix(path.Join(Model_prefix, path.Join(modeluuid[0:1], modeluuid[1:2], modeluuid, filename)), "/") return strings.TrimPrefix(path.Join(Model_prefix, path.Join(modeluuid[0:1], modeluuid[1:2], modeluuid, filename)), "/")


Loading…
Cancel
Save