Browse Source

download obs

tags/v1.21.12.1
yuyuanshifu 4 years ago
parent
commit
799587ce05
5 changed files with 44 additions and 8 deletions
  1. +19
    -0
      modules/storage/obs.go
  2. +22
    -5
      routers/repo/attachment.go
  3. +1
    -0
      routers/repo/dataset.go
  4. +2
    -2
      templates/repo/datasets/dataset_list.tmpl
  5. +0
    -1
      templates/repo/datasets/index.tmpl

+ 19
- 0
modules/storage/obs.go View File

@@ -154,3 +154,22 @@ func ObsGenMultiPartSignedUrl(uuid string, uploadId string, partNumber int, part
return req.URL.String(), nil

}

func ObsGetPreSignedUrl(uuid, fileName string) (string, error) {
input := &obs.CreateSignedUrlInput{}
input.Method = obs.HttpMethodGet
input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid)), "/")
input.Bucket = setting.Bucket
input.Expires = 60 * 60
reqParams := make(map[string]string)
reqParams["response-content-disposition"] = "attachment; filename=\"" + fileName + "\""
input.QueryParams = reqParams
output, err := ObsCli.CreateSignedUrl(input)
if err != nil {
log.Error("CreateSignedUrl failed:", err.Error())
return "", err
}

return output.SignedUrl, nil
}

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

@@ -143,6 +143,13 @@ func DeleteAttachment(ctx *context.Context) {

// GetAttachment serve attachements
func GetAttachment(ctx *context.Context) {
typeCloudBrain := ctx.QueryInt("type")
err := checkTypeCloudBrain(typeCloudBrain)
if err != nil {
ctx.ServerError("checkTypeCloudBrain failed", err)
return
}

attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid"))
if err != nil {
if models.IsErrAttachmentNotExist(err) {
@@ -196,19 +203,29 @@ func GetAttachment(ctx *context.Context) {

//If we have matched and access to release or issue
if setting.Attachment.StoreType == storage.MinioStorageType {
url, err := storage.Attachments.PresignedGetURL(attach.RelativePath(), attach.Name)
if err != nil {
ctx.ServerError("PresignedGetURL", err)
return
url := ""
if typeCloudBrain == models.TypeCloudBrainOne {
url, err = storage.Attachments.PresignedGetURL(attach.RelativePath(), attach.Name)
if err != nil {
ctx.ServerError("PresignedGetURL", err)
return
}
} else {
url, err = storage.ObsGetPreSignedUrl(attach.UUID, attach.Name)
if err != nil {
ctx.ServerError("ObsGetPreSignedUrl", err)
return
}
}

log.Info(url)

if err = increaseDownloadCount(attach, dataSet); err != nil {
ctx.ServerError("Update", err)
return
}

http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently)

} else {
fr, err := storage.Attachments.Open(attach.RelativePath())
if err != nil {


+ 1
- 0
routers/repo/dataset.go View File

@@ -80,6 +80,7 @@ func DatasetIndex(ctx *context.Context) {
ctx.Data["Attachments"] = attachments
ctx.Data["IsOwner"] = true
ctx.Data["StoreType"] = setting.Attachment.StoreType
ctx.Data["Type"] = ctx.QueryInt("type")

renderAttachmentSettings(ctx)



+ 2
- 2
templates/repo/datasets/dataset_list.tmpl View File

@@ -3,7 +3,7 @@
<div class="ui grid item" id="{{.UUID}}">
<div class="row">
<div class="{{if $.Permission.CanWrite $.UnitTypeDatasets}}five{{else}}nine{{end}} wide column">
<a class="title" href="{{.DownloadURL}}">
<a class="title" href="{{.DownloadURL}}?type={{$.Type}}">
<span class="fitted">{{svg "octicon-cloud-download" 16}}</span> {{.Name}}
</a>
</div>
@@ -14,7 +14,7 @@
<span class="ui text center" data-tooltip='{{$.i18n.Tr "dataset.download_count"}}' data-position="bottom right">{{svg "octicon-flame" 16}} {{(.DownloadCount | PrettyNumber)}}</span>
</div>

<div class="one wide column">
<div class="one wide column" style="{{if ne $.Type 0}}visibility: hidden;{{end}}">
<span class="ui text center clipboard" data-clipboard-text="{{.DownloadURL}}" data-tooltip='{{$.i18n.Tr "dataset.copy_url"}}' data-clipboard-action="copy">{{svg "octicon-file" 16}}</span>
</div>



+ 0
- 1
templates/repo/datasets/index.tmpl View File

@@ -5,7 +5,6 @@
$(document).ready(function() {
url = window.location.href
type = url.split('?type=')[1]
console.log(type)
if (type == 0){
$('.contorl_component').attr("id", 'minioUploader')
}else{


Loading…
Cancel
Save