expose recommended posts to everyone

This commit is contained in:
r888888888
2018-07-21 23:25:06 -07:00
committed by Albert Yi
parent a669fe361c
commit cc7a66438f
5 changed files with 28 additions and 10 deletions

View File

@@ -28,7 +28,12 @@ class UploadService
if preprocessor.completed?
@upload = preprocessor.finish!
create_post_from_upload(@upload)
begin
create_post_from_upload(@upload)
rescue Exception => x
@upload.update(status: "error: #{x.class} - #{x.message}", backtrace: x.backtrace.join("\n"))
end
return @upload
end
@@ -78,8 +83,6 @@ class UploadService
@post = convert_to_post(upload)
@post.save!
upload.update(status: "error: " + @post.errors.full_messages.join(", "))
if upload.context && upload.context["ugoira"]
PixivUgoiraFrameData.create(
post_id: @post.id,

View File

@@ -18,7 +18,7 @@ class Post < ApplicationRecord
before_validation :parse_pixiv_id
before_validation :blank_out_nonexistent_parents
before_validation :remove_parent_loops
validates_uniqueness_of :md5, :on => :create
validates_uniqueness_of :md5, :on => :create, message: ->(obj, data) { "duplicate: #{Post.find_by_md5(obj.md5).id}"}
validates_inclusion_of :rating, in: %w(s q e), message: "rating must be s, q, or e"
validate :tag_names_are_valid
validate :added_tags_are_valid

View File

@@ -10,7 +10,7 @@ module RecommenderService
def available_for_post?(post)
return true if Rails.env.development?
enabled? && CurrentUser.enable_recommended_posts? && post.created_at > Date.civil(2017, 1, 1) && post.fav_count >= SCORE_THRESHOLD
enabled? && post.created_at > Date.civil(2017, 1, 1) && post.fav_count >= SCORE_THRESHOLD
end
def available_for_user?

View File

@@ -82,7 +82,7 @@
<%= f.input :disable_cropped_thumbnails, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %>
<%= f.input :enable_recommended_posts, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %>
<%#= f.input :enable_recommended_posts, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %>
<div class="input text optional field_with_hint">
<label class="text optional" for="user_dmail_filter_attributes_words">Dmail filter</label>

View File

@@ -343,7 +343,7 @@ class UploadServiceTest < ActiveSupport::TestCase
FactoryBot.create(:user)
end
CurrentUser.ip_addr = "127.0.0.1"
@jpeg = "https://upload.wikimedia.org/wikipedia/commons/c/c5/Moraine_Lake_17092005.jpg"
@jpeg = "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
@ugoira = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364"
@video = "https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4"
end
@@ -362,7 +362,8 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_operator(@upload.file_size, :>, 0)
assert_not_nil(@upload.source)
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :original)))
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :large)))
# this image is not large enough to generate a large file
#assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :large)))
assert(File.exists?(Danbooru.config.storage_manager.file_path(@upload.md5, "jpg", :preview)))
end
@@ -825,7 +826,7 @@ class UploadServiceTest < ActiveSupport::TestCase
subject { UploadService }
setup do
@source = "https://upload.wikimedia.org/wikipedia/commons/c/c5/Moraine_Lake_17092005.jpg"
@source = "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
CurrentUser.user = travel_to(1.month.ago) do
FactoryBot.create(:user)
end
@@ -895,7 +896,7 @@ class UploadServiceTest < ActiveSupport::TestCase
context "with a preprocessed predecessor" do
setup do
@predecessor = FactoryBot.create(:source_upload, status: "preprocessed", source: @source, image_height: 0, image_width: 0, file_size: 1, md5: 'blank', file_ext: "jpg")
@predecessor = FactoryBot.create(:source_upload, status: "preprocessed", source: @source, image_height: 0, image_width: 0, file_size: 1, md5: 'd34e4cf0a437a5d65f8e82b7bcd02606', file_ext: "jpg")
@tags = 'hello world'
end
@@ -906,6 +907,20 @@ class UploadServiceTest < ActiveSupport::TestCase
assert_equal(@predecessor, predecessor)
assert_equal(@tags, predecessor.tag_string.strip)
end
context "when the file has already been uploaded" do
setup do
@post = create(:post, md5: "d34e4cf0a437a5d65f8e82b7bcd02606")
@service = subject.new(source: @source)
end
should "point to the dup post in the upload" do
@upload = subject.new(source: @source, tag_string: @tags).start!
@predecessor.reload
assert_equal("error: ActiveRecord::RecordInvalid - Validation failed: Md5 duplicate: #{@post.id}", @predecessor.status)
end
end
end
context "with no predecessor" do