mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
Storage: validation and sanitization stubs (#50523)
* add `IsPathValidationError` util to fs api * refactor storage.Upload method * remove unused struct * extract `RootUpload` constant * move file validation outside of the service * Make UploadErrorToStatusCode exported * validation/sanitization * refactor pathValidationError check * refactor, rename sanitize to transform * add a todo * refactor * transform -> sanitize * lint fix * #50608: fix jpg/jpeg Co-authored-by: Tania B <yalyna.ts@gmail.com> Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
co-authored by
Tania B
Ryan McKinley
parent
dfb0f6b1b8
commit
cc4473faf3
@@ -34,18 +34,12 @@ func ProvideHTTPService(store StorageService) HTTPStorageService {
|
||||
func UploadErrorToStatusCode(err error) int {
|
||||
switch {
|
||||
case errors.Is(err, ErrUploadFeatureDisabled):
|
||||
return 404
|
||||
|
||||
case errors.Is(err, ErrUnsupportedStorage):
|
||||
return 400
|
||||
|
||||
case errors.Is(err, ErrUnsupportedFolder):
|
||||
return 400
|
||||
|
||||
case errors.Is(err, ErrFileTooBig):
|
||||
return 400
|
||||
|
||||
case errors.Is(err, ErrInvalidPath):
|
||||
return 400
|
||||
|
||||
case errors.Is(err, ErrInvalidFileType):
|
||||
case errors.Is(err, ErrValidationFailed):
|
||||
return 400
|
||||
|
||||
case errors.Is(err, ErrFileAlreadyExists):
|
||||
@@ -102,9 +96,10 @@ func (s *httpStorage) Upload(c *models.ReqContext) response.Response {
|
||||
|
||||
mimeType := http.DetectContentType(data)
|
||||
|
||||
err = s.store.Upload(c.Req.Context(), c.SignedInUser, UploadRequest{
|
||||
err = s.store.Upload(c.Req.Context(), c.SignedInUser, &UploadRequest{
|
||||
Contents: data,
|
||||
MimeType: mimeType,
|
||||
EntityType: EntityTypeImage,
|
||||
Path: path,
|
||||
OverwriteExistingFile: true,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user