Skip to content
Permalink
Browse files

Merge pull request #65 from r888888888/master

Merging
  • Loading branch information...
Iratu committed Apr 19, 2019
2 parents 01e40dd + 06045ac commit 4eae3eb8b227539e9cb437b79fce69c5dcc3d876
@@ -52,6 +52,7 @@ gem 'jquery-rails'
gem 'webpacker', '>= 4.0.x'
gem 'retriable'
gem 'redis'
gem 'request_store'

# needed for looser jpeg header compat
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
@@ -319,6 +319,8 @@ GEM
ref (2.0.0)
representable (2.3.0)
uber (~> 0.0.7)
request_store (1.4.1)
rack (>= 1.4)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
@@ -492,6 +494,7 @@ DEPENDENCIES
rakismet
recaptcha
redis
request_store
responders
retriable
ruby-imagespec!
@@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
before_action :api_check
before_action :set_safe_mode
before_action :set_variant
before_action :track_only_param
# before_action :secure_cookies_check
layout "default"
helper_method :show_moderation_notice?
@@ -49,6 +50,12 @@ def bad_db_connection
end
end

def track_only_param
if params[:only]
RequestStore[:only_param] = params[:only].split(/,/)
end
end

def api_check
if !CurrentUser.is_anonymous? && !request.get? && !request.head?
if CurrentUser.user.token_bucket.nil?
@@ -7,7 +7,7 @@ def index
@post_versions = PostArchive.includes(:updater, post: [:versions]).search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
respond_with(@post_versions) do |format|
format.xml do
render :xml => @post_versions.to_xml(:root => "post-versions")
render xml: @post_versions.to_xml(root: "post-versions")
end
end
end
@@ -14,7 +14,7 @@ def index
respond_with(@posts) do |format|
format.atom
format.xml do
render :xml => @posts.to_xml(:root => "posts")
render xml: @posts.to_xml(root: "posts")
end
end
end
@@ -61,19 +61,13 @@ def print_name(job)
when "BulkRevert#process"
"<strong>bulk revert</strong>"

when "PostKeeperManager.check_and_update"
"<strong>update top tagger</strong>"

else
h(job.name)
end
end

def print_handler(job)
case job.name
when "PostKeeperManager.check_and_assign"
""

when "Tag.increment_post_counts", "Tag.decrement_post_counts"
""

@@ -130,9 +124,6 @@ def print_handler(job)

when "BulkRevert#process"
h(job.payload_object.args.join(" "))

