Browse Source

feat; regular the codes

master
colorfulberry 5 years ago
parent
commit
69069155f4
5 changed files with 25 additions and 24 deletions
  1. +6
    -6
      modules/storage/local.go
  2. +11
    -11
      modules/storage/minio.go
  3. +1
    -1
      modules/upload/filetype.go
  4. +4
    -4
      routers/repo/attachment.go
  5. +3
    -2
      routers/repo/dataset.go

+ 6
- 6
modules/storage/local.go View File

@@ -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
}

+ 11
- 11
modules/storage/minio.go View File

@@ -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
}

+ 1
- 1
modules/upload/filetype.go View File

@@ -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
}


+ 4
- 4
routers/repo/attachment.go View File

@@ -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"),
})



+ 3
- 2
routers/repo/dataset.go View File

@@ -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)
}


Loading…
Cancel
Save