-
Notifications
You must be signed in to change notification settings - Fork 0
Make human readable short urls #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
793d001
Add album image model
bbucsy 3c8835c
Add image controller
bbucsy 1686b4a
fix image metadata issue
bbucsy 8a81967
upgrade data migration rake task
bbucsy 8300c52
update controllers to use new model
bbucsy 75e2df9
run rubocop
bbucsy 63e73e6
update migration task
bbucsy 2fb404b
Update model slug creation
bbucsy 24e5137
update rubocop
bbucsy 4caebda
fix public image not avalable outside application bug
bbucsy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -35,3 +35,5 @@ | |
yarn-debug.log* | ||
.yarn-integrity | ||
.env | ||
|
||
.idea |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,3 @@ | ||
// Place all the styles related to the AlbumImage controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: https://sass-lang.com/ |
This file contains hidden or 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,38 @@ | ||
class AlbumImageController < ApplicationController | ||
before_action :set_image | ||
|
||
def show | ||
http_cache_forever public: true do | ||
content_headers_from @image.file.blob | ||
stream @image.file.blob | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_image | ||
@image = AlbumImage.friendly.find(params[:id]) | ||
authorize_image | ||
end | ||
|
||
def authorize_image | ||
unless current_user.present? && (current_user.site_admin? || logged_in_as_admin_of?(album.circle) || album.shared?) | ||
redirect_to '/', notice: I18n.t('unauthorized', scope: 'album_images.errors') | ||
end | ||
end | ||
|
||
def content_headers_from(blob) | ||
response.headers['Content-Type'] = blob.content_type_for_serving | ||
response.headers['Content-Disposition'] = ActionDispatch::Http::ContentDisposition.format \ | ||
disposition: blob.forced_disposition_for_serving || params[:disposition] || 'inline', | ||
filename: blob.filename.sanitized | ||
end | ||
|
||
def stream(blob) | ||
blob.download do |chunk| | ||
response.stream.write chunk | ||
end | ||
ensure | ||
response.stream.close | ||
end | ||
end |
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,2 @@ | ||
module AlbumImageHelper | ||
end |
This file contains hidden or 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 |
---|---|---|
@@ -1,19 +1,27 @@ | ||
class Album < ApplicationRecord | ||
has_many_attached :images | ||
validates :title, presence: true, length: { minimum: 3, maximum: 128 } | ||
validates :desc, length: { maximum: 255 } | ||
belongs_to :user | ||
belongs_to :circle | ||
has_many :album_images, dependent: :destroy, autosave: true | ||
|
||
def thumbnail | ||
if images.empty? | ||
if album_images.empty? | ||
ActionController::Base.helpers.image_url('album-blank.jpg') | ||
else | ||
images.first.variant gravity: 'Center', resize: '300x200^', crop: '300x200+0+0' | ||
album_images.first.file.variant gravity: 'Center', resize: '300x200^', crop: '300x200+0+0' | ||
end | ||
end | ||
|
||
def self.find_blob_owner(blob_id) | ||
Album.joins(:images_blobs).find_by(active_storage_blobs: { id: blob_id }) | ||
def images | ||
album_images | ||
end | ||
|
||
def build_images(images) | ||
return if images.blank? | ||
|
||
images.each do |image| | ||
album_images.build(file: image) | ||
end | ||
end | ||
end |
This file contains hidden or 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,33 @@ | ||
class AlbumImage < ApplicationRecord | ||
extend FriendlyId | ||
belongs_to :album | ||
has_one_attached :file | ||
friendly_id :slug_candidates, use: :slugged | ||
|
||
private | ||
|
||
def slug_candidates | ||
[ | ||
:filename, | ||
%i[filename extension], | ||
%i[album_name filename extension], | ||
%i[circle_name album_name filename extension] | ||
] | ||
end | ||
|
||
def filename | ||
file.filename.base.to_s | ||
end | ||
|
||
def extension | ||
file.filename.extension_without_delimiter.to_s | ||
end | ||
|
||
def circle_name | ||
album.circle.name | ||
end | ||
|
||
def album_name | ||
album.title | ||
end | ||
end |
This file contains hidden or 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 |
---|---|---|
|
@@ -10,8 +10,8 @@ | |
</span> | ||
<% end %> | ||
<% unless @album.public? %> | ||
<span | ||
class="tag is-warning is-medium ml-1" | ||
<span | ||
class="tag is-warning is-medium ml-1" | ||
title="Az album képei nem elérhetőek a weboldalon kívülről" | ||
> | ||
Nem publikus<sup class="is-align-self-flex-start">?</sup> | ||
|
@@ -26,7 +26,7 @@ | |
<%= @album.desc %> | ||
</p> | ||
<p class="is-size-6 mt-5"> | ||
Használd a | ||
Használd a | ||
<svg xmlns="http://www.w3.org/2000/svg" height="20" fill="none" viewBox="0 2 24 20" stroke="currentColor"> | ||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3" /> | ||
</svg> | ||
|
@@ -110,7 +110,7 @@ | |
|
||
<script> | ||
images = <%= @album.images.map { |i| | ||
{ src: url_for(i), w: i.metadata["width"], h: i.metadata["height"] } | ||
{ src: url_for(i), w: i.file.metadata["width"], h: i.file.metadata["height"] } | ||
}.to_json.html_safe %> | ||
</script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/masonry.pkgd.min.js"></script> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line would be complete with only checking for
album.shared?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise anytime someone/some website would like to reach the image (for example, our blog), there should be a user logged in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh true, i forgot to check for public albums
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will correct it tomorrow