Compare commits

...

2 Commits

Author SHA1 Message Date
Matt Jankowski
5fbf7619b8
Merge b3ba07e6fa into c442589593 2025-07-10 08:06:41 +00:00
Matt Jankowski
b3ba07e6fa Add concern for MediaAttachment file extensions 2025-07-03 18:26:08 -04:00
2 changed files with 49 additions and 8 deletions

View File

@ -0,0 +1,48 @@
# frozen_string_literal: true
module MediaAttachment::Extensions
extend ActiveSupport::Concern
AUDIO_FILE_EXTENSIONS = %w(
.3gp
.aac
.flac
.m4a
.mp3
.oga
.ogg
.opus
.wav
.wma
).freeze
IMAGE_FILE_EXTENSIONS = %w(
.avif
.gif
.heic
.heif
.jpeg
.jpg
.png
.webp
).freeze
VIDEO_FILE_EXTENSIONS = %w(
.m4v
.mov
.mp4
.webm
).freeze
class_methods do
def supported_file_extensions
[
AUDIO_FILE_EXTENSIONS,
IMAGE_FILE_EXTENSIONS,
VIDEO_FILE_EXTENSIONS,
]
.flatten
.sort
end
end
end

View File

@ -33,6 +33,7 @@ class MediaAttachment < ApplicationRecord
self.inheritance_column = nil self.inheritance_column = nil
include Attachmentable include Attachmentable
include MediaAttachment::Extensions
enum :type, { image: 0, gifv: 1, video: 2, unknown: 3, audio: 4 } enum :type, { image: 0, gifv: 1, video: 2, unknown: 3, audio: 4 }
enum :processing, { queued: 0, in_progress: 1, complete: 2, failed: 3 }, prefix: true enum :processing, { queued: 0, in_progress: 1, complete: 2, failed: 3 }, prefix: true
@ -46,10 +47,6 @@ class MediaAttachment < ApplicationRecord
MAX_VIDEO_FRAME_RATE = 120 MAX_VIDEO_FRAME_RATE = 120
MAX_VIDEO_FRAMES = 36_000 # Approx. 5 minutes at 120 fps MAX_VIDEO_FRAMES = 36_000 # Approx. 5 minutes at 120 fps
IMAGE_FILE_EXTENSIONS = %w(.jpg .jpeg .png .gif .webp .heic .heif .avif).freeze
VIDEO_FILE_EXTENSIONS = %w(.webm .mp4 .m4v .mov).freeze
AUDIO_FILE_EXTENSIONS = %w(.ogg .oga .mp3 .wav .flac .opus .aac .m4a .3gp .wma).freeze
META_KEYS = %i( META_KEYS = %i(
focus focus
colors colors
@ -294,10 +291,6 @@ class MediaAttachment < ApplicationRecord
IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES
end end
def supported_file_extensions
IMAGE_FILE_EXTENSIONS + VIDEO_FILE_EXTENSIONS + AUDIO_FILE_EXTENSIONS
end
private private
def file_styles(attachment) def file_styles(attachment)