| @@ -65,14 +65,14 @@ func (l *LocalStorage) Delete(path string) error { | |||||
| return os.Remove(p) | 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 | |||||
| } | } | ||||
| @@ -77,33 +77,33 @@ func (m *MinioStorage) Delete(path string) error { | |||||
| } | } | ||||
| //Get Presigned URL for get object | //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. | // Set request parameters for content-disposition. | ||||
| reqParams := make(url.Values) | reqParams := make(url.Values) | ||||
| reqParams.Set("response-content-disposition", "attachment; filename=\"" + fileName + "\"") | |||||
| reqParams.Set("response-content-disposition", "attachment; filename=\""+fileName+"\"") | |||||
| var preURL *url.URL | 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 { | if err != nil { | ||||
| return "",err | |||||
| return "", err | |||||
| } | } | ||||
| return preURL.String(),nil | |||||
| return preURL.String(), nil | |||||
| } | } | ||||
| //Get Presigned URL for put object | //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 | 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 { | if err != nil { | ||||
| return "",err | |||||
| return "", err | |||||
| } | } | ||||
| return preURL.String(),nil | |||||
| return preURL.String(), nil | |||||
| } | } | ||||
| //check if has the object | //check if has the object | ||||
| func (m *MinioStorage) HasObject(path string) (bool,error) { | |||||
| func (m *MinioStorage) HasObject(path string) (bool, error) { | |||||
| hasObject := false | hasObject := false | ||||
| // Create a done channel to control 'ListObjects' go routine. | // Create a done channel to control 'ListObjects' go routine. | ||||
| doneCh := make(chan struct{}) | doneCh := make(chan struct{}) | ||||
| @@ -120,5 +120,5 @@ func (m *MinioStorage) HasObject(path string) (bool,error) { | |||||
| hasObject = true | hasObject = true | ||||
| } | } | ||||
| return hasObject,nil | |||||
| return hasObject, nil | |||||
| } | } | ||||
| @@ -39,7 +39,7 @@ func VerifyFileType(fileType string, allowedTypes []string) error { | |||||
| t := strings.Trim(t, " ") | t := strings.Trim(t, " ") | ||||
| if t == "*/*" || t == fileType || | 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+";") { | strings.HasPrefix(fileType, t+";") { | ||||
| return nil | return nil | ||||
| } | } | ||||
| @@ -236,7 +236,7 @@ func GetPresignedPutObjectURL(ctx *context.Context) { | |||||
| ctx.JSON(200, map[string]string{ | ctx.JSON(200, map[string]string{ | ||||
| "uuid": uuid, | "uuid": uuid, | ||||
| "url": url, | |||||
| "url": url, | |||||
| }) | }) | ||||
| } else { | } else { | ||||
| ctx.Error(404, "storage type is not enabled") | ctx.Error(404, "storage type is not enabled") | ||||
| @@ -247,7 +247,7 @@ func GetPresignedPutObjectURL(ctx *context.Context) { | |||||
| // AddAttachment response for add attachment record | // AddAttachment response for add attachment record | ||||
| func AddAttachment(ctx *context.Context) { | func AddAttachment(ctx *context.Context) { | ||||
| uuid := ctx.Query("uuid") | uuid := ctx.Query("uuid") | ||||
| has,err := storage.Attachments.HasObject(models.AttachmentRelativePath(uuid)) | |||||
| has, err := storage.Attachments.HasObject(models.AttachmentRelativePath(uuid)) | |||||
| if err != nil { | if err != nil { | ||||
| ctx.ServerError("HasObject", err) | ctx.ServerError("HasObject", err) | ||||
| return | return | ||||
| @@ -259,10 +259,10 @@ func AddAttachment(ctx *context.Context) { | |||||
| } | } | ||||
| _, err = models.InsertAttachment(&models.Attachment{ | _, err = models.InsertAttachment(&models.Attachment{ | ||||
| UUID: uuid, | |||||
| UUID: uuid, | |||||
| UploaderID: ctx.User.ID, | UploaderID: ctx.User.ID, | ||||
| Name: ctx.Query("file_name"), | Name: ctx.Query("file_name"), | ||||
| Size: ctx.QueryInt64("size"), | |||||
| Size: ctx.QueryInt64("size"), | |||||
| DatasetID: ctx.QueryInt64("dataset_id"), | DatasetID: ctx.QueryInt64("dataset_id"), | ||||
| }) | }) | ||||
| @@ -1,10 +1,11 @@ | |||||
| package repo | package repo | ||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/modules/storage" | |||||
| "net/url" | "net/url" | ||||
| "sort" | "sort" | ||||
| "code.gitea.io/gitea/modules/storage" | |||||
| "code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
| "code.gitea.io/gitea/modules/auth" | "code.gitea.io/gitea/modules/auth" | ||||
| "code.gitea.io/gitea/modules/base" | "code.gitea.io/gitea/modules/base" | ||||
| @@ -86,7 +87,7 @@ func DatasetIndex(ctx *context.Context) { | |||||
| if err != nil { | if err != nil { | ||||
| ctx.ServerError("PresignedPutURL", err) | ctx.ServerError("PresignedPutURL", err) | ||||
| } | } | ||||
| preUrl,err := url.QueryUnescape(tmpUrl) | |||||
| preUrl, err := url.QueryUnescape(tmpUrl) | |||||
| if err != nil { | if err != nil { | ||||
| ctx.ServerError("QueryUnescape", err) | ctx.ServerError("QueryUnescape", err) | ||||
| } | } | ||||