From ec732ff5dc4f0487a7362315cb3d2a7891ecef4c Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Thu, 18 Nov 2021 14:28:16 +0800 Subject: [PATCH 1/3] fix 872 --- modules/storage/obs.go | 22 +++++++++++----------- routers/repo/attachment.go | 8 +++++--- web_src/js/components/ObsUploader.vue | 1 + 3 files changed, 17 insertions(+), 14 deletions(-) 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/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 } }; From 192e7575629f646574bc9c8bc8bba3078d0828eb Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 18 Nov 2021 15:12:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E5=BD=93=E7=94=A8=E6=88=B7=E9=80=89=E6=8B=A9=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=B0=8F=E4=BA=8E2021-11-05=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E4=BF=AE=E6=AD=A3=E5=88=B02021-11-05?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/user_data_analysis.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index a621289ae..dde11350e 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -50,6 +50,10 @@ 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 + } endTime, _ = time.Parse("2006-01-02", endDate) endTime = endTime.AddDate(0, 0, 1) isAll = false From 93943231d07ef420032c08897514f0f260963a0b Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 18 Nov 2021 15:55:12 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E7=BB=93=E6=9D=9F=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/user_data_analysis.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index dde11350e..5c701eadb 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -53,6 +53,7 @@ func QueryUserStaticDataPage(ctx *context.Context) { 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) @@ -135,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 {