2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-16 20:46:42 -04:00
|
|
|
Fabricator(:upload) do
|
|
|
|
user
|
2020-06-03 00:23:46 -04:00
|
|
|
sha1 { sequence(:sha1) { |n| Digest::SHA1.hexdigest("#{n}#{Process.pid}") } }
|
2014-04-14 16:55:57 -04:00
|
|
|
original_filename "logo.png"
|
2013-06-16 20:46:42 -04:00
|
|
|
filesize 1234
|
|
|
|
width 100
|
|
|
|
height 200
|
2018-10-04 10:00:07 -04:00
|
|
|
thumbnail_width 30
|
|
|
|
thumbnail_height 60
|
2018-09-14 01:42:59 -04:00
|
|
|
|
|
|
|
url do |attrs|
|
|
|
|
sequence(:url) do |n|
|
|
|
|
Discourse.store.get_path_for("original", n + 1, attrs[:sha1], ".#{attrs[:extension]}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-03 13:08:59 -04:00
|
|
|
extension "png"
|
2013-06-16 20:46:42 -04:00
|
|
|
end
|
2013-07-10 16:59:07 -04:00
|
|
|
|
2022-11-24 20:40:31 -05:00
|
|
|
Fabricator(:large_image_upload, from: :upload) do
|
|
|
|
width 2000
|
|
|
|
height 2000
|
|
|
|
after_create do |upload, _transients|
|
|
|
|
file = file_from_fixtures("2000x2000.png")
|
|
|
|
upload.url = Discourse.store.store_upload(file, upload)
|
|
|
|
upload.sha1 = Upload.generate_digest(file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-26 10:40:00 -04:00
|
|
|
Fabricator(:image_upload, from: :upload) do
|
2022-09-20 05:28:17 -04:00
|
|
|
transient color: "white"
|
2023-02-14 20:41:04 -05:00
|
|
|
transient color_depth: 8
|
2022-09-20 05:28:17 -04:00
|
|
|
|
|
|
|
after_create do |upload, transients|
|
2020-03-26 10:40:00 -04:00
|
|
|
file = Tempfile.new(%w[fabricated .png])
|
2024-07-08 04:55:59 -04:00
|
|
|
`magick -size #{upload.width}x#{upload.height} -depth #{transients[:color_depth]} xc:#{transients[:color]} "#{file.path}"`
|
2020-03-26 10:40:00 -04:00
|
|
|
|
|
|
|
upload.url = Discourse.store.store_upload(file, upload)
|
|
|
|
upload.sha1 = Upload.generate_digest(file.path)
|
|
|
|
|
|
|
|
WebMock.stub_request(:get, "http://#{Discourse.current_hostname}#{upload.url}").to_return(
|
|
|
|
status: 200,
|
|
|
|
body: File.new(file.path),
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-13 18:54:28 -04:00
|
|
|
Fabricator(:upload_no_dimensions, from: :upload) do
|
|
|
|
width nil
|
|
|
|
height nil
|
|
|
|
thumbnail_width nil
|
|
|
|
thumbnail_height nil
|
|
|
|
end
|
|
|
|
|
2019-07-16 08:35:17 -04:00
|
|
|
Fabricator(:video_upload, from: :upload) do
|
|
|
|
original_filename "video.mp4"
|
|
|
|
width nil
|
|
|
|
height nil
|
|
|
|
thumbnail_width nil
|
|
|
|
thumbnail_height nil
|
|
|
|
extension "mp4"
|
|
|
|
end
|
|
|
|
|
2020-01-15 22:50:27 -05:00
|
|
|
Fabricator(:secure_upload, from: :upload) do
|
2020-04-22 14:49:53 -04:00
|
|
|
secure true
|
2020-01-15 22:50:27 -05:00
|
|
|
sha1 { SecureRandom.hex(20) }
|
|
|
|
original_sha1 { sequence(:sha1) { |n| Digest::SHA1.hexdigest(n.to_s) } }
|
|
|
|
end
|
|
|
|
|
2017-05-22 12:37:01 -04:00
|
|
|
Fabricator(:upload_s3, from: :upload) do
|
2018-09-14 01:42:59 -04:00
|
|
|
url do |attrs|
|
|
|
|
sequence(:url) do |n|
|
2019-05-30 02:38:46 -04:00
|
|
|
path = +Discourse.store.get_path_for("original", n + 1, attrs[:sha1], ".#{attrs[:extension]}")
|
|
|
|
|
|
|
|
path.prepend(File.join(Discourse.store.upload_path, "/")) if Rails.configuration.multisite
|
|
|
|
|
|
|
|
File.join(Discourse.store.absolute_base_url, path)
|
2018-09-14 01:42:59 -04:00
|
|
|
end
|
|
|
|
end
|
2013-07-10 16:59:07 -04:00
|
|
|
end
|
2020-01-28 19:11:38 -05:00
|
|
|
|
2020-06-11 08:47:59 -04:00
|
|
|
Fabricator(:s3_image_upload, from: :upload_s3) do
|
|
|
|
after_create do |upload|
|
|
|
|
file = Tempfile.new(%w[fabricated .png])
|
2024-07-08 04:55:59 -04:00
|
|
|
`magick -size #{upload.width}x#{upload.height} xc:white "#{file.path}"`
|
2020-06-11 08:47:59 -04:00
|
|
|
|
2021-05-27 11:42:25 -04:00
|
|
|
upload.url = Discourse.store.store_upload(file, upload)
|
2020-06-11 08:47:59 -04:00
|
|
|
upload.sha1 = Upload.generate_digest(file.path)
|
|
|
|
|
|
|
|
WebMock.stub_request(:get, upload.url).to_return(status: 200, body: File.new(file.path))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-28 19:11:38 -05:00
|
|
|
Fabricator(:secure_upload_s3, from: :upload_s3) do
|
2020-04-22 14:49:53 -04:00
|
|
|
secure true
|
2020-01-28 19:11:38 -05:00
|
|
|
sha1 { SecureRandom.hex(20) }
|
|
|
|
original_sha1 { sequence(:sha1) { |n| Digest::SHA1.hexdigest(n.to_s) } }
|
|
|
|
end
|
2023-01-23 22:28:21 -05:00
|
|
|
|
|
|
|
Fabricator(:upload_reference) do
|
|
|
|
target
|
|
|
|
upload
|
|
|
|
end
|