uploads: fix broken tests.

* Fix broken upload tests.
* Fix uploads to return an error if both a file and a source are given
  at the same time, or if neither are given. Also fix the error message
  in this case so that it doesn't include "base" at the start of the string.
* Fix uploads to percent-encode any Unicode characters in the source URL.
* Add a max filesize validation to media assets.
This commit is contained in:
evazion
2022-01-29 04:38:47 -06:00
parent 5d0c14d2bd
commit 11b7bcac91
9 changed files with 248 additions and 611 deletions

View File

@@ -35,6 +35,7 @@ class MediaAsset < ApplicationRecord
validates :md5, uniqueness: { conditions: -> { where(status: [:processing, :active]) } }
validates :file_ext, inclusion: { in: %w[jpg png gif mp4 webm swf zip], message: "Not an image or video" }
validates :file_size, numericality: { less_than_or_equal_to: Danbooru.config.max_file_size }
validates :duration, numericality: { less_than_or_equal_to: MAX_VIDEO_DURATION, message: "must be less than #{MAX_VIDEO_DURATION} seconds", allow_nil: true }, on: :create # XXX should allow admins to bypass
validate :validate_resolution, on: :create
@@ -228,7 +229,7 @@ class MediaAsset < ApplicationRecord
# failed state, then mark the asset as failed so the user can try the upload again later.
if !media_asset.active?
media_asset.update!(status: :failed)
raise Error, "Upload failed, try again (upload was stuck in 'processing' state)"
raise Error, "Upload failed, try again (timed out while waiting for file to be processed)"
end
media_asset