aboutsummaryrefslogtreecommitdiff
path: root/mediaapi
diff options
context:
space:
mode:
authordevonh <devon.dmytro@gmail.com>2023-05-09 22:46:49 +0000
committerGitHub <noreply@github.com>2023-05-09 22:46:49 +0000
commit0489d16f95a3d9f1f5bc532e2060bd2482d7b156 (patch)
treea0573b5a0c21ca563e97abae81e36d66ad14e7d8 /mediaapi
parenta49c9f01e227aeb12aa2f27d5bf1915453c23a3b (diff)
Move json errors over to gmsl (#3080)
Diffstat (limited to 'mediaapi')
-rw-r--r--mediaapi/routing/download.go13
-rw-r--r--mediaapi/routing/upload.go20
2 files changed, 16 insertions, 17 deletions
diff --git a/mediaapi/routing/download.go b/mediaapi/routing/download.go
index bba24327..e9f161a3 100644
--- a/mediaapi/routing/download.go
+++ b/mediaapi/routing/download.go
@@ -30,7 +30,6 @@ import (
"sync"
"unicode"
- "github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/mediaapi/fileutils"
"github.com/matrix-org/dendrite/mediaapi/storage"
"github.com/matrix-org/dendrite/mediaapi/thumbnailer"
@@ -130,7 +129,7 @@ func Download(
// TODO: Handle the fact we might have started writing the response
dReq.jsonErrorResponse(w, util.JSONResponse{
Code: http.StatusNotFound,
- JSON: jsonerror.NotFound("Failed to download: " + err.Error()),
+ JSON: spec.NotFound("Failed to download: " + err.Error()),
})
return
}
@@ -138,7 +137,7 @@ func Download(
if metadata == nil {
dReq.jsonErrorResponse(w, util.JSONResponse{
Code: http.StatusNotFound,
- JSON: jsonerror.NotFound("File not found"),
+ JSON: spec.NotFound("File not found"),
})
return
}
@@ -168,7 +167,7 @@ func (r *downloadRequest) Validate() *util.JSONResponse {
if !mediaIDRegex.MatchString(string(r.MediaMetadata.MediaID)) {
return &util.JSONResponse{
Code: http.StatusNotFound,
- JSON: jsonerror.NotFound(fmt.Sprintf("mediaId must be a non-empty string using only characters in %v", mediaIDCharacters)),
+ JSON: spec.NotFound(fmt.Sprintf("mediaId must be a non-empty string using only characters in %v", mediaIDCharacters)),
}
}
// Note: the origin will be validated either by comparison to the configured server name of this homeserver
@@ -176,7 +175,7 @@ func (r *downloadRequest) Validate() *util.JSONResponse {
if r.MediaMetadata.Origin == "" {
return &util.JSONResponse{
Code: http.StatusNotFound,
- JSON: jsonerror.NotFound("serverName must be a non-empty string"),
+ JSON: spec.NotFound("serverName must be a non-empty string"),
}
}
@@ -184,7 +183,7 @@ func (r *downloadRequest) Validate() *util.JSONResponse {
if r.ThumbnailSize.Width <= 0 || r.ThumbnailSize.Height <= 0 {
return &util.JSONResponse{
Code: http.StatusBadRequest,
- JSON: jsonerror.Unknown("width and height must be greater than 0"),
+ JSON: spec.Unknown("width and height must be greater than 0"),
}
}
// Default method to scale if not set
@@ -194,7 +193,7 @@ func (r *downloadRequest) Validate() *util.JSONResponse {
if r.ThumbnailSize.ResizeMethod != types.Crop && r.ThumbnailSize.ResizeMethod != types.Scale {
return &util.JSONResponse{
Code: http.StatusBadRequest,
- JSON: jsonerror.Unknown("method must be one of crop or scale"),
+ JSON: spec.Unknown("method must be one of crop or scale"),
}
}
}
diff --git a/mediaapi/routing/upload.go b/mediaapi/routing/upload.go
index 2175648e..5061d476 100644
--- a/mediaapi/routing/upload.go
+++ b/mediaapi/routing/upload.go
@@ -26,7 +26,6 @@ import (
"path"
"strings"
- "github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/mediaapi/fileutils"
"github.com/matrix-org/dendrite/mediaapi/storage"
"github.com/matrix-org/dendrite/mediaapi/thumbnailer"
@@ -34,6 +33,7 @@ import (
"github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
log "github.com/sirupsen/logrus"
)
@@ -165,7 +165,7 @@ func (r *uploadRequest) doUpload(
}).Warn("Error while transferring file")
return &util.JSONResponse{
Code: http.StatusBadRequest,
- JSON: jsonerror.Unknown("Failed to upload"),
+ JSON: spec.Unknown("Failed to upload"),
}
}
@@ -184,7 +184,7 @@ func (r *uploadRequest) doUpload(
if err != nil {
fileutils.RemoveDir(tmpDir, r.Logger)
r.Logger.WithError(err).Error("Error querying the database by hash.")
- resErr := jsonerror.InternalServerError()
+ resErr := spec.InternalServerError()
return &resErr
}
if existingMetadata != nil {
@@ -194,7 +194,7 @@ func (r *uploadRequest) doUpload(
mediaID, merr := r.generateMediaID(ctx, db)
if merr != nil {
r.Logger.WithError(merr).Error("Failed to generate media ID for existing file")
- resErr := jsonerror.InternalServerError()
+ resErr := spec.InternalServerError()
return &resErr
}
@@ -217,7 +217,7 @@ func (r *uploadRequest) doUpload(
if err != nil {
fileutils.RemoveDir(tmpDir, r.Logger)
r.Logger.WithError(err).Error("Failed to generate media ID for new upload")
- resErr := jsonerror.InternalServerError()
+ resErr := spec.InternalServerError()
return &resErr
}
}
@@ -239,7 +239,7 @@ func (r *uploadRequest) doUpload(
func requestEntityTooLargeJSONResponse(maxFileSizeBytes config.FileSizeBytes) *util.JSONResponse {
return &util.JSONResponse{
Code: http.StatusRequestEntityTooLarge,
- JSON: jsonerror.Unknown(fmt.Sprintf("HTTP Content-Length is greater than the maximum allowed upload size (%v).", maxFileSizeBytes)),
+ JSON: spec.Unknown(fmt.Sprintf("HTTP Content-Length is greater than the maximum allowed upload size (%v).", maxFileSizeBytes)),
}
}
@@ -251,7 +251,7 @@ func (r *uploadRequest) Validate(maxFileSizeBytes config.FileSizeBytes) *util.JS
if strings.HasPrefix(string(r.MediaMetadata.UploadName), "~") {
return &util.JSONResponse{
Code: http.StatusBadRequest,
- JSON: jsonerror.Unknown("File name must not begin with '~'."),
+ JSON: spec.Unknown("File name must not begin with '~'."),
}
}
// TODO: Validate filename - what are the valid characters?
@@ -264,7 +264,7 @@ func (r *uploadRequest) Validate(maxFileSizeBytes config.FileSizeBytes) *util.JS
if _, _, err := gomatrixserverlib.SplitID('@', string(r.MediaMetadata.UserID)); err != nil {
return &util.JSONResponse{
Code: http.StatusBadRequest,
- JSON: jsonerror.BadJSON("user id must be in the form @localpart:domain"),
+ JSON: spec.BadJSON("user id must be in the form @localpart:domain"),
}
}
}
@@ -290,7 +290,7 @@ func (r *uploadRequest) storeFileAndMetadata(
r.Logger.WithError(err).Error("Failed to move file.")
return &util.JSONResponse{
Code: http.StatusBadRequest,
- JSON: jsonerror.Unknown("Failed to upload"),
+ JSON: spec.Unknown("Failed to upload"),
}
}
if duplicate {
@@ -307,7 +307,7 @@ func (r *uploadRequest) storeFileAndMetadata(
}
return &util.JSONResponse{
Code: http.StatusBadRequest,
- JSON: jsonerror.Unknown("Failed to upload"),
+ JSON: spec.Unknown("Failed to upload"),
}
}