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 1/4] 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 @@
{{svg "octicon-flame" 16}} {{(.DownloadCount | PrettyNumber)}} - + {{svg "octicon-file-binary" 16}}
{{if eq .DecompressState 1}} From 6b0a34ca6e261a06cf2681bae5460c331366a446 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Tue, 15 Feb 2022 11:08:01 +0800 Subject: [PATCH 2/4] obs download link --- models/attachment.go | 2 +- templates/repo/datasets/dataset_list.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index 715cd0a90..a6d4b3715 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -103,7 +103,7 @@ func (a *Attachment) S3DownloadURL() string { if a.Type == TypeCloudBrainOne { url, _ = storage.Attachments.PresignedGetURL(setting.Attachment.Minio.BasePath+AttachmentRelativePath(a.UUID), a.Name) } else if a.Type == TypeCloudBrainTwo { - + url, _ = storage.ObsGetPreSignedUrl(a.UUID, a.Name) } return url diff --git a/templates/repo/datasets/dataset_list.tmpl b/templates/repo/datasets/dataset_list.tmpl index 765adf391..eed89b709 100755 --- a/templates/repo/datasets/dataset_list.tmpl +++ b/templates/repo/datasets/dataset_list.tmpl @@ -14,7 +14,7 @@
{{svg "octicon-flame" 16}} {{(.DownloadCount | PrettyNumber)}} - + {{svg "octicon-file" 16}} {{svg "octicon-file-binary" 16}}
{{if eq .DecompressState 1}} From f7b4d218a811846254c8e0d44d00d8bd9672328e Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Thu, 17 Feb 2022 16:53:06 +0800 Subject: [PATCH 3/4] download link --- models/attachment.go | 2 +- templates/repo/datasets/dataset_list.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/attachment.go b/models/attachment.go index a6d4b3715..6ab1f3652 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -94,7 +94,7 @@ func (a *Attachment) APIFormat() *api.Attachment { // DownloadURL returns the download url of the attached file func (a *Attachment) DownloadURL() string { - return fmt.Sprintf("%sattachments/%s", setting.AppURL, a.UUID) + return fmt.Sprintf("%sattachments/%s?type=%d", setting.AppURL, a.UUID, a.Type) } // DownloadURL returns the download url of the attached file diff --git a/templates/repo/datasets/dataset_list.tmpl b/templates/repo/datasets/dataset_list.tmpl index eed89b709..7ea420fa0 100755 --- a/templates/repo/datasets/dataset_list.tmpl +++ b/templates/repo/datasets/dataset_list.tmpl @@ -14,7 +14,7 @@
{{svg "octicon-flame" 16}} {{(.DownloadCount | PrettyNumber)}} - {{svg "octicon-file" 16}} + {{svg "octicon-file" 16}} {{svg "octicon-file-binary" 16}}
{{if eq .DecompressState 1}} From 11bacb83e24ef682d5186deeca22e7137b9c9786 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Thu, 17 Feb 2022 16:54:38 +0800 Subject: [PATCH 4/4] download link --- models/attachment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/attachment.go b/models/attachment.go index 6ab1f3652..c322d391b 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -97,7 +97,7 @@ func (a *Attachment) DownloadURL() string { return fmt.Sprintf("%sattachments/%s?type=%d", setting.AppURL, a.UUID, a.Type) } -// DownloadURL returns the download url of the attached file +// S3DownloadURL returns the s3 download url of the attached file func (a *Attachment) S3DownloadURL() string { url := "" if a.Type == TypeCloudBrainOne {