avatars: add manual expiry function to settings page
This commit is contained in:
parent
8311cb31d2
commit
d42685f4e2
|
@ -1,8 +1,30 @@
|
|||
class AvatarsController < ApplicationController
|
||||
before_action :require_logged_in_user, :only => [ :expire ]
|
||||
|
||||
ALLOWED_SIZES = [ 16, 32, 100, 200 ]
|
||||
|
||||
CACHE_DIR = "#{Rails.root}/public/avatars/"
|
||||
|
||||
def expire
|
||||
expired = 0
|
||||
|
||||
Dir.entries(CACHE_DIR).select{|f|
|
||||
f.match(/\A#{@user.username}-(\d+)\.png\z/)
|
||||
}.each do |f|
|
||||
begin
|
||||
Rails.logger.debug "Expiring #{f}"
|
||||
File.unlink("#{CACHE_DIR}/#{f}")
|
||||
expired += 1
|
||||
rescue => e
|
||||
Rails.logger.error "Failed expiring #{f}: #{e}"
|
||||
end
|
||||
end
|
||||
|
||||
flash[:success] = "Your avatar cache has been purged of #{expired} " <<
|
||||
"file#{expired == 1 ? "" : "s"}"
|
||||
return redirect_to "/settings"
|
||||
end
|
||||
|
||||
def show
|
||||
username, size = params[:username_size].to_s.scan(/\A(.+)-(\d+)\z/).first
|
||||
size = size.to_i
|
||||
|
|
|
@ -43,9 +43,6 @@
|
|||
<div class="boxline">
|
||||
<%= f.label :email, "E-mail Address:", :class => "required" %>
|
||||
<%= f.email_field :email, :size => 40 %>
|
||||
<span class="hint">
|
||||
<a href="http://www.gravatar.com/" target="_blank">Gravatar</a>'ized
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="boxline">
|
||||
|
@ -76,11 +73,23 @@
|
|||
External Accounts
|
||||
</div>
|
||||
|
||||
<div class="boxline">
|
||||
<%= label_tag :gravatar,
|
||||
raw("<a href=\"https://gravatar.com/\">Gravatar</a>:"),
|
||||
:class => "required" %>
|
||||
<span>
|
||||
Your avatar will be cached from the Gravatar icon for your e-mail
|
||||
address above.
|
||||
(<%= link_to "Expire cache", "/avatars/expire", :method => :post %>)
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<% if Pushover.enabled? %>
|
||||
<div class="boxline">
|
||||
<%= label_tag :pushover_user_key,
|
||||
raw("<a href=\"https://pushover.net/\">Pushover</a>:"),
|
||||
:class => "required" %>
|
||||
<span>
|
||||
<%= link_to((@edit_user.pushover_user_key.present??
|
||||
"Manage Pushover Subscription" : "Subscribe With Pushover"),
|
||||
"/settings/pushover_auth", :class => "pushover_button",
|
||||
|
@ -88,12 +97,16 @@
|
|||
<span class="hint">
|
||||
For optional comment and message notifications below
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if Github.enabled? %>
|
||||
<div class="boxline">
|
||||
<%= label_tag :github_username, "GitHub:", :class => "required" %>
|
||||
<span>
|
||||
<%= label_tag :github_username,
|
||||
raw("<a href=\"https://github.com/\">GitHub</a>:"),
|
||||
:class => "required" %>
|
||||
<% if @edit_user.github_username.present? %>
|
||||
Linked to
|
||||
<strong><a href="https://github.com/<%= h(@edit_user.github_username)
|
||||
|
@ -103,12 +116,16 @@
|
|||
<% else %>
|
||||
<a href="/settings/github_auth">Connect</a>
|
||||
<% end %>
|
||||
</span>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if Twitter.enabled? %>
|
||||
<div class="boxline">
|
||||
<%= label_tag :twitter_username, "Twitter:", :class => "required" %>
|
||||
<%= label_tag :twitter_username,
|
||||
raw("<a href=\"https://twitter.com/\">Twitter</a>:"),
|
||||
:class => "required" %>
|
||||
<span>
|
||||
<% if @edit_user.twitter_username.present? %>
|
||||
Linked to
|
||||
<strong><a href="https://twitter.com/<%= h(@edit_user.twitter_username)
|
||||
|
@ -118,6 +135,7 @@
|
|||
<% else %>
|
||||
<a href="/settings/twitter_auth">Connect</a>
|
||||
<% end %>
|
||||
</span>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ Lobsters::Application.routes.draw do
|
|||
get "/u/:username" => "users#show", :as => "user", :format => /html|json/
|
||||
|
||||
get "/avatars/:username_size.png" => "avatars#show"
|
||||
post "/avatars/expire" => "avatars#expire"
|
||||
|
||||
post "/users/:username/ban" => "users#ban", :as => "user_ban"
|
||||
post "/users/:username/unban" => "users#unban", :as => "user_unban"
|
||||
|
|
Loading…
Reference in New Issue