fix tests and typo bugs
This commit is contained in:
@@ -51,39 +51,41 @@ module Downloads
|
||||
}
|
||||
@source, headers = before_download(source, headers)
|
||||
|
||||
Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http|
|
||||
http.read_timeout = 10
|
||||
http.request_get(url.request_uri, headers) do |res|
|
||||
case res
|
||||
when Net::HTTPSuccess then
|
||||
if max_size
|
||||
len = res["Content-Length"]
|
||||
raise Error.new("File is too large (#{len} bytes)") if len && len.to_i > max_size
|
||||
end
|
||||
yield(res)
|
||||
return
|
||||
begin
|
||||
Net::HTTP.start(url.host, url.port, :use_ssl => url.is_a?(URI::HTTPS)) do |http|
|
||||
http.read_timeout = 10
|
||||
http.request_get(url.request_uri, headers) do |res|
|
||||
case res
|
||||
when Net::HTTPSuccess then
|
||||
if max_size
|
||||
len = res["Content-Length"]
|
||||
raise Error.new("File is too large (#{len} bytes)") if len && len.to_i > max_size
|
||||
end
|
||||
yield(res)
|
||||
return
|
||||
|
||||
when Net::HTTPRedirection then
|
||||
if limit == 0 then
|
||||
raise Error.new("Too many redirects")
|
||||
end
|
||||
source = res["location"]
|
||||
limit -= 1
|
||||
when Net::HTTPRedirection then
|
||||
if limit == 0 then
|
||||
raise Error.new("Too many redirects")
|
||||
end
|
||||
source = res["location"]
|
||||
limit -= 1
|
||||
|
||||
else
|
||||
raise Error.new("HTTP error code: #{res.code} #{res.message}")
|
||||
end
|
||||
end # http.request_get
|
||||
end # http.start
|
||||
else
|
||||
raise Error.new("HTTP error code: #{res.code} #{res.message}")
|
||||
end
|
||||
end # http.request_get
|
||||
end # http.start
|
||||
rescue Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EIO, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, IOError => x
|
||||
puts x.inspect
|
||||
@tries += 1
|
||||
if @tries < 3
|
||||
retry
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
end # while
|
||||
|
||||
rescue Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EIO, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, IOError
|
||||
@tries += 1
|
||||
if @tries < 3
|
||||
retry
|
||||
else
|
||||
raise
|
||||
end
|
||||
end # def
|
||||
|
||||
def fix_image_board_sources
|
||||
|
||||
@@ -349,7 +349,9 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def set_per_page
|
||||
self.per_page = Danbooru.config.posts_per_page unless is_privileged?
|
||||
if per_page.nil? || !is_privileged?
|
||||
self.per_page = Danbooru.config.posts_per_page
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -38,12 +38,12 @@ class UserPresenter
|
||||
return "none"
|
||||
end
|
||||
|
||||
deleted_count = Post.for_user(id).deleted.where("created_at >= ?", 1.month.ago).count
|
||||
pending_count = Post.for_user(id).pending.where("created_at >= ?", 3.days.ago).count
|
||||
approved_count = Post.where("is_flagged = false and is_pending = false and is_deleted = false and uploader_id = ? and created_at >= ?", id, 1.month.ago).count
|
||||
deleted_count = Post.for_user(user.id).deleted.where("created_at >= ?", 1.month.ago).count
|
||||
pending_count = Post.for_user(user.id).pending.where("created_at >= ?", 3.days.ago).count
|
||||
approved_count = Post.where("is_flagged = false and is_pending = false and is_deleted = false and uploader_id = ? and created_at >= ?", user.id, 1.month.ago).count
|
||||
|
||||
if base_upload_limit
|
||||
string = "max(base_upload_limit:#{base_upload_limit} - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
||||
if user.base_upload_limit
|
||||
string = "max(base_upload_limit:#{user.base_upload_limit} - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
||||
else
|
||||
string = "max(10 + min(approved_count:#{approved_count} / 2, 30) - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user