when "PostKeeperManager.check_and_update"
h(job.payload_object.args[0])
end
end
end
@@ -156,7 +156,6 @@ Blacklist.post_match = function(post, entry) {
tags.push("user:" + $post.attr("data-uploader").toLowerCase());
}
tags.push("uploaderid:" + $post.attr("data-uploader-id"));
tags.push("toptaggerid:" + $post.attr("data-top-tagger"));
$.each(String($post.data("flags")).match(/\S+/g) || [], function(i, v) {
tags.push("status:" + v);
});
@@ -84,15 +84,19 @@ def image_urls
# work is downloadable
elsif api_deviation[:is_downloadable]
src = api_download[:src]
src.gsub!(%r!\Ahttps?://s3\.amazonaws\.com/!i, "https://")
src.gsub!(/\?.*\z/, "") # strip s3 query params
src.gsub!(%r!\Ahttps://origin-orig\.deviantart\.net!, "http://origin-orig.deviantart.net") # https://origin-orig.devianart.net doesn't work
src.sub!(%r!\Ahttps?://s3\.amazonaws\.com/!i, "https://")
src.sub!(/\?.*\z/, "") # strip s3 query params
src.sub!(%r!\Ahttps://origin-orig\.deviantart\.net!, "http://origin-orig.deviantart.net") # https://origin-orig.devianart.net doesn't work
[src]
# work isn't downloadable, or download size is same as regular size.
elsif api_deviation.present?
src = api_deviation.dig(:content, :src)
src = src.gsub(%r!\Ahttps?://orig\d+\.deviantart\.net!i, "http://origin-orig.deviantart.net")
src = src.gsub(%r!/v1/(fit|fill)/.*\z!i, "")
if deviation_id && deviation_id.to_i <= 790677560 && src =~ /^https:\/\/images-wixmp-/
src = src.sub(%r!(/f/[a-f0-9-]+/[a-f0-9-]+)!, '/intermediary\1')
src = src.sub(%r!/v1/(fit|fill)/.*\z!i, "")
end
src = src.sub(%r!\Ahttps?://orig\d+\.deviantart\.net!i, "http://origin-orig.deviantart.net")
src = src.sub(%r!q_\d+!, "q_100")
[src]
else
raise "Couldn't find image url" # this should never happen
@@ -149,24 +149,55 @@ module ApiMethods

def as_json(options = {})
options ||= {}

options[:include] ||= []

options[:except] ||= []
options[:except] += hidden_attributes

options[:methods] ||= []
options[:methods] += method_attributes

if !options.key?(:only) && RequestStore.exist?(:only_param)
options[:only] = RequestStore[:only_param]
end

if options[:only].is_a?(String)
options[:only] = options[:only].split(/,/)
end

if options[:only]
options[:methods] = options[:methods] & options[:only].map(&:to_sym)
options[:include] = options[:include] & options[:only].map(&:to_sym)
end

super(options)
end

def to_xml(options = {}, &block)
options ||= {}

options[:include] ||= []

options[:except] ||= []
options[:except] += hidden_attributes

options[:methods] ||= []
options[:methods] += method_attributes

if !options.key?(:only) && RequestStore.exist?(:only_param)
options[:only] = RequestStore[:only_param]
end

if options[:only].is_a?(String)
options[:only] = options[:only].split(/,/)
end

if options[:only]
options[:methods] = options[:methods] & options[:only]
options[:include] = options[:include] & options[:only]
end

super(options, &block)
end

@@ -84,7 +84,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest

context "for a twitter post" do
setup do
@source = "https://twitter.com/frappuccino/status/566030116182949888"
@source = "https://twitter.com/onsen_musume_jp/status/865534101918330881"
end

should "render" do
@@ -38,7 +38,7 @@ def setup
should "get the image url" do
@site = Sources::Strategies.find("https://noizave.deviantart.com/art/test-no-download-697415967")

assert_equal(["https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dbj81lr-3306feb1-87dc-4d25-9a4c-da8d2973a8b7.jpg"], @site.image_urls)
assert_match(%r!^https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dbj81lr-3306feb1-87dc-4d25-9a4c-da8d2973a8b7.jpg!, @site.image_urls[0])
assert_equal("https://www.deviantart.com/noizave/art/test-no-download-697415967", @site.canonical_url)
end
end
@@ -162,7 +162,7 @@ def setup
should "work" do
@site = Sources::Strategies.find(@url, @ref)

assert_equal("https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg", @site.image_url)
assert_match(%r!^https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg!, @site.image_url)
assert_equal("edsfox", @site.artist_name)
assert_equal("https://www.deviantart.com/edsfox", @site.profile_url)
assert_equal("https://www.deviantart.com/edsfox/art/Silverhawks-Quicksilver-126872896", @site.page_url)
@@ -173,18 +173,18 @@ def setup
end
end

context "The source for a images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com sample image" do
context "The source for a images-wixmp-.* sample image" do
setup do
@url = "https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg/v1/fill/w_786,h_1017,q_70,strp/silverhawks_quicksilver_by_edsfox_d23jbr4-pre.jpg"
@ref = "https://www.deviantart.com/edsfox/art/Silverhawks-Quicksilver-126872896"
@artist = FactoryBot.create(:artist, name: "edsfox", url_string: "https://edsfox.deviantart.com")
end

context "without a referer" do
context "with a referer" do
should "work" do
@site = Sources::Strategies.find(@url, @ref)

assert_equal("https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg", @site.image_url)
assert_match(%r!^https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg!, @site.image_url)
assert_equal("edsfox", @site.artist_name)
assert_equal("https://www.deviantart.com/edsfox", @site.profile_url)
assert_equal("https://www.deviantart.com/edsfox/art/Silverhawks-Quicksilver-126872896", @site.page_url)

0 comments on commit 4eae3eb

Please sign in to comment.
You can’t perform that action at this time.