From 9e5bc3c86a68807cc869a4f54073adc684cbd042 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Tue, 15 Feb 2022 10:16:48 +0800 Subject: [PATCH 01/24] s3 download link --- models/attachment.go | 13 +++++++++++++ modules/structs/attachment.go | 7 ++++--- templates/repo/datasets/dataset_list.tmpl | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) mode change 100644 => 100755 modules/structs/attachment.go diff --git a/models/attachment.go b/models/attachment.go index fd1df9e43..715cd0a90 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -88,6 +88,7 @@ func (a *Attachment) APIFormat() *api.Attachment { Size: a.Size, UUID: a.UUID, DownloadURL: a.DownloadURL(), + S3DownloadURL: a.S3DownloadURL(), } } @@ -96,6 +97,18 @@ func (a *Attachment) DownloadURL() string { return fmt.Sprintf("%sattachments/%s", setting.AppURL, a.UUID) } +// DownloadURL returns the download url of the attached file +func (a *Attachment) S3DownloadURL() string { + url := "" + if a.Type == TypeCloudBrainOne { + url, _ = storage.Attachments.PresignedGetURL(setting.Attachment.Minio.BasePath+AttachmentRelativePath(a.UUID), a.Name) + } else if a.Type == TypeCloudBrainTwo { + + } + + return url +} + // AttachmentRelativePath returns the relative path func AttachmentRelativePath(uuid string) string { return path.Join(uuid[0:1], uuid[1:2], uuid) diff --git a/modules/structs/attachment.go b/modules/structs/attachment.go old mode 100644 new mode 100755 index 7becd9433..0f3c2ed6a --- a/modules/structs/attachment.go +++ b/modules/structs/attachment.go @@ -16,9 +16,10 @@ type Attachment struct { Size int64 `json:"size"` DownloadCount int64 `json:"download_count"` // swagger:strfmt date-time - Created time.Time `json:"created_at"` - UUID string `json:"uuid"` - DownloadURL string `json:"browser_download_url"` + Created time.Time `json:"created_at"` + UUID string `json:"uuid"` + DownloadURL string `json:"browser_download_url"` + S3DownloadURL string } // EditAttachmentOptions options for editing attachments diff --git a/templates/repo/datasets/dataset_list.tmpl b/templates/repo/datasets/dataset_list.tmpl index e0c69c745..765adf391 100755 --- a/templates/repo/datasets/dataset_list.tmpl +++ b/templates/repo/datasets/dataset_list.tmpl @@ -14,7 +14,7 @@
* {{.page_only_dynamic}}
{{.page_dev_env_desc}}