From 69069155f4baa106363d4e4ad736487d6bbc90a1 Mon Sep 17 00:00:00 2001 From: colorfulberry Date: Thu, 4 Jun 2020 18:18:12 +0800 Subject: [PATCH] feat; regular the codes --- modules/storage/local.go | 12 ++++++------ modules/storage/minio.go | 22 +++++++++++----------- modules/upload/filetype.go | 2 +- routers/repo/attachment.go | 8 ++++---- routers/repo/dataset.go | 5 +++-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/modules/storage/local.go b/modules/storage/local.go index 4d2f28029..c462dcd9e 100644 --- a/modules/storage/local.go +++ b/modules/storage/local.go @@ -65,14 +65,14 @@ func (l *LocalStorage) Delete(path string) error { return os.Remove(p) } -func (l *LocalStorage) PresignedGetURL(path string, fileName string) (string,error) { - return "",nil +func (l *LocalStorage) PresignedGetURL(path string, fileName string) (string, error) { + return "", nil } -func (l *LocalStorage) PresignedPutURL(path string) (string,error) { - return "",nil +func (l *LocalStorage) PresignedPutURL(path string) (string, error) { + return "", nil } -func (l *LocalStorage) HasObject(path string) (bool,error) { - return false,nil +func (l *LocalStorage) HasObject(path string) (bool, error) { + return false, nil } diff --git a/modules/storage/minio.go b/modules/storage/minio.go index dfbe39558..83a60f376 100644 --- a/modules/storage/minio.go +++ b/modules/storage/minio.go @@ -77,33 +77,33 @@ func (m *MinioStorage) Delete(path string) error { } //Get Presigned URL for get object -func (m *MinioStorage) PresignedGetURL(path string, fileName string) (string,error) { +func (m *MinioStorage) PresignedGetURL(path string, fileName string) (string, error) { // Set request parameters for content-disposition. reqParams := make(url.Values) - reqParams.Set("response-content-disposition", "attachment; filename=\"" + fileName + "\"") + reqParams.Set("response-content-disposition", "attachment; filename=\""+fileName+"\"") var preURL *url.URL - preURL,err := m.client.PresignedGetObject(m.bucket, m.buildMinioPath(path), PresignedGetUrlExpireTime, reqParams) + preURL, err := m.client.PresignedGetObject(m.bucket, m.buildMinioPath(path), PresignedGetUrlExpireTime, reqParams) if err != nil { - return "",err + return "", err } - return preURL.String(),nil + return preURL.String(), nil } //Get Presigned URL for put object -func (m *MinioStorage) PresignedPutURL(path string) (string,error) { +func (m *MinioStorage) PresignedPutURL(path string) (string, error) { var preURL *url.URL - preURL,err := m.client.PresignedPutObject(m.bucket, m.buildMinioPath(path), PresignedPutUrlExpireTime) + preURL, err := m.client.PresignedPutObject(m.bucket, m.buildMinioPath(path), PresignedPutUrlExpireTime) if err != nil { - return "",err + return "", err } - return preURL.String(),nil + return preURL.String(), nil } //check if has the object -func (m *MinioStorage) HasObject(path string) (bool,error) { +func (m *MinioStorage) HasObject(path string) (bool, error) { hasObject := false // Create a done channel to control 'ListObjects' go routine. doneCh := make(chan struct{}) @@ -120,5 +120,5 @@ func (m *MinioStorage) HasObject(path string) (bool,error) { hasObject = true } - return hasObject,nil + return hasObject, nil } diff --git a/modules/upload/filetype.go b/modules/upload/filetype.go index ff88eb140..a79178719 100644 --- a/modules/upload/filetype.go +++ b/modules/upload/filetype.go @@ -39,7 +39,7 @@ func VerifyFileType(fileType string, allowedTypes []string) error { t := strings.Trim(t, " ") if t == "*/*" || t == fileType || - // Allow directives after type, like 'text/plain; charset=utf-8' + // Allow directives after type, like 'text/plain; charset=utf-8' strings.HasPrefix(fileType, t+";") { return nil } diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 62d29cf22..9ee167b0b 100644 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -236,7 +236,7 @@ func GetPresignedPutObjectURL(ctx *context.Context) { ctx.JSON(200, map[string]string{ "uuid": uuid, - "url": url, + "url": url, }) } else { ctx.Error(404, "storage type is not enabled") @@ -247,7 +247,7 @@ func GetPresignedPutObjectURL(ctx *context.Context) { // AddAttachment response for add attachment record func AddAttachment(ctx *context.Context) { uuid := ctx.Query("uuid") - has,err := storage.Attachments.HasObject(models.AttachmentRelativePath(uuid)) + has, err := storage.Attachments.HasObject(models.AttachmentRelativePath(uuid)) if err != nil { ctx.ServerError("HasObject", err) return @@ -259,10 +259,10 @@ func AddAttachment(ctx *context.Context) { } _, err = models.InsertAttachment(&models.Attachment{ - UUID: uuid, + UUID: uuid, UploaderID: ctx.User.ID, Name: ctx.Query("file_name"), - Size: ctx.QueryInt64("size"), + Size: ctx.QueryInt64("size"), DatasetID: ctx.QueryInt64("dataset_id"), }) diff --git a/routers/repo/dataset.go b/routers/repo/dataset.go index 811011527..879f779c6 100644 --- a/routers/repo/dataset.go +++ b/routers/repo/dataset.go @@ -1,10 +1,11 @@ package repo import ( - "code.gitea.io/gitea/modules/storage" "net/url" "sort" + "code.gitea.io/gitea/modules/storage" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" @@ -86,7 +87,7 @@ func DatasetIndex(ctx *context.Context) { if err != nil { ctx.ServerError("PresignedPutURL", err) } - preUrl,err := url.QueryUnescape(tmpUrl) + preUrl, err := url.QueryUnescape(tmpUrl) if err != nil { ctx.ServerError("QueryUnescape", err) }