Validate validates the uploadRequest fields
(maxFileSizeBytes config.FileSizeBytes)
| 245 | |
| 246 | // Validate validates the uploadRequest fields |
| 247 | func (r *uploadRequest) Validate(maxFileSizeBytes config.FileSizeBytes) *util.JSONResponse { |
| 248 | if maxFileSizeBytes > 0 && r.MediaMetadata.FileSizeBytes > types.FileSizeBytes(maxFileSizeBytes) { |
| 249 | return requestEntityTooLargeJSONResponse(maxFileSizeBytes) |
| 250 | } |
| 251 | if strings.HasPrefix(string(r.MediaMetadata.UploadName), "~") { |
| 252 | return &util.JSONResponse{ |
| 253 | Code: http.StatusBadRequest, |
| 254 | JSON: jsonerror.Unknown("File name must not begin with '~'."), |
| 255 | } |
| 256 | } |
| 257 | // TODO: Validate filename - what are the valid characters? |
| 258 | if r.MediaMetadata.UserID != "" { |
| 259 | // TODO: We should put user ID parsing code into gomatrixserverlib and use that instead |
| 260 | // (see https://github.com/matrix-org/gomatrixserverlib/blob/3394e7c7003312043208aa73727d2256eea3d1f6/eventcontent.go#L347 ) |
| 261 | // It should be a struct (with pointers into a single string to avoid copying) and |
| 262 | // we should update all refs to use UserID types rather than strings. |
| 263 | // https://github.com/matrix-org/synapse/blob/v0.19.2/synapse/types.py#L92 |
| 264 | if _, _, err := gomatrixserverlib.SplitID('@', string(r.MediaMetadata.UserID)); err != nil { |
| 265 | return &util.JSONResponse{ |
| 266 | Code: http.StatusBadRequest, |
| 267 | JSON: jsonerror.BadJSON("user id must be in the form @localpart:domain"), |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | return nil |
| 272 | } |
| 273 | |
| 274 | // storeFileAndMetadata moves the temporary file to its final path based on metadata and stores the metadata in the database |
| 275 | // See getPathFromMediaMetadata in fileutils for details of the final path. |
no test coverage detected