changes
This commit is contained in:
@@ -1,4 +1,19 @@
|
||||
class CurrentUser
|
||||
def self.scoped(user, ip_addr)
|
||||
old_user = self.user
|
||||
old_ip_addr = self.ip_addr
|
||||
|
||||
self.user = user
|
||||
self.ip_addr = ip_addr
|
||||
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
self.user = old_user
|
||||
self.ip_addr = old_ip_addr
|
||||
end
|
||||
end
|
||||
|
||||
def self.user=(user)
|
||||
Thread.current[:current_user] = user
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ class Download
|
||||
@source = source
|
||||
@file_path = file_path
|
||||
end
|
||||
|
||||
|
||||
# Downloads to @file_path
|
||||
def download!
|
||||
http_get_streaming(@source) do |response|
|
||||
@@ -18,8 +18,8 @@ class Download
|
||||
end
|
||||
@source = fix_image_board_sources(@source)
|
||||
end
|
||||
|
||||
# private
|
||||
|
||||
# private
|
||||
def handle_pixiv(source, headers)
|
||||
if source =~ /pixiv\.net/
|
||||
headers["Referer"] = "http://www.pixiv.net"
|
||||
@@ -33,7 +33,7 @@ class Download
|
||||
|
||||
source
|
||||
end
|
||||
|
||||
|
||||
def http_get_streaming(source, options = {})
|
||||
max_size = options[:max_size] || Danbooru.config.max_file_size
|
||||
max_size = nil if max_size == 0 # unlimited
|
||||
@@ -77,7 +77,7 @@ class Download
|
||||
end # http.start
|
||||
end # while
|
||||
end # def
|
||||
|
||||
|
||||
def fix_image_board_sources(source)
|
||||
if source =~ /\/src\/\d{12,}|urnc\.yi\.org|yui\.cynthia\.bne\.jp/
|
||||
"Image board"
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
class PostSet
|
||||
class Error < Exception ; end
|
||||
|
||||
attr_accessor :tags, :page, :current_user, :before_id, :errors, :count
|
||||
attr_accessor :tags, :page, :before_id, :errors, :count
|
||||
attr_accessor :wiki_page, :artist, :posts, :suggestions
|
||||
|
||||
def initialize(tags, page, current_user, before_id = nil)
|
||||
def initialize(tags, page, before_id = nil)
|
||||
@tags = Tag.normalize(tags)
|
||||
@page = page.to_i
|
||||
@current_user = current_user
|
||||
@before_id = before_id
|
||||
@errors = []
|
||||
load_associations
|
||||
@@ -60,16 +59,14 @@ class PostSet
|
||||
end
|
||||
|
||||
def tag_array
|
||||
@tag_arary ||= Tag.scan_query(tags)
|
||||
@tag_array ||= Tag.scan_query(tags)
|
||||
end
|
||||
|
||||
def validate
|
||||
begin
|
||||
validate_page
|
||||
validate_query_count
|
||||
rescue Error => x
|
||||
@errors << x.to_s
|
||||
end
|
||||
validate_page
|
||||
validate_query_count
|
||||
rescue Error => x
|
||||
@errors << x.to_s
|
||||
end
|
||||
|
||||
def validate_page
|
||||
@@ -79,7 +76,7 @@ class PostSet
|
||||
end
|
||||
|
||||
def validate_query_count
|
||||
if !current_user.is_privileged? && tag_array.size > 2
|
||||
if !CurrentUser.user.is_privileged? && tag_array.size > 2
|
||||
raise Error.new("You can only search up to two tags at once with a basic account")
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user