Merge branch 'master' into feat-public-favgroups
This commit is contained in:
@@ -124,6 +124,7 @@
|
||||
var query = Danbooru.RelatedTag.recent_search.query;
|
||||
var related_tags = Danbooru.RelatedTag.recent_search.tags;
|
||||
var wiki_page_tags = Danbooru.RelatedTag.recent_search.wiki_page_tags;
|
||||
var other_wikis = Danbooru.RelatedTag.recent_search.other_wikis;
|
||||
var $dest = $("#related-tags");
|
||||
$dest.empty();
|
||||
|
||||
@@ -134,6 +135,9 @@
|
||||
if (wiki_page_tags.length) {
|
||||
$dest.append(Danbooru.RelatedTag.build_html("wiki:" + query, wiki_page_tags, "wiki"));
|
||||
}
|
||||
$.each(other_wikis, function(i,wiki) {
|
||||
$dest.append(Danbooru.RelatedTag.build_html("wiki:" + wiki.title, wiki.wiki_page_tags, "otherwiki" + i.toString()));
|
||||
});
|
||||
if (Danbooru.RelatedTag.recent_artists) {
|
||||
var tags = [];
|
||||
if (Danbooru.RelatedTag.recent_artists.length === 0) {
|
||||
|
||||
@@ -14,6 +14,13 @@ class PostReplacementsController < ApplicationController
|
||||
respond_with(@post_replacement, location: @post)
|
||||
end
|
||||
|
||||
def update
|
||||
@post_replacement = PostReplacement.find(params[:id])
|
||||
@post_replacement.update(update_params)
|
||||
|
||||
respond_with(@post_replacement)
|
||||
end
|
||||
|
||||
def index
|
||||
params[:search][:post_id] = params.delete(:post_id) if params.has_key?(:post_id)
|
||||
@post_replacements = PostReplacement.search(params[:search]).paginate(params[:page], limit: params[:limit])
|
||||
@@ -25,4 +32,12 @@ private
|
||||
def create_params
|
||||
params.require(:post_replacement).permit(:replacement_url, :replacement_file, :final_source, :tags)
|
||||
end
|
||||
|
||||
def update_params
|
||||
params.require(:post_replacement).permit(
|
||||
:file_ext_was, :file_size_was, :image_width_was, :image_height_was, :md5_was,
|
||||
:file_ext, :file_size, :image_width, :image_height, :md5,
|
||||
:original_url, :replacement_url
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,12 +26,26 @@ class RelatedTagQuery
|
||||
results
|
||||
end
|
||||
|
||||
def other_wiki_category_tags
|
||||
if Tag.category_for(query) != Tag.categories.copyright
|
||||
return []
|
||||
end
|
||||
listtags = (wiki_page.try(:tags) || []).select {|name| name =~ /^list_of_/i }
|
||||
results = listtags.map do |name|
|
||||
listlinks = WikiPage.titled(name).first.try(:tags) || []
|
||||
if listlinks.length > 0
|
||||
{"title" => name, "wiki_page_tags" => map_with_category_data(listlinks)}
|
||||
end
|
||||
end
|
||||
results.reject {|list| list.nil?}
|
||||
end
|
||||
|
||||
def tags_for_html
|
||||
map_with_category_data(tags)
|
||||
end
|
||||
|
||||
def to_json
|
||||
{:query => query, :category => category, :tags => map_with_category_data(tags), :wiki_page_tags => map_with_category_data(wiki_page_tags)}.to_json
|
||||
{:query => query, :category => category, :tags => map_with_category_data(tags), :wiki_page_tags => map_with_category_data(wiki_page_tags), :other_wikis => other_wiki_category_tags}.to_json
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@@ -3,13 +3,19 @@ class PostReplacement < ApplicationRecord
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :creator, class_name: "User"
|
||||
before_validation :initialize_fields
|
||||
before_validation :initialize_fields, on: :create
|
||||
attr_accessor :replacement_file, :final_source, :tags
|
||||
|
||||
def initialize_fields
|
||||
self.creator = CurrentUser.user
|
||||
self.original_url = post.source
|
||||
self.tags = post.tag_string + " " + self.tags.to_s
|
||||
|
||||
self.file_ext_was = post.file_ext
|
||||
self.file_size_was = post.file_size
|
||||
self.image_width_was = post.image_width
|
||||
self.image_height_was = post.image_height
|
||||
self.md5_was = post.md5
|
||||
end
|
||||
|
||||
def undo!
|
||||
@@ -32,9 +38,9 @@ class PostReplacement < ApplicationRecord
|
||||
md5_changed = (upload.md5 != post.md5)
|
||||
|
||||
if replacement_file.present?
|
||||
update(replacement_url: "file://#{replacement_file.original_filename}")
|
||||
self.replacement_url = "file://#{replacement_file.original_filename}"
|
||||
else
|
||||
update(replacement_url: upload.downloaded_source)
|
||||
self.replacement_url = upload.downloaded_source
|
||||
end
|
||||
|
||||
# queue the deletion *before* updating the post so that we use the old
|
||||
@@ -44,6 +50,12 @@ class PostReplacement < ApplicationRecord
|
||||
Post.delay(queue: "default", run_at: Time.now + DELETION_GRACE_PERIOD).delete_files(post.id, post.file_path, post.large_file_path, post.preview_file_path)
|
||||
end
|
||||
|
||||
self.file_ext = upload.file_ext
|
||||
self.file_size = upload.file_size
|
||||
self.image_height = upload.image_height
|
||||
self.image_width = upload.image_width
|
||||
self.md5 = upload.md5
|
||||
|
||||
post.md5 = upload.md5
|
||||
post.file_ext = upload.file_ext
|
||||
post.image_width = upload.image_width
|
||||
@@ -51,6 +63,7 @@ class PostReplacement < ApplicationRecord
|
||||
post.file_size = upload.file_size
|
||||
post.source = final_source.presence || upload.source
|
||||
post.tag_string = upload.tag_string
|
||||
|
||||
rescale_notes
|
||||
update_ugoira_frame_data(upload)
|
||||
|
||||
@@ -60,6 +73,7 @@ class PostReplacement < ApplicationRecord
|
||||
post.queue_backup
|
||||
end
|
||||
|
||||
save!
|
||||
post.save!
|
||||
end
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
<tr>
|
||||
<th width="1%">Post</th>
|
||||
<th>Source</th>
|
||||
<th>MD5</th>
|
||||
<th>Size</th>
|
||||
<th>Replacer</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -36,6 +38,37 @@
|
||||
</dd>
|
||||
</dl>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<% if post_replacement.md5_was.present? && post_replacement.md5.present? %>
|
||||
<dl>
|
||||
<dt>Original MD5</dt>
|
||||
<dd><%= post_replacement.md5_was %></dd>
|
||||
|
||||
<dt>Replacement MD5</dt>
|
||||
<dd><%= post_replacement.md5 %></dd>
|
||||
</dl>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<% if %i[image_width_was image_height_was file_size_was file_ext_was image_width image_height file_size file_ext].all? { |k| post_replacement[k].present? } %>
|
||||
<dl>
|
||||
<dt>Original Size</dt>
|
||||
<dd>
|
||||
<%= post_replacement.image_width_was %>x<%= post_replacement.image_height_was %>
|
||||
(<%= post_replacement.file_size_was.to_s(:human_size, precision: 4) %>, <%= post_replacement.file_ext_was %>)
|
||||
</dd>
|
||||
|
||||
<dt>Replacement Size</dt>
|
||||
<dd>
|
||||
<%= post_replacement.image_width %>x<%= post_replacement.image_height %>
|
||||
(<%= post_replacement.file_size.to_s(:human_size, precision: 4) %>, <%= post_replacement.file_ext %>)
|
||||
</dd>
|
||||
</dl>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<%= compact_time post_replacement.created_at %>
|
||||
<br> by <%= link_to_user post_replacement.creator %>
|
||||
|
||||
@@ -195,7 +195,7 @@ Rails.application.routes.draw do
|
||||
get :diff
|
||||
end
|
||||
end
|
||||
resources :post_replacements, :only => [:index, :new, :create]
|
||||
resources :post_replacements, :only => [:index, :new, :create, :update]
|
||||
resources :posts do
|
||||
resources :events, :only => [:index], :controller => "post_events"
|
||||
resources :replacements, :only => [:index, :new, :create], :controller => "post_replacements"
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
class AddMetadataToPostReplacements < ActiveRecord::Migration
|
||||
def change
|
||||
PostReplacement.without_timeout do
|
||||
add_column :post_replacements, :file_ext_was, :string
|
||||
add_column :post_replacements, :file_size_was, :integer
|
||||
add_column :post_replacements, :image_width_was, :integer
|
||||
add_column :post_replacements, :image_height_was, :integer
|
||||
add_column :post_replacements, :md5_was, :string
|
||||
|
||||
add_column :post_replacements, :file_ext, :string
|
||||
add_column :post_replacements, :file_size, :integer
|
||||
add_column :post_replacements, :image_width, :integer
|
||||
add_column :post_replacements, :image_height, :integer
|
||||
add_column :post_replacements, :md5, :string
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2667,7 +2667,17 @@ CREATE TABLE post_replacements (
|
||||
original_url text NOT NULL,
|
||||
replacement_url text NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
file_ext_was character varying,
|
||||
file_size_was integer,
|
||||
image_width_was integer,
|
||||
image_height_was integer,
|
||||
md5_was character varying,
|
||||
file_ext character varying,
|
||||
file_size integer,
|
||||
image_width integer,
|
||||
image_height integer,
|
||||
md5 character varying
|
||||
);
|
||||
|
||||
|
||||
@@ -7533,3 +7543,5 @@ INSERT INTO schema_migrations (version) VALUES ('20171127195124');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20171219001521');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20171218213037');
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
require 'danbooru_image_resizer/danbooru_image_resizer'
|
||||
|
||||
namespace :images do
|
||||
desc "Reset S3 + Storage Class"
|
||||
task :reset_s3, [:min_id, :max_id] => :environment do |t, args|
|
||||
@@ -117,7 +115,7 @@ namespace :images do
|
||||
Post.where(id: post_id).find_each do |post|
|
||||
if post.is_image?
|
||||
puts "resizing preview #{post.id}"
|
||||
Danbooru.resize(post.file_path, post.preview_file_path, width, width, 90)
|
||||
DanbooruImageResizer.resize(post.file_path, post.preview_file_path, width, width, 90)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -133,7 +131,7 @@ namespace :images do
|
||||
Post.where(id: post_id).find_each do |post|
|
||||
if post.is_image? && post.has_large?
|
||||
puts "resizing large #{post.id}"
|
||||
Danbooru.resize(post.file_path, post.large_file_path, Danbooru.config.large_image_width, nil, 90)
|
||||
DanbooruImageResizer.resize(post.file_path, post.large_file_path, Danbooru.config.large_image_width, nil, 90)
|
||||
post.distribute_files
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,6 +43,25 @@ class PostReplacementsControllerTest < ActionController::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
should "update the replacement" do
|
||||
params = {
|
||||
format: :json,
|
||||
id: @post_replacement.id,
|
||||
post_replacement: {
|
||||
file_size_was: 23,
|
||||
file_size: 42,
|
||||
}
|
||||
}
|
||||
|
||||
put :update, params, { user_id: @user.id }
|
||||
@post_replacement.reload
|
||||
|
||||
assert_equal(23, @post_replacement.file_size_was)
|
||||
assert_equal(42, @post_replacement.file_size)
|
||||
end
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
should "render" do
|
||||
get :index, {format: :json}
|
||||
|
||||
@@ -30,7 +30,7 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
Delayed::Worker.delay_jobs = false
|
||||
@@ -49,6 +49,7 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@post.update(source: "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png")
|
||||
@post.replace!(replacement_url: "https://www.google.com/intl/en_ALL/images/logo.gif", tags: "-tag1 tag2")
|
||||
@replacement = @post.replacements.last
|
||||
@upload = Upload.last
|
||||
end
|
||||
|
||||
@@ -79,6 +80,22 @@ class PostReplacementTest < ActiveSupport::TestCase
|
||||
assert_equal(@post.id, PostReplacement.last.post_id)
|
||||
end
|
||||
|
||||
should "record the old file metadata" do
|
||||
assert_equal(500, @replacement.image_width_was)
|
||||
assert_equal(335, @replacement.image_height_was)
|
||||
assert_equal(28086, @replacement.file_size_was)
|
||||
assert_equal("jpg", @replacement.file_ext_was)
|
||||
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", @replacement.md5_was)
|
||||
end
|
||||
|
||||
should "record the new file metadata" do
|
||||
assert_equal(276, @replacement.image_width)
|
||||
assert_equal(110, @replacement.image_height)
|
||||
assert_equal(8558, @replacement.file_size)
|
||||
assert_equal("gif", @replacement.file_ext)
|
||||
assert_equal("e80d1c59a673f560785784fb1ac10959", @replacement.md5)
|
||||
end
|
||||
|
||||
should "correctly update the attributes" do
|
||||
assert_equal(@post.id, @upload.post.id)
|
||||
assert_equal("completed", @upload.status)
|
||||
|
||||
@@ -2,11 +2,29 @@ require 'test_helper'
|
||||
|
||||
class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
User.any_instance.stubs(:validate_sock_puppets).returns(true)
|
||||
user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
context "#other_wiki_category_tags" do
|
||||
subject { RelatedTagQuery.new("copyright") }
|
||||
|
||||
setup do
|
||||
@copyright = FactoryGirl.create(:copyright_tag, name: "copyright")
|
||||
@wiki = FactoryGirl.create(:wiki_page, title: "copyright", body: "[[list_of_hoges]]")
|
||||
@list_of_hoges = FactoryGirl.create(:wiki_page, title: "list_of_hoges", body: "[[alpha]] and [[beta]]")
|
||||
end
|
||||
|
||||
should "return tags from the associated list wiki" do
|
||||
result = subject.other_wiki_category_tags
|
||||
assert_not_nil(result[0])
|
||||
assert_not_nil(result[0]["wiki_page_tags"])
|
||||
assert_equal(%w(alpha beta), result[0]["wiki_page_tags"].map(&:first))
|
||||
end
|
||||
end
|
||||
|
||||
context "a related tag query without a category constraint" do
|
||||
setup do
|
||||
@post_1 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
@@ -24,7 +42,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "render the json" do
|
||||
assert_equal("{\"query\":\"aaa\",\"category\":\"\",\"tags\":[[\"aaa\",0],[\"bbb\",0],[\"ccc\",0]],\"wiki_page_tags\":[]}", @query.to_json)
|
||||
assert_equal("{\"query\":\"aaa\",\"category\":\"\",\"tags\":[[\"aaa\",0],[\"bbb\",0],[\"ccc\",0]],\"wiki_page_tags\":[],\"other_wikis\":[]}", @query.to_json)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user