[deploy] Migrate ProfileImage to Images::Profile (#10055)

This commit is contained in:
Mac Siri 2020-09-01 17:16:03 -04:00 committed by GitHub
parent 79b00d4960
commit ab81f36a38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
62 changed files with 99 additions and 99 deletions

View file

@ -56,7 +56,7 @@ class AsyncInfoController < ApplicationController
id: @user.id, id: @user.id,
name: @user.name, name: @user.name,
username: @user.username, username: @user.username,
profile_image_90: ProfileImage.new(@user).get(width: 90), profile_image_90: Images::Profile.call(@user.profile_image_url, length: 90),
followed_tags: @user.cached_followed_tags.to_json(only: %i[id name bg_color_hex text_color_hex hotness_score], followed_tags: @user.cached_followed_tags.to_json(only: %i[id name bg_color_hex text_color_hex hotness_score],
methods: [:points]), methods: [:points]),
followed_podcast_ids: @user.cached_following_podcasts_ids, followed_podcast_ids: @user.cached_following_podcasts_ids,

View file

@ -378,7 +378,7 @@ class StoriesController < ApplicationController
}, },
"url": URL.user(@user), "url": URL.user(@user),
"sameAs": user_same_as, "sameAs": user_same_as,
"image": ProfileImage.new(@user).get(width: 320), "image": Images::Profile.call(@user.profile_image_url, length: 320),
"name": @user.name, "name": @user.name,
"email": @user.email_public ? @user.email : nil, "email": @user.email_public ? @user.email : nil,
"jobTitle": @user.employment_title.presence, "jobTitle": @user.employment_title.presence,
@ -444,7 +444,7 @@ class StoriesController < ApplicationController
"@id": URL.organization(@organization) "@id": URL.organization(@organization)
}, },
"url": URL.organization(@organization), "url": URL.organization(@organization),
"image": ProfileImage.new(@organization).get(width: 320), "image": Images::Profile.call(@organization.profile_image_url, length: 320),
"name": @organization.name, "name": @organization.name,
"description": @organization.summary.presence || "404 bio not found" "description": @organization.summary.presence || "404 bio not found"
} }

View file

@ -8,7 +8,7 @@ module ChatChannelMembershipHelper
membership_id: membership.id, membership_id: membership.id,
role: membership.role, role: membership.role,
status: membership.status, status: membership.status,
image: ProfileImage.new(membership.user).get(width: 90) image: Images::Profile.call(membership.user.profile_image_url, length: 90)
} }
end end
end end
@ -21,7 +21,7 @@ module ChatChannelMembershipHelper
membership_id: membership.id, membership_id: membership.id,
role: membership.role, role: membership.role,
status: membership.status, status: membership.status,
image: ProfileImage.new(membership.user).get(width: 90) image: Images::Profile.call(membership.user.profile_image_url, length: 90)
} }
end end
end end

View file

@ -8,7 +8,7 @@ module ChatChannelMembershipsHelper
membership_id: membership.id, membership_id: membership.id,
role: membership.role, role: membership.role,
status: membership.status, status: membership.status,
image: ProfileImage.new(membership.user).get(width: 90), image: Images::Profile.call(membership.user.profile_image_url, length: 90),
chat_channel_name: membership.chat_channel.channel_name, chat_channel_name: membership.chat_channel.channel_name,
chat_channel_id: membership.chat_channel.id, chat_channel_id: membership.chat_channel.id,
slug: membership.chat_channel.slug slug: membership.chat_channel.slug

View file

@ -8,7 +8,7 @@ module MessagesHelper
chat_channel_adjusted_slug: new_message.chat_channel.adjusted_slug(current_user, "sender"), chat_channel_adjusted_slug: new_message.chat_channel.adjusted_slug(current_user, "sender"),
channel_type: new_message.chat_channel.channel_type, channel_type: new_message.chat_channel.channel_type,
username: new_message.user.username, username: new_message.user.username,
profile_image_url: ProfileImage.new(new_message.user).get(width: 90), profile_image_url: Images::Profile.call(new_message.user.profile_image_url, length: 90),
message: new_message.message_html, message: new_message.message_html,
markdown: new_message.message_markdown, markdown: new_message.message_markdown,
edited_at: new_message.edited_at, edited_at: new_message.edited_at,

View file

@ -1,13 +0,0 @@
class ProfileImage
BACKUP_LINK = "https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png".freeze
attr_accessor :image_link
def initialize(resource)
@image_link = resource.profile_image_url
end
def get(width: 120)
Images::Optimizer.call(image_link || BACKUP_LINK, width: width, height: width, crop: "fill")
end
end

View file

