diff --git a/modules/storage/obs.go b/modules/storage/obs.go index acf660e56..39312bfde 100755 --- a/modules/storage/obs.go +++ b/modules/storage/obs.go @@ -29,20 +29,20 @@ type FileInfo struct { } //check if has the object -//todo:修改查询方式 func ObsHasObject(path string) (bool, error) { hasObject := false - output, err := ObsCli.ListObjects(&obs.ListObjectsInput{Bucket: setting.Bucket}) - if err != nil { - log.Error("ListObjects failed:%v", err) - return hasObject, err - } - for _, obj := range output.Contents { - //obj.Key:attachment/0/1/019fd24e-4ef7-41cc-9f85-4a7b8504d958 - if path == obj.Key { - hasObject = true - break + input := &obs.GetObjectMetadataInput{} + input.Bucket = setting.Bucket + input.Key = path + _, err := ObsCli.GetObjectMetadata(input) + if err == nil { + hasObject = true + } else { + if obsError, ok := err.(obs.ObsError); ok { + log.Error("GetObjectMetadata failed(%d): %s", obsError.StatusCode, obsError.Message) + } else { + log.Error("%v", err.Error()) } } diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 2c082a289..8443d6488 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -360,6 +360,7 @@ func GetPresignedPutObjectURL(ctx *context.Context) { // AddAttachment response for add attachment record func AddAttachment(ctx *context.Context) { typeCloudBrain := ctx.QueryInt("type") + fileName := ctx.Query("file_name") err := checkTypeCloudBrain(typeCloudBrain) if err != nil { ctx.ServerError("checkTypeCloudBrain failed", err) @@ -375,7 +376,7 @@ func AddAttachment(ctx *context.Context) { return } } else { - has, err = storage.ObsHasObject(setting.BasePath + models.AttachmentRelativePath(uuid) + "/" + uuid) + has, err = storage.ObsHasObject(setting.BasePath + models.AttachmentRelativePath(uuid) + "/" + fileName) if err != nil { ctx.ServerError("ObsHasObject", err) return @@ -391,7 +392,7 @@ func AddAttachment(ctx *context.Context) { UUID: uuid, UploaderID: ctx.User.ID, IsPrivate: true, - Name: ctx.Query("file_name"), + Name: fileName, Size: ctx.QueryInt64("size"), DatasetID: ctx.QueryInt64("dataset_id"), Type: typeCloudBrain, @@ -479,6 +480,7 @@ func UpdateAttachmentDecompressState(ctx *context.Context) { func GetSuccessChunks(ctx *context.Context) { fileMD5 := ctx.Query("md5") typeCloudBrain := ctx.QueryInt("type") + fileName := ctx.Query("file_name") var chunks string err := checkTypeCloudBrain(typeCloudBrain) @@ -510,7 +512,7 @@ func GetSuccessChunks(ctx *context.Context) { return } } else { - isExist, err = storage.ObsHasObject(setting.BasePath + models.AttachmentRelativePath(fileChunk.UUID) + "/" + fileChunk.UUID) + isExist, err = storage.ObsHasObject(setting.BasePath + models.AttachmentRelativePath(fileChunk.UUID) + "/" + fileName) if err != nil { ctx.ServerError("ObsHasObject failed", err) return diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index a621289ae..5c701eadb 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -50,6 +50,11 @@ func QueryUserStaticDataPage(ctx *context.Context) { endTime = time.Now() } else { startTime, _ = time.Parse("2006-01-02", startDate) + settingStartTime, _ := time.Parse("2006-01-02", setting.RadarMap.RecordBeginTime) + if startTime.Unix() < settingStartTime.Unix() { + startTime = settingStartTime + startDate = settingStartTime.Format("2006-01-02") + } endTime, _ = time.Parse("2006-01-02", endDate) endTime = endTime.AddDate(0, 0, 1) isAll = false @@ -131,6 +136,13 @@ func QueryUserStaticDataPage(ctx *context.Context) { //设置默认打开的表单 xlsx.SetActiveSheet(index) var filename string + + nowTime := time.Now() + nowZeroTime := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, nowTime.Location()) + if endTime.Unix() >= nowZeroTime.Unix() { + endDate = nowZeroTime.AddDate(0, 0, -1).Format("2006-01-02") + } + if isAll { filename = sheetName + "_" + ctx.Tr("user.static.all") + ".xlsx" } else { diff --git a/web_src/js/components/ObsUploader.vue b/web_src/js/components/ObsUploader.vue index 381cb7f95..b0796fe81 100755 --- a/web_src/js/components/ObsUploader.vue +++ b/web_src/js/components/ObsUploader.vue @@ -262,6 +262,7 @@ export default { params: { md5: file.uniqueIdentifier, type: CloudBrainType, + file_name: file.name, _csrf: csrf } };