diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/concerns/file_attachment.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/app/models/concerns/file_attachment.rb b/app/models/concerns/file_attachment.rb index e9acda6..0e99fa2 100644 --- a/app/models/concerns/file_attachment.rb +++ b/app/models/concerns/file_attachment.rb | |||
| @@ -28,7 +28,9 @@ module FileAttachment | |||
| 28 | headline: { geometry: "460x250!", format: nil } | 28 | headline: { geometry: "460x250!", format: nil } |
| 29 | }.freeze | 29 | }.freeze |
| 30 | 30 | ||
| 31 | IMAGE_CONTENT_TYPES = %w[image/jpeg image/gif image/png image/webp].freeze | 31 | IMAGE_CONTENT_TYPES = %w[image/jpeg image/gif image/png image/webp].freeze |
| 32 | VECTOR_CONTENT_TYPES = %w[image/svg+xml].freeze | ||
| 33 | DISPLAYABLE_AS_IMAGE = IMAGE_CONTENT_TYPES + VECTOR_CONTENT_TYPES | ||
| 32 | 34 | ||
| 33 | included do | 35 | included do |
| 34 | attr_reader :upload | 36 | attr_reader :upload |
| @@ -69,6 +71,8 @@ module FileAttachment | |||
| 69 | 71 | ||
| 70 | if IMAGE_CONTENT_TYPES.include?(upload_content_type) | 72 | if IMAGE_CONTENT_TYPES.include?(upload_content_type) |
| 71 | generate_variants(original_path) | 73 | generate_variants(original_path) |
| 74 | elsif VECTOR_CONTENT_TYPES.include?(upload_content_type) | ||
| 75 | generate_svg_variants(original_path) | ||
| 72 | end | 76 | end |
| 73 | end | 77 | end |
| 74 | 78 | ||
| @@ -80,6 +84,14 @@ module FileAttachment | |||
| 80 | end | 84 | end |
| 81 | end | 85 | end |
| 82 | 86 | ||
| 87 | def generate_svg_variants(original_path) | ||
| 88 | STYLES.each do |style, _| | ||
| 89 | dest_path = file_path(style) | ||
| 90 | FileUtils.mkdir_p(File.dirname(dest_path)) | ||
| 91 | FileUtils.cp(original_path, dest_path) | ||
| 92 | end | ||
| 93 | end | ||
| 94 | |||
| 83 | def delete_upload_files | 95 | def delete_upload_files |
| 84 | dir = Rails.root.join("public", "system", "uploads", id.to_s) | 96 | dir = Rails.root.join("public", "system", "uploads", id.to_s) |
| 85 | FileUtils.rm_rf(dir) if Dir.exist?(dir) | 97 | FileUtils.rm_rf(dir) if Dir.exist?(dir) |