@ -169,7 +169,7 @@ class ChatChannel < ApplicationRecord
def user_obj(membership) def user_obj(membership)
{ {
profile_image: ProfileImage.new(membership.user).get(width: 90), profile_image: Images::Profile.call(membership.user.profile_image_url, length: 90),
darker_color: membership.user.decorate.darker_color, darker_color: membership.user.decorate.darker_color,
name: membership.user.name, name: membership.user.name,
last_opened_at: membership.last_opened_at, last_opened_at: membership.last_opened_at,

View file

@ -50,7 +50,7 @@ class ChatChannelMembership < ApplicationRecord
def channel_image def channel_image
if chat_channel.channel_type == "direct" if chat_channel.channel_type == "direct"
ProfileImage.new(other_user).get(width: 90) Images::Profile.call(other_user.profile_image_url, length: 90)
else else
ActionController::Base.helpers.asset_path("organization.svg") ActionController::Base.helpers.asset_path("organization.svg")
end end

View file

@ -109,7 +109,7 @@ class Message < ApplicationRecord
target='_blank' rel='noopener' data-content='sidecar-article'> target='_blank' rel='noopener' data-content='sidecar-article'>
#{"<div class='chatchannels__richlinkmainimage' style='background-image:url(#{cl_path(article.main_image)})' data-content='sidecar-article' ></div>" if article.main_image.present?} #{"<div class='chatchannels__richlinkmainimage' style='background-image:url(#{cl_path(article.main_image)})' data-content='sidecar-article' ></div>" if article.main_image.present?}
<h1 data-content='sidecar-article'>#{article.title}</h1> <h1 data-content='sidecar-article'>#{article.title}</h1>
<h4 data-content='sidecar-article'><img src='#{ProfileImage.new(article.cached_user).get(width: 90)}' /> #{article.cached_user.name}#{article.readable_publish_date || 'Draft Post'}</h4> <h4 data-content='sidecar-article'><img src='#{Images::Profile.call(article.cached_user.profile_image_url, length: 90)}' /> #{article.cached_user.name}#{article.readable_publish_date || 'Draft Post'}</h4>
</a>".html_safe </a>".html_safe
elsif (tag = rich_link_tag(anchor)) elsif (tag = rich_link_tag(anchor))
html += "<a href='/t/#{tag.name}' html += "<a href='/t/#{tag.name}'
@ -125,7 +125,7 @@ class Message < ApplicationRecord
class='chatchannels__richlink' class='chatchannels__richlink'
target='_blank' rel='noopener' data-content='sidecar-user'> target='_blank' rel='noopener' data-content='sidecar-user'>
<h1 data-content='sidecar-user'> <h1 data-content='sidecar-user'>
<img src='#{ProfileImage.new(user).get(width: 90)}' data-content='sidecar-user' class='chatchannels__richlinkprofilepic' /> <img src='#{Images::Profile.call(user.profile_image_url, length: 90)}' data-content='sidecar-user' class='chatchannels__richlinkprofilepic' />
#{user.name} #{user.name}
</h1> </h1>
</a>".html_safe </a>".html_safe

View file

@ -93,7 +93,7 @@ class Organization < ApplicationRecord
end end
def profile_image_90 def profile_image_90
ProfileImage.new(self).get(width: 90) Images::Profile.call(profile_image_url, length: 90)
end end
def enough_credits?(num_credits_needed) def enough_credits?(num_credits_needed)

View file

@ -43,7 +43,7 @@ class Podcast < ApplicationRecord
end end
def image_90 def image_90
ProfileImage.new(self).get(width: 90) Images::Profile.call(profile_image_url, length: 90)
end end
private private

View file

@ -490,7 +490,7 @@ class User < ApplicationRecord
end end
def profile_image_90 def profile_image_90
ProfileImage.new(self).get(width: 90) Images::Profile.call(profile_image_url, length: 90)
end end
def unsubscribe_from_newsletters def unsubscribe_from_newsletters

View file

@ -8,7 +8,7 @@ module Search
:website_url :website_url
attribute :main_image do |pde| attribute :main_image do |pde|
ProfileImage.new(pde.podcast).get(width: 90) Images::Profile.call(pde.podcast.profile_image_url, length: 90)
end end
attribute :slug, &:podcast_slug attribute :slug, &:podcast_slug

View file

@ -3,10 +3,10 @@ module Webhook
attributes :name, :username, :twitter_username, :github_username attributes :name, :username, :twitter_username, :github_username
attribute :website_url, &:processed_website_url attribute :website_url, &:processed_website_url
attribute :profile_image do |user| attribute :profile_image do |user|
ProfileImage.new(user).get(width: 640) Images::Profile.call(user.profile_image_url, length: 640)
end end
attribute :profile_image_90 do |user| attribute :profile_image_90 do |user|
ProfileImage.new(user).get(width: 90) Images::Profile.call(user.profile_image_url, length: 90)
end end
end end
end end

View file

@ -0,0 +1,14 @@
module Images
module Profile
BACKUP_LINK = "https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png".freeze
def self.call(image_url, length: 120)
Optimizer.call(
image_url || BACKUP_LINK,
width: length,
height: length,
crop: "fill",
)
end
end
end

View file

@ -19,7 +19,7 @@
<h5 class="card-title text-center"> <h5 class="card-title text-center">
<% if comment.user %> <% if comment.user %>
<a href="<%= comment.user.path %>" target="_blank" rel="noopener"> <a href="<%= comment.user.path %>" target="_blank" rel="noopener">
<img class="rounded" height="30" src="<%= ProfileImage.new(comment.user).get(width: 50) %>" alt="<%= comment.user.username %> profile" /> <%= comment.user.username %> <img class="rounded" height="30" src="<%= Images::Profile.call(comment.user.profile_image_url, length: 50) %>" alt="<%= comment.user.username %> profile" /> <%= comment.user.username %>
</a> </a>
<% end %> <% end %>
<% if comment.user && comment.user.twitter_username.present? %> <% if comment.user && comment.user.twitter_username.present? %>

View file

@ -13,6 +13,6 @@ json.array! @articles do |article|
json.user do json.user do
json.name article.user.name json.name article.user.name
json.profile_image_url ProfileImage.new(article.user).get(width: 90) json.profile_image_url Images::Profile.call(article.user.profile_image_url, length: 90)
end end
end end

View file

@ -1,4 +1,4 @@
json.name user.name json.name user.name
json.path "/#{user.path.delete_prefix('/')}" json.path "/#{user.path.delete_prefix('/')}"
json.username user.try(:username) || user.name json.username user.try(:username) || user.name
json.profile_image ProfileImage.new(user).get(width: 60) json.profile_image Images::Profile.call(user.profile_image_url, length: 60)

View file

@ -1,8 +1,6 @@
organization_profile_image = ProfileImage.new(organization)
json.organization do json.organization do
json.extract!(organization, :name, :username, :slug) json.extract!(organization, :name, :username, :slug)
json.profile_image organization_profile_image.get(width: 640) json.profile_image Images::Profile.call(organization.profile_image_url, length: 640)
json.profile_image_90 organization_profile_image.get(width: 90) json.profile_image_90 Images::Profile.call(organization.profile_image_url, length: 90)
end end

View file

@ -1,9 +1,7 @@
user_profile_image = ProfileImage.new(user)
json.user do json.user do
json.extract!(user, :name, :username, :twitter_username, :github_username) json.extract!(user, :name, :username, :twitter_username, :github_username)
json.website_url user.processed_website_url json.website_url user.processed_website_url
json.profile_image user_profile_image.get(width: 640) json.profile_image Images::Profile.call(user.profile_image_url, length: 640)
json.profile_image_90 user_profile_image.get(width: 90) json.profile_image_90 Images::Profile.call(user.profile_image_url, length: 90)
end end

View file

@ -13,4 +13,4 @@ json.extract!(
) )
json.joined_at @user.created_at.strftime("%b %e, %Y") json.joined_at @user.created_at.strftime("%b %e, %Y")
json.profile_image ProfileImage.new(@user).get(width: 320) json.profile_image Images::Profile.call(@user.profile_image_url, length: 320)

View file

@ -5,7 +5,7 @@
<div class="flex"> <div class="flex">
<a href="<%= URL.user(@user) %>" class="crayons-avatar crayons-avatar--2xl shrink-0 mr-4"> <a href="<%= URL.user(@user) %>" class="crayons-avatar crayons-avatar--2xl shrink-0 mr-4">
<img class="crayons-avatar__image" src="<%= ProfileImage.new(@user).get(width: 180) %>" alt="<%= @user.username %> profile" /> <img class="crayons-avatar__image" src="<%= Images::Profile.call(@user.profile_image_url, length: 180) %>" alt="<%= @user.username %> profile" />
</a> </a>
<div> <div>
<h3 class="fs-l s:fs-xl m:fs-2xl l:fs-3xl fw-medium"><a href="<%= URL.user(@user) %>" class="crayons-link"><%= @user.name %></a></h3> <h3 class="fs-l s:fs-xl m:fs-2xl l:fs-3xl fw-medium"><a href="<%= URL.user(@user) %>" class="crayons-link"><%= @user.name %></a></h3>

View file

@ -9,7 +9,7 @@
<% end %> <% end %>
<a href='<%= article.user.path %>' class='ltag__link__link'> <a href='<%= article.user.path %>' class='ltag__link__link'>
<div class='ltag__link__pic'> <div class='ltag__link__pic'>
<img src='<%= ProfileImage.new(article.user).get(width: 150) %>' alt='<%= article.user.username + " " + "image" %>'> <img src='<%= Images::Profile.call(article.user.profile_image_url, length: 150) %>' alt='<%= "#{article.user.username} image" %>'>
</div> </div>
</a> </a>
<a href='<%= article.path %>' class='ltag__link__link'> <a href='<%= article.path %>' class='ltag__link__link'>

View file

@ -2,7 +2,7 @@
<div class="flex <% if author == true %>mt-6<% end %>"> <div class="flex <% if author == true %>mt-6<% end %>">
<a href="/<%= organization.slug %>" class="crayons-logo crayons-logo--2xl shrink-0 mr-4"> <a href="/<%= organization.slug %>" class="crayons-logo crayons-logo--2xl shrink-0 mr-4">
<% cache("article-organization-image-#{organization.id}-#{organization.updated_at.rfc3339}", expires_in: 100.hours) do %> <% cache("article-organization-image-#{organization.id}-#{organization.updated_at.rfc3339}", expires_in: 100.hours) do %>
<img src="<%= ProfileImage.new(organization).get %>" alt="<%= organization.name %>" class="crayons-logo__image" /> <img src="<%= Images::Profile.call(organization.profile_image_url) %>" alt="<%= organization.name %>" class="crayons-logo__image" />
<% end %> <% end %>
</a> </a>
<div> <div>

View file

@ -28,7 +28,7 @@
<% end %> <% end %>
<a href="/<%= story.cached_user.username %>" class="crayons-avatar <% if story.cached_organization && !@organization_article_index %> crayons-avatar--s absolute -right-2 -bottom-2 border-solid border-2 border-base-inverted <% else %> crayons-avatar--l <% end %> "> <a href="/<%= story.cached_user.username %>" class="crayons-avatar <% if story.cached_organization && !@organization_article_index %> crayons-avatar--s absolute -right-2 -bottom-2 border-solid border-2 border-base-inverted <% else %> crayons-avatar--l <% end %> ">
<img src="<%= ProfileImage.new(story.cached_user).get(width: 90) %>" alt="<%= story.cached_user.username %> profile" class="crayons-avatar__image" /> <img src="<%= Images::Profile.call(story.cached_user.profile_image_url, length: 90) %>" alt="<%= story.cached_user.username %> profile" class="crayons-avatar__image" />
</a> </a>
</div> </div>
<div> <div>

View file

@ -4,7 +4,7 @@
<div class="-mt-4"> <div class="-mt-4">
<a href="<%= @actor.path %>" class="flex"> <a href="<%= @actor.path %>" class="flex">
<span class="<% if @actor.class.name == "User" %>crayons-avatar crayons-avatar--xl<% elsif @actor.class.name == "Organization" %>crayons-logo crayons-logo--xl<% end %> mr-2 shrink-0"> <span class="<% if @actor.class.name == "User" %>crayons-avatar crayons-avatar--xl<% elsif @actor.class.name == "Organization" %>crayons-logo crayons-logo--xl<% end %> mr-2 shrink-0">
<img src="<%= ProfileImage.new(@actor).get(width: 90) %>" class="<% if @actor.class.name == "User" %>crayons-avatar__image<% elsif @actor.class.name == "Organization" %>crayons-logo__image<% end %>" alt="<%= @actor.name %> profile image"> <img src="<%= Images::Profile.call(@actor.profile_image_url, length: 90) %>" class="<% if @actor.class.name == "User" %>crayons-avatar__image<% elsif @actor.class.name == "Organization" %>crayons-logo__image<% end %>" alt="<%= @actor.name %> profile image">
</span> </span>
<span class="crayons-link fs-l fw-bold mt-5"><%= @actor.name %></span> <span class="crayons-link fs-l fw-bold mt-5"><%= @actor.name %></span>
</a> </a>
@ -72,7 +72,7 @@
<% @sticky_articles.each_with_index do |article, index| %> <% @sticky_articles.each_with_index do |article, index| %>
<a class="crayons-link crayons-link--contentful flex" href="<%= article.path %>"> <a class="crayons-link crayons-link--contentful flex" href="<%= article.path %>">
<span class="crayons-avatar mr-2 shrink-0"> <span class="crayons-avatar mr-2 shrink-0">
<img src="<%= ProfileImage.new(article.user).get(width: 90) %>" class="crayons-avatar__image" loading="lazy" alt="<%= article.user.name %> profile image"> <img src="<%= Images::Profile.call(article.user.profile_image_url, length: 90) %>" class="crayons-avatar__image" loading="lazy" alt="<%= article.user.name %> profile image">
</span> </span>
<div> <div>
<%= article.title %> <%= article.title %>

View file

@ -124,7 +124,7 @@
<% if @organization %> <% if @organization %>
<a href="<%= @organization.path %>" class="flex items-center mb-4 fs-l fw-medium crayons-link"> <a href="<%= @organization.path %>" class="flex items-center mb-4 fs-l fw-medium crayons-link">
<span class="crayons-logo crayons-logo--l mr-3"> <span class="crayons-logo crayons-logo--l mr-3">
<img src="<%= ProfileImage.new(@organization).get(width: 50) %>" class="crayons-logo__image" alt="<%= @organization.name %> profile image"> <img src="<%= Images::Profile.call(@organization.profile_image_url, length: 50) %>" class="crayons-logo__image" alt="<%= @organization.name %> profile image">
</span> </span>
<%= @organization.name %> <%= @organization.name %>
</a> </a>
@ -147,7 +147,7 @@
<div class="crayons-article__subheader"> <div class="crayons-article__subheader">
<a href="/<%= @user.username %>" class="flex items-center mr-4 mb-4 s:mb-0 fw-medium crayons-link"> <a href="/<%= @user.username %>" class="flex items-center mr-4 mb-4 s:mb-0 fw-medium crayons-link">
<span class="crayons-avatar crayons-avatar--l mr-2"><img class="crayons-avatar__image" src="<%= ProfileImage.new(@user).get(width: 50) %>" alt="<%= @user.username %> profile image" /></span> <span class="crayons-avatar crayons-avatar--l mr-2"><img class="crayons-avatar__image" src="<%= Images::Profile.call(@user.profile_image_url, length: 50) %>" alt="<%= @user.username %> profile image" /></span>
<%= @user.name %> <%= @user.name %>
</a> </a>

View file

@ -54,7 +54,7 @@
<% @moderators.each do |user| %> <% @moderators.each do |user| %>
<div class="widget-user-pic"> <div class="widget-user-pic">
<a href="/<%= user.username %>" title="<%= user.username %>"> <a href="/<%= user.username %>" title="<%= user.username %>">
<img src="<%= ProfileImage.new(user).get(width: 90) %>" alt="<%= user.username %> profile image"> <img src="<%= Images::Profile.call(user.profile_image_url, length: 90) %>" alt="<%= user.username %> profile image">
</a> </a>
</div> </div>
<% end %> <% end %>

View file

@ -2,7 +2,7 @@ json.messages @chat_messages.reverse do |message|
json.extract!(message, :id, :user_id, :edited_at) json.extract!(message, :id, :user_id, :edited_at)
json.username message.user.username json.username message.user.username
json.profile_image_url ProfileImage.new(message.user).get(width: 90) json.profile_image_url Images::Profile.call(message.user.profile_image_url, length: 90)
json.message message.message_html json.message message.message_html
json.markdown message.message_markdown json.markdown message.message_markdown
json.timestamp message.created_at json.timestamp message.created_at

View file

@ -12,7 +12,7 @@ json.user do
json.id current_user.id json.id current_user.id
json.username current_user.username json.username current_user.username
json.name current_user.name json.name current_user.name
json.profile_pic ProfileImage.new(current_user).get(width: 50) json.profile_pic Images::Profile.call(current_user.profile_image_url, length: 50)
json.twitter_username current_user.twitter_username json.twitter_username current_user.twitter_username
json.github_username current_user.github_username json.github_username current_user.github_username
end end

View file

@ -26,7 +26,7 @@
<div class="details <%= "low-quality-comment" if decorated_comment.low_quality %>"> <div class="details <%= "low-quality-comment" if decorated_comment.low_quality %>">
<a href="/<%= comment.user.username %>"> <a href="/<%= comment.user.username %>">
<img class="profile-pic" src="<%= ProfileImage.new(comment.user).get(width: 50) %>" alt="<%= comment.user.username %> profile image" /> <img class="profile-pic" src="<%= Images::Profile.call(comment.user.profile_image_url, length: 50) %>" alt="<%= comment.user.username %> profile image" />
<span class="comment-username"> <span class="comment-username">
<span class="comment-username-inner"> <span class="comment-username-inner">
<%= comment.user.name %> <%= comment.user.name %>

View file

@ -1,7 +1,7 @@
<div class="liquid-comment"> <div class="liquid-comment">
<div class="details"> <div class="details">
<a href="/<%= comment.user.username %>"> <a href="/<%= comment.user.username %>">
<img class="profile-pic" src="<%= ProfileImage.new(comment.user).get(width: 50) %>" alt="<%= comment.user.username %> profile image" /> <img class="profile-pic" src="<%= Images::Profile.call(comment.user.profile_image_url, length: 50) %>" alt="<%= comment.user.username %> profile image" />
</a> </a>
<a href="/<%= comment.user.username %>"> <a href="/<%= comment.user.username %>">
<span class="comment-username"><%= comment.user.name %></span> <span class="comment-username"><%= comment.user.name %></span>

View file

@ -23,7 +23,7 @@
<div class="details <%= "low-quality-comment" if decorated_comment.low_quality %>"> <div class="details <%= "low-quality-comment" if decorated_comment.low_quality %>">
<a href="/<%= @user.username %>"> <a href="/<%= @user.username %>">
<img class="profile-pic" src="<%= ProfileImage.new(@user).get(width: 50) %>" alt="<%= @user.username %> profile image" /> <img class="profile-pic" src="<%= Images::Profile.call(@user.profile_image_url, length: 50) %>" alt="<%= @user.username %> profile image" />
<span class="comment-username"> <span class="comment-username">
<span class="comment-username-inner"> <span class="comment-username-inner">
<%= @user.name %> <%= @user.name %>

View file

@ -21,7 +21,7 @@
<% if user %> <% if user %>
<div class="crayons-card p-4 m:p-6 flex s:grid single-article break-word content-center" id="follows-<%= follow.id %>"> <div class="crayons-card p-4 m:p-6 flex s:grid single-article break-word content-center" id="follows-<%= follow.id %>">
<a href="<%= user.path %>" class="crayons-avatar crayons-avatar--2xl s:mb-2 s:mx-auto"> <a href="<%= user.path %>" class="crayons-avatar crayons-avatar--2xl s:mb-2 s:mx-auto">
<img alt="<%= user.username %> profile image" class="crayons-avatar__image" src="<%= ProfileImage.new(user).get(width: 60) %>" /> <img alt="<%= user.username %> profile image" class="crayons-avatar__image" src="<%= Images::Profile.call(user.profile_image_url, length: 60) %>" />
</a> </a>
<div class="pl-4 s:pl-0 self-center"> <div class="pl-4 s:pl-0 self-center">

View file

@ -21,7 +21,7 @@
<% organization = follow.followable %> <% organization = follow.followable %>
<div class="crayons-card p-4 m:p-6 flex s:grid single-article break-word content-center" id="follows-<%= follow.id %>"> <div class="crayons-card p-4 m:p-6 flex s:grid single-article break-word content-center" id="follows-<%= follow.id %>">
<a href="<%= organization.path %>" class="crayons-logo crayons-logo--2xl s:mb-2 s:mx-auto"> <a href="<%= organization.path %>" class="crayons-logo crayons-logo--2xl s:mb-2 s:mx-auto">
<img alt="<%= organization.name %> logo" class="crayons-logo__image" src="<%= ProfileImage.new(organization).get(width: 60) %>" /> <img alt="<%= organization.name %> logo" class="crayons-logo__image" src="<%= Images::Profile.call(organization.profile_image_url, length: 60) %>" />
</a> </a>
<div class="pl-4 s:pl-0 self-center"> <div class="pl-4 s:pl-0 self-center">

View file

@ -22,7 +22,7 @@
<% if user %> <% if user %>
<div class="crayons-card p-4 m:p-6 flex s:grid single-article break-word content-center" id="follows-<%= follow.id %>"> <div class="crayons-card p-4 m:p-6 flex s:grid single-article break-word content-center" id="follows-<%= follow.id %>">
<a href="<%= user.path %>" class="crayons-avatar crayons-avatar--2xl s:mb-2 s:mx-auto"> <a href="<%= user.path %>" class="crayons-avatar crayons-avatar--2xl s:mb-2 s:mx-auto">
<img alt="<%= user.username %> profile image" class="crayons-avatar__image" src="<%= ProfileImage.new(user).get(width: 60) %>" /> <img alt="<%= user.username %> profile image" class="crayons-avatar__image" src="<%= Images::Profile.call(user.profile_image_url, length: 60) %>" />
</a> </a>
<div class="pl-4 s:pl-0 self-center"> <div class="pl-4 s:pl-0 self-center">

View file

@ -3,7 +3,7 @@
<% cache "broadcast-html-#{notification.json_data['broadcast']['title']}" do %> <% cache "broadcast-html-#{notification.json_data['broadcast']['title']}" do %>
<a href="<%= json_data["user"]["path"] %>" class="small-pic-link-wrapper"> <a href="<%= json_data["user"]["path"] %>" class="small-pic-link-wrapper">
<div class="small-pic"> <div class="small-pic">
<img src="<%= ProfileImage.new(user).get %>" alt="link to <%= json_data["user"]["username"] %>'s profile"> <img src="<%= Images::Profile.call(user.profile_image_url) %>" alt="link to <%= json_data["user"]["username"] %>'s profile">
</div> </div>
</a> </a>
<div class="content notification-content broadcast-content" id="<%= sanitized_broadcast_id(json_data["broadcast"]["title"]) %>"> <div class="content notification-content broadcast-content" id="<%= sanitized_broadcast_id(json_data["broadcast"]["title"]) %>">

View file

@ -8,7 +8,7 @@
</style> </style>
<a href="<%= organization.path %>" class="ltag__user__link profile-image-link"> <a href="<%= organization.path %>" class="ltag__user__link profile-image-link">
<div class="ltag__user__pic"> <div class="ltag__user__pic">
<img src="<%= ProfileImage.new(organization).get(width: 150) %>" alt="<%= organization.slug + " image" %>" /> <img src="<%= Images::Profile.call(organization.profile_image_url, length: 150) %>" alt="<%= "#{organization.slug} image" %>" />
</div> </div>
</a> </a>
<div class="ltag__user__content"> <div class="ltag__user__content">

View file

@ -18,7 +18,7 @@
<% @organization.users.find_each do |user| %> <% @organization.users.find_each do |user| %>
<div class="widget-user-pic"> <div class="widget-user-pic">
<a href="/<%= user.username %>"> <a href="/<%= user.username %>">
<img src="<%= ProfileImage.new(user).get(width: 90) %>" alt="<%= user.username %> profile image"> <img src="<%= Images::Profile.call(user.profile_image_url, length: 90) %>" alt="<%= user.username %> profile image">
</a> </a>
</div> </div>
<% end %> <% end %>

View file

@ -1,5 +1,5 @@
<div class="partner-credits-explainer"> <div class="partner-credits-explainer">
<h3><img src="<%= ProfileImage.new(org).get(width: 90) %>" />@<%= org.slug %></h3> <h3><img src="<%= Images::Profile.call(org.profile_image_url, length: 90) %>" />@<%= org.slug %></h3>
<div style="font-size: 0.88em;"><em>This organization account has <%= org.credits.unspent.size %> credits available</em></div> <div style="font-size: 0.88em;"><em>This organization account has <%= org.credits.unspent.size %> credits available</em></div>
<% sponsorships = org.sponsorships.unexpired.where(level: Sponsorship::METAL_LEVELS) %> <% sponsorships = org.sponsorships.unexpired.where(level: Sponsorship::METAL_LEVELS) %>
<% level_sponsorship = sponsorships.where(level: level).take %> <% level_sponsorship = sponsorships.where(level: level).take %>

View file

@ -1,5 +1,5 @@
<h4>What next?</h4> <h4>What next?</h4>
<h3><img src="<%= ProfileImage.new(org).get(width: 90) %>" /> Purchase Credits for @<%= org.slug %></h3> <h3><img src="<%= Images::Profile.call(org.profile_image_url, length: 90) %>" /> Purchase Credits for @<%= org.slug %></h3>
<% if org.credits.unspent.size > 0 %> <% if org.credits.unspent.size > 0 %>
<div style="font-size: 0.88em;"> <div style="font-size: 0.88em;">
<em>This organization account has <%= org.credits.unspent.size %> credits available</em> <em>This organization account has <%= org.credits.unspent.size %> credits available</em>

View file

@ -1,6 +1,6 @@
<div class="partner-credits-explainer"> <div class="partner-credits-explainer">
<% sponsored_tags = org.sponsorships.unexpired.where(level: :tag).includes(:sponsorable).map { |sp| sp.sponsorable.name } %> <% sponsored_tags = org.sponsorships.unexpired.where(level: :tag).includes(:sponsorable).map { |sp| sp.sponsorable.name } %>
<h3><img src="<%= ProfileImage.new(org).get(width: 90) %>" />@<%= org.slug %></h3> <h3><img src="<%= Images::Profile.call(org.profile_image_url, length: 90) %>" />@<%= org.slug %></h3>
<% if org.enough_credits?(Sponsorship::CREDITS[level]) %> <% if org.enough_credits?(Sponsorship::CREDITS[level]) %>
<div style="font-size: 0.88em;"><em>This organization account has <%= org.credits.unspent.size %> credits available</em></div> <div style="font-size: 0.88em;"><em>This organization account has <%= org.credits.unspent.size %> credits available</em></div>
<br /> <br />

View file

@ -127,7 +127,7 @@
<h1 style="font-size:<%= font_size %>vw;"><%= @article.title %></h1> <h1 style="font-size:<%= font_size %>vw;"><%= @article.title %></h1>
</div> </div>
<div class="preview-user"> <div class="preview-user">
<img src="<%= ProfileImage.new(@article.user).get(width: 90) %>" /> <img src="<%= Images::Profile.call(@article.user.profile_image_url, length: 90) %>" />
<%= truncate @article.user.name, length: 28 %>・<%= @article.readable_publish_date %> <%= truncate @article.user.name, length: 28 %>・<%= @article.readable_publish_date %>
</div> </div>
<div class="badge-images"> <div class="badge-images">

View file

@ -117,7 +117,7 @@
<h1 style="font-size:<%= font_size %>vw;"><%= @article.title %></h1> <h1 style="font-size:<%= font_size %>vw;"><%= @article.title %></h1>
</div> </div>
<div class="preview-user"> <div class="preview-user">
<img src="<%= ProfileImage.new(@article.user).get(width: 90) %>" /> <img src="<%= Images::Profile.call(@article.user.profile_image_url, length: 90) %>" />
<%= truncate @article.user.name, length: 28 %>・<%= @article.readable_publish_date %> <%= truncate @article.user.name, length: 28 %>・<%= @article.readable_publish_date %>
</div> </div>
<div class="badge-images"> <div class="badge-images">

View file

@ -120,7 +120,7 @@
<h1 style="font-size:<%= font_size %>vw;"><%= @comment.title %></h1> <h1 style="font-size:<%= font_size %>vw;"><%= @comment.title %></h1>
</div> </div>
<div class="preview-user"> <div class="preview-user">
<img src="<%= ProfileImage.new(@comment.user).get(width: 90) %>" /> <img src="<%= Images::Profile.call(@comment.user.profile_image_url, length: 90) %>" />
<%= truncate @comment.user.name, length: 28 %>・<%= @comment.readable_publish_date %> <%= truncate @comment.user.name, length: 28 %>・<%= @comment.readable_publish_date %>
</div> </div>
<div class="badge-images"> <div class="badge-images">

View file

@ -110,7 +110,7 @@
<% font_size = 4.6 %> <% font_size = 4.6 %>
<% end %> <% end %>
<h1 style="font-size:<%= font_size %>vw;"> <h1 style="font-size:<%= font_size %>vw;">
<img src="<%= ProfileImage.new(@user).get(width: 640) %>" alt="<%= @user.name %> profile image"> <img src="<%= Images::Profile.call(@user.profile_image_url, length: 640) %>" alt="<%= @user.name %> profile image">
<%= truncate @user.name, length: 32 %> <%= truncate @user.name, length: 32 %>
<br /> <br />
<span style="font-size: 0.4em;display: inline-block; margin-left: 5.4em; margin-top: -1.7em">@<%= @user.username %></span> <span style="font-size: 0.4em;display: inline-block; margin-left: 5.4em; margin-top: -1.7em">@<%= @user.username %></span>

View file

@ -9,12 +9,12 @@
<% if user_path.present? %> <% if user_path.present? %>
<a href="<%= user_path %>" class="ltag__user__link profile-image-link"> <a href="<%= user_path %>" class="ltag__user__link profile-image-link">
<div class="ltag__user__pic"> <div class="ltag__user__pic">
<img src="<%= ProfileImage.new(user).get(width: 150) %>" alt="<%= "#{user.username} image" %>" /> <img src="<%= Images::Profile.call(user.profile_image_url, length: 150) %>" alt="<%= "#{user.username} image" %>" />
</div> </div>
</a> </a>
<% else %> <% else %>
<div class="ltag__user__pic"> <div class="ltag__user__pic">
<img src="<%= ProfileImage.new(user).get(width: 150) %>" alt="<%= "#{user.username} image" %>" /> <img src="<%= Images::Profile.call(user.profile_image_url, length: 150) %>" alt="<%= "#{user.username} image" %>" />
</div> </div>
<% end %> <% end %>
<div class="ltag__user__content"> <div class="ltag__user__content">

View file

@ -8,7 +8,7 @@
<% @user.organizations.each do |organization| %> <% @user.organizations.each do |organization| %>
<div class="widget-user-pic"> <div class="widget-user-pic">
<a href="/<%= organization.slug %>"> <a href="/<%= organization.slug %>">
<img src="<%= ProfileImage.new(organization).get(width: 90) %>" alt="<%= organization.name %> profile image"> <img src="<%= Images::Profile.call(organization.profile_image_url, length: 90) %>" alt="<%= organization.name %> profile image">
</a> </a>
</div> </div>
<% end %> <% end %>

View file

@ -42,7 +42,7 @@
<div class="flex items-center"> <div class="flex items-center">
<% if @user.profile_image_url.present? %> <% if @user.profile_image_url.present? %>
<span class="crayons-avatar crayons-avatar--xl mr-2"><img alt="<%= @user.username %> profile image" src="<%= ProfileImage.new(@user).get(width: 50) %>" class="crayons-avatar__image" /></span> <span class="crayons-avatar crayons-avatar--xl mr-2"><img alt="<%= @user.username %> profile image" src="<%= Images::Profile.call(@user.profile_image_url, length: 50) %>" class="crayons-avatar__image" /></span>
<%= f.file_field :profile_image, accept: "image/*", class: "crayons-card crayons-card--secondary p-3 flex items-center flex-1 w-100" %> <%= f.file_field :profile_image, accept: "image/*", class: "crayons-card crayons-card--secondary p-3 flex items-center flex-1 w-100" %>
<% end %> <% end %>
</div> </div>

View file

@ -20,7 +20,7 @@
<a href="<%= user_url(@user) %>"></a> <a href="<%= user_url(@user) %>"></a>
<div class="user-profile-header-container"> <div class="user-profile-header-container">
<div class="profile-pic-wrapper"> <div class="profile-pic-wrapper">
<img class="profile-pic" src="<%= ProfileImage.new(@user).get(width: 320) %>" alt="<%= @user.username %> profile" style="border-color:<%= user_colors(@user)[:bg] %>;background:<%= user_colors(@user)[:bg] %>" /> <img class="profile-pic" src="<%= Images::Profile.call(@user.profile_image_url, length: 320) %>" alt="<%= @user.username %> profile" style="border-color:<%= user_colors(@user)[:bg] %>;background:<%= user_colors(@user)[:bg] %>" />
</div> </div>
<div class="profile-details"> <div class="profile-details">
<h1 style="color:<%= HexComparer.new([user_colors(@user)[:bg], user_colors(@user)[:text]]).brightness(0.78) %>"> <h1 style="color:<%= HexComparer.new([user_colors(@user)[:bg], user_colors(@user)[:text]]).brightness(0.78) %>">

View file

@ -2,6 +2,6 @@ json.array! @users.each do |user|
json.extract!(user, :id, :name, :username) json.extract!(user, :id, :name, :username)
json.summary truncate(user.summary.presence || "Active #{community_name} author", length: 100) json.summary truncate(user.summary.presence || "Active #{community_name} author", length: 100)
json.profile_image_url ProfileImage.new(user).get(width: 90) json.profile_image_url Images::Profile.call(user.profile_image_url, length: 90)
json.following false json.following false
end end

View file

@ -29,7 +29,7 @@
<div class="user-profile-header" style="<%= user_colors_style(@user) %>"> <div class="user-profile-header" style="<%= user_colors_style(@user) %>">
<div class="user-profile-header-container"> <div class="user-profile-header-container">
<div class="profile-pic-wrapper"> <div class="profile-pic-wrapper">
<img class="profile-pic" src="<%= ProfileImage.new(@user).get(width: 320) %>" alt="<%= @user.username %> profile" style="border-color:<%= user_colors(@user)[:bg] %>;background:<%= user_colors(@user)[:bg] %>" /> <img class="profile-pic" src="<%= Images::Profile.call(@user.profile_image_url, length: 320) %>" alt="<%= @user.username %> profile" style="border-color:<%= user_colors(@user)[:bg] %>;background:<%= user_colors(@user)[:bg] %>" />
</div> </div>
<div class="profile-details"> <div class="profile-details">
<h1> <h1>

View file

@ -35,7 +35,7 @@ RSpec.describe LinkTag, type: :liquid_tag do
<div class='ltag__link'> <div class='ltag__link'>
<a href='#{article.user.path}' class='ltag__link__link'> <a href='#{article.user.path}' class='ltag__link__link'>
<div class='ltag__link__pic'> <div class='ltag__link__pic'>
<img src='#{ProfileImage.new(article.user).get(width: 150)}' alt='#{article.user.username} image'> <img src='#{Images::Profile.call(article.user.profile_image_url, length: 150)}' alt='#{article.user.username} image'>
</div> </div>
</a> </a>
<a href='#{article.path}' class='ltag__link__link'> <a href='#{article.path}' class='ltag__link__link'>

View file

@ -42,7 +42,7 @@ RSpec.describe "Api::V0::FollowersController", type: :request do
expect(response_follower["name"]).to eq(follower.name) expect(response_follower["name"]).to eq(follower.name)
expect(response_follower["path"]).to eq(follower.path) expect(response_follower["path"]).to eq(follower.path)
expect(response_follower["username"]).to eq(follower.username) expect(response_follower["username"]).to eq(follower.username)
expect(response_follower["profile_image"]).to eq(ProfileImage.new(follower).get(width: 60)) expect(response_follower["profile_image"]).to eq(Images::Profile.call(follower.profile_image_url, length: 60))
end end
it "supports pagination" do it "supports pagination" do

View file

@ -46,7 +46,7 @@ RSpec.describe "Api::V0::Users", type: :request do
end end
expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y")) expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y"))
expect(response_user["profile_image"]).to eq(ProfileImage.new(user).get(width: 320)) expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 320))
end end
end end
@ -74,7 +74,7 @@ RSpec.describe "Api::V0::Users", type: :request do
end end
expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y")) expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y"))
expect(response_user["profile_image"]).to eq(ProfileImage.new(user).get(width: 320)) expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 320))
end end
it "returns 200 if no authentication and site config is set to private but user is authenticated" do it "returns 200 if no authentication and site config is set to private but user is authenticated" do
@ -92,7 +92,7 @@ RSpec.describe "Api::V0::Users", type: :request do
end end
expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y")) expect(response_user["joined_at"]).to eq(user.created_at.strftime("%b %e, %Y"))
expect(response_user["profile_image"]).to eq(ProfileImage.new(user).get(width: 320)) expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 320))
end end
end end
end end

