Browse Source

Merge branch 'V20211115' into wangjr_pro

tags/v1.21.12.1
Gitea 4 years ago
parent
commit
deafe7b205
4 changed files with 29 additions and 14 deletions
  1. +11
    -11
      modules/storage/obs.go
  2. +5
    -3
      routers/repo/attachment.go
  3. +12
    -0
      routers/repo/user_data_analysis.go
  4. +1
    -0
      web_src/js/components/ObsUploader.vue

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

@@ -29,20 +29,20 @@ type FileInfo struct {
} }


//check if has the object //check if has the object
//todo:修改查询方式
func ObsHasObject(path string) (bool, error) { func ObsHasObject(path string) (bool, error) {
hasObject := false 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())
} }
} }




+ 5
- 3
routers/repo/attachment.go View File

@@ -360,6 +360,7 @@ func GetPresignedPutObjectURL(ctx *context.Context) {
// AddAttachment response for add attachment record // AddAttachment response for add attachment record
func AddAttachment(ctx *context.Context) { func AddAttachment(ctx *context.Context) {
typeCloudBrain := ctx.QueryInt("type") typeCloudBrain := ctx.QueryInt("type")
fileName := ctx.Query("file_name")
err := checkTypeCloudBrain(typeCloudBrain) err := checkTypeCloudBrain(typeCloudBrain)
if err != nil { if err != nil {
ctx.ServerError("checkTypeCloudBrain failed", err) ctx.ServerError("checkTypeCloudBrain failed", err)
@@ -375,7 +376,7 @@ func AddAttachment(ctx *context.Context) {
return return
} }
} else { } else {
has, err = storage.ObsHasObject(setting.BasePath + models.AttachmentRelativePath(uuid) + "/" + uuid)
has, err = storage.ObsHasObject(setting.BasePath + models.AttachmentRelativePath(uuid) + "/" + fileName)
if err != nil { if err != nil {
ctx.ServerError("ObsHasObject", err) ctx.ServerError("ObsHasObject", err)
return return
@@ -391,7 +392,7 @@ func AddAttachment(ctx *context.Context) {
UUID: uuid, UUID: uuid,
UploaderID: ctx.User.ID, UploaderID: ctx.User.ID,
IsPrivate: true, IsPrivate: true,
Name: ctx.Query("file_name"),
Name: fileName,
Size: ctx.QueryInt64("size"), Size: ctx.QueryInt64("size"),
DatasetID: ctx.QueryInt64("dataset_id"), DatasetID: ctx.QueryInt64("dataset_id"),
Type: typeCloudBrain, Type: typeCloudBrain,
@@ -479,6 +480,7 @@ func UpdateAttachmentDecompressState(ctx *context.Context) {
func GetSuccessChunks(ctx *context.Context) { func GetSuccessChunks(ctx *context.Context) {
fileMD5 := ctx.Query("md5") fileMD5 := ctx.Query("md5")
typeCloudBrain := ctx.QueryInt("type") typeCloudBrain := ctx.QueryInt("type")
fileName := ctx.Query("file_name")
var chunks string var chunks string


err := checkTypeCloudBrain(typeCloudBrain) err := checkTypeCloudBrain(typeCloudBrain)
@@ -510,7 +512,7 @@ func GetSuccessChunks(ctx *context.Context) {
return return
} }
} else { } 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 { if err != nil {
ctx.ServerError("ObsHasObject failed", err) ctx.ServerError("ObsHasObject failed", err)
return return


+ 12
- 0
routers/repo/user_data_analysis.go View File

@@ -50,6 +50,11 @@ func QueryUserStaticDataPage(ctx *context.Context) {
endTime = time.Now() endTime = time.Now()
} else { } else {
startTime, _ = time.Parse("2006-01-02", startDate) 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, _ = time.Parse("2006-01-02", endDate)
endTime = endTime.AddDate(0, 0, 1) endTime = endTime.AddDate(0, 0, 1)
isAll = false isAll = false
@@ -131,6 +136,13 @@ func QueryUserStaticDataPage(ctx *context.Context) {
//设置默认打开的表单 //设置默认打开的表单
xlsx.SetActiveSheet(index) xlsx.SetActiveSheet(index)
var filename string 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 { if isAll {
filename = sheetName + "_" + ctx.Tr("user.static.all") + ".xlsx" filename = sheetName + "_" + ctx.Tr("user.static.all") + ".xlsx"
} else { } else {


+ 1
- 0
web_src/js/components/ObsUploader.vue View File

@@ -262,6 +262,7 @@ export default {
params: { params: {
md5: file.uniqueIdentifier, md5: file.uniqueIdentifier,
type: CloudBrainType, type: CloudBrainType,
file_name: file.name,
_csrf: csrf _csrf: csrf
} }
}; };


Loading…
Cancel
Save