From 4197eaec1303d88b38e751d5269fa37c312e2f04 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Thu, 7 Apr 2022 10:42:05 +0800 Subject: [PATCH 1/4] no_record md5 --- models/attachment.go | 1 + models/dataset.go | 9 ++++++++- templates/repo/datasets/index.tmpl | 10 +++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index a3fc6fa01..7c95a73dd 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -51,6 +51,7 @@ type Attachment struct { FileChunk *FileChunk `xorm:"-"` CanDel bool `xorm:"-"` Uploader *User `xorm:"-"` + Md5 string `xorm:"-"` } type AttachmentUsername struct { diff --git a/models/dataset.go b/models/dataset.go index 7cac6c468..c56a8fdc3 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -1,6 +1,7 @@ package models import ( + "code.gitea.io/gitea/modules/log" "errors" "fmt" "sort" @@ -296,7 +297,13 @@ func getDatasetAttachments(e Engine, typeCloudBrain int, isSigned bool, user *Us if err != nil { return err } - attachment.FileChunk = fileChunks[0] + if len(fileChunks) > 0 { + attachment.Md5 = fileChunks[0].Md5 + } else { + log.Error("has attachment record, but has no file_chunk record") + attachment.Md5 = "no_record" + } + attachment.CanDel = CanDelAttachment(isSigned, user, attachment) sortedRels.Rel[currentIndex].Attachments = append(sortedRels.Rel[currentIndex].Attachments, attachment) } diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index 065ada386..e8d9b65e3 100755 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -199,7 +199,7 @@ {{range $k, $v :=.Attachments}} -
+
@@ -266,8 +266,8 @@ {{$.i18n.Tr "preview"}} {{end}} {{if and (.CanDel) (not $.Repository.IsPrivate)}} - {{$.i18n.Tr "dataset.set_public"}} - {{$.i18n.Tr "dataset.set_private"}} + {{$.i18n.Tr "dataset.set_public"}} + {{$.i18n.Tr "dataset.set_private"}} {{end}}