-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Make media its own model (#940)
* chore: Setup new Medium model and table This does *not* migrate data just yet, and is intended to record the model creation and associations without being in use yet. * db: Move Story Media migration * chore: switch active storage validator The new gem has more robust features, including that the attachment can be processable and custom proc validations. It's also a 1.0+ release rather than 0.X. From what I can determine, the old validation syntax is still compatible with this one, so no other changes are necessary for the swap. * Enable ActiveStorage 6.1 defaults * Story references new Medium model * refactor: extract media rendering into shared partial This way our media rendering stays consistent * Ensure routes to create, update, and delete Story Media still work * Ensure all API endpoints and usages of Medium are updated * Add file limit size on Media attachments * chore: update all file uploads to have restricted file sizes * Add irregular inflection for singular Media --------- Co-authored-by: Laura Mosher <[email protected]>
- Loading branch information
1 parent
3771942
commit 4e03e99
Showing
29 changed files
with
348 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class Media < ApplicationRecord | ||
self.table_name = "media" | ||
|
||
belongs_to :story | ||
|
||
has_one_attached :media do | ||
def blob_id | ||
blob.id | ||
end | ||
end | ||
|
||
validates :media, | ||
attached: true, | ||
# Symbol Content Types must map in Marcel::EXTENSIONS | ||
# otherwise, use string for full mime type. | ||
content_type: [ | ||
# image types | ||
:png, :jpeg, :svg, 'image/jpg', | ||
# video types | ||
:mpeg, :mp4, :mov, :webm, | ||
# audio types | ||
:mp3, :aac, :flac, :mp4a, :wav, | ||
'audio/wav', 'audio/m4a', 'audio/x-m4a', 'audio/x-aac', 'audio/x-flac', | ||
], | ||
size: { less_than_or_equal_to: 200.megabytes } | ||
|
||
delegate :content_type, :blob_id, :blob, to: :media | ||
end | ||
|
||
# == Schema Information | ||
# | ||
# Table name: media | ||
# | ||
# id :bigint not null, primary key | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# story_id :bigint | ||
# | ||
# Indexes | ||
# | ||
# index_media_on_story_id (story_id) | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<% if media.image? %> | ||
<% if media.variable? %> | ||
<%= image_tag(media.variant(resize_to_limit: [size, size])) %> | ||
<% else %> | ||
<%= image_tag(media, width: size) %> | ||
<% end %> | ||
<% elsif media.video? %> | ||
<video | ||
controls | ||
disablePictureInPicture | ||
controlsList="nodownload" | ||
id="video-player-<%= media.blob.id %>" | ||
poster="<%= url_for(media.preview(resize_to_limit:[nil, size])) if media.previewable? %>" | ||
> | ||
<source src="<%= url_for(media) %>"/> | ||
<%= t("video_unsupported") %> | ||
</video> | ||
<% elsif media.audio? %> | ||
<audio id="audio-player-<%= media.blob.id %>" | ||
controls | ||
controlsList="nodownload" | ||
ref="audio" | ||
> | ||
<source src="<%= url_for(media) %>" type="<%= media.blob.content_type %>" /> | ||
</audio> | ||
<% elsif media.previewable? %> | ||
<%= image_tag(media.preview(resize_to_limit:[size, size])) %> | ||
<% else %> | ||
<%= media.filename %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.