View file

@ -121,15 +121,18 @@ RSpec.describe "Api::V0::Webhooks", type: :request do
get api_webhook_path(webhook.id) get api_webhook_path(webhook.id)
response_webhook_user = response.parsed_body["user"] response_webhook_user = response.parsed_body["user"]
user_profile_image = ProfileImage.new(webhook.user)
expect(response_webhook_user["name"]).to eq(webhook.user.name) expect(response_webhook_user).to eq({
expect(response_webhook_user["username"]).to eq(webhook.user.username) "name" => webhook.user.name,
expect(response_webhook_user["twitter_username"]).to eq(webhook.user.twitter_username) "username" => webhook.user.username,
expect(response_webhook_user["github_username"]).to eq(webhook.user.github_username) "twitter_username" => webhook.user.twitter_username,
expect(response_webhook_user["website_url"]).to eq(webhook.user.processed_website_url) "github_username" => webhook.user.github_username,
expect(response_webhook_user["profile_image"]).to eq(user_profile_image.get(width: 640)) "website_url" => webhook.user.processed_website_url,
expect(response_webhook_user["profile_image_90"]).to eq(user_profile_image.get(width: 90)) "profile_image" => Images::Profile.call(webhook.user.profile_image_url,
length: 640),
"profile_image_90" => Images::Profile.call(webhook.user.profile_image_url,
length: 90)
})
end end
end end

View file

@ -70,7 +70,7 @@ RSpec.describe "ArticlesShow", type: :request do
"@id" => URL.organization(organization) "@id" => URL.organization(organization)
}, },
"url" => URL.organization(organization), "url" => URL.organization(organization),
"image" => ProfileImage.new(organization).get(width: 320), "image" => Images::Profile.call(organization.profile_image_url, length: 320),
"name" => organization.name, "name" => organization.name,
"description" => organization.summary "description" => organization.summary
}, },

View file

@ -406,7 +406,7 @@ RSpec.describe "ChatChannels", type: :request do
expected_last_opened_at = Time.zone.parse(response_channel_users[user.username]["last_opened_at"]).to_i expected_last_opened_at = Time.zone.parse(response_channel_users[user.username]["last_opened_at"]).to_i
response_user = response_channel_users[user.username] response_user = response_channel_users[user.username]
expect(response_user["profile_image"]).to eq(ProfileImage.new(user).get(width: 90)) expect(response_user["profile_image"]).to eq(Images::Profile.call(user.profile_image_url, length: 90))
expect(response_user["darker_color"]).to eq(user.decorate.darker_color) expect(response_user["darker_color"]).to eq(user.decorate.darker_color)
expect(response_user["name"]).to eq(user.name) expect(response_user["name"]).to eq(user.name)
expect(expected_last_opened_at).to eq(user.chat_channel_memberships.last.last_opened_at.to_i) expect(expected_last_opened_at).to eq(user.chat_channel_memberships.last.last_opened_at.to_i)

View file

@ -35,7 +35,7 @@ RSpec.describe "FollowingsController", type: :request do
expect(response_following["name"]).to eq(followed.name) expect(response_following["name"]).to eq(followed.name)
expect(response_following["path"]).to eq(followed.path) expect(response_following["path"]).to eq(followed.path)
expect(response_following["username"]).to eq(followed.username) expect(response_following["username"]).to eq(followed.username)
expect(response_following["profile_image"]).to eq(ProfileImage.new(followed).get(width: 60)) expect(response_following["profile_image"]).to eq(Images::Profile.call(followed.profile_image_url, length: 60))
end end
end end
end end
@ -111,7 +111,7 @@ RSpec.describe "FollowingsController", type: :request do
expect(response_following["name"]).to eq(followed.name) expect(response_following["name"]).to eq(followed.name)
expect(response_following["path"]).to eq(followed.path) expect(response_following["path"]).to eq(followed.path)
expect(response_following["username"]).to eq(followed.username) expect(response_following["username"]).to eq(followed.username)
expect(response_following["profile_image"]).to eq(ProfileImage.new(followed).get(width: 60)) expect(response_following["profile_image"]).to eq(Images::Profile.call(followed.profile_image_url, length: 60))
end end
end end
end end
@ -148,7 +148,7 @@ RSpec.describe "FollowingsController", type: :request do
expect(response_following["name"]).to eq(followed.name) expect(response_following["name"]).to eq(followed.name)
expect(response_following["path"]).to eq("/#{followed.path}") expect(response_following["path"]).to eq("/#{followed.path}")
expect(response_following["username"]).to eq(followed.name) expect(response_following["username"]).to eq(followed.name)
expect(response_following["profile_image"]).to eq(ProfileImage.new(followed).get(width: 60)) expect(response_following["profile_image"]).to eq(Images::Profile.call(followed.profile_image_url, length: 60))
end end
end end
end end

View file

@ -38,7 +38,7 @@ RSpec.describe "UserShow", type: :request do
user.twitch_username, user.twitch_username,
user.website_url, user.website_url,
], ],
"image" => ProfileImage.new(user).get(width: 320), "image" => Images::Profile.call(user.profile_image_url, length: 320),
"name" => user.name, "name" => user.name,
"email" => user.email, "email" => user.email,
"jobTitle" => user.employment_title, "jobTitle" => user.employment_title,

View file

@ -32,7 +32,7 @@ RSpec.describe "Users", type: :request do
"name" => suggested_user.name, "name" => suggested_user.name,
"username" => suggested_user.username, "username" => suggested_user.username,
"summary" => suggested_user.summary, "summary" => suggested_user.summary,
"profile_image_url" => ProfileImage.new(suggested_user).get(width: 90), "profile_image_url" => Images::Profile.call(suggested_user.profile_image_url, length: 90),
"following" => false, "following" => false,
) )
end end

View file

@ -1,17 +1,17 @@
require "rails_helper" require "rails_helper"
RSpec.describe ProfileImage, type: :labor do RSpec.describe Images::Profile, type: :services do
describe "#get" do describe "#get" do
it "returns user profile_image_url" do it "returns user profile_image_url" do
user = build_stubbed(:user) user = build_stubbed(:user)
expect(described_class.new(user).get).to eq(user.profile_image_url) expect(described_class.call(user.profile_image_url)).to eq(user.profile_image_url)
end end
context "when user has no profile_image" do context "when user has no profile_image" do
it "returns backup image prefixed with Cloudinary" do it "returns backup image prefixed with Cloudinary" do
user = build_stubbed(:user, profile_image: nil) user = build_stubbed(:user, profile_image: nil)
correct_prefix = "/c_fill,f_auto,fl_progressive,h_120,q_auto,w_120/" correct_prefix = "/c_fill,f_auto,fl_progressive,h_120,q_auto,w_120/"
expect(described_class.new(user).get).to include(correct_prefix + described_class::BACKUP_LINK) expect(described_class.call(user.profile_image_url)).to include(correct_prefix + described_class::BACKUP_LINK)
end end
end end
end end