This commit is contained in:
Toks
2015-05-23 12:14:03 -04:00
18 changed files with 125 additions and 59 deletions

View File

@@ -1,23 +1,23 @@
=== Installation ### Installation
It is recommended that you install Danbooru on a Debian-based system It is recommended that you install Danbooru on a Debian-based system
since most of the required packages are available on APT. Danbooru since most of the required packages are available on APT. Danbooru
has been successfully installed on Fedora, CentOS, FreeBSD, and OS X. has been successfully installed on Fedora, CentOS, FreeBSD, and OS X.
The INSTALL.debian install script is straightforward and should be The INSTALL.debian install script is straightforward and should be
simple to adapt for other platforms. If you want something similar to simple to adapt for other platforms.
Danbooru that is easier to install, try Shimmie
(http://code.shishnet.org/shimmie2/). Shimmie uses PHP and MySQL and
should be straightforward to install on most hosts.
For best performance, you will need at least 256MB of RAM for For best performance, you will need at least 256MB of RAM for
PostgreSQL and Rails. The memory requirement will grow as your PostgreSQL and Rails. The memory requirement will grow as your
database gets bigger. database gets bigger.
On production Danbooru uses PostgreSQL 9.4, but any 9.x release should
work.
Use your operating system's package management system whenever Use your operating system's package management system whenever
possible. This will simplify the process of installing init scripts, possible. This will simplify the process of installing init scripts,
which will not always happen when compiling from source. which will not always happen when compiling from source.
=== Troubleshooting ### Troubleshooting
These instructions won't work for everyone. If your setup is not These instructions won't work for everyone. If your setup is not
working, here are the steps I usually recommend to people: working, here are the steps I usually recommend to people:
@@ -37,7 +37,7 @@ debug your Nginx configuration file.
4) Check all log files. 4) Check all log files.
=== IQDB Integration ### IQDB Integration
In order to enable IQDB integration, you must compile and run the IQDB server somewhere (preferably on the local server). There are two Danbooru configuration settings that you must then set: iqdb_hostname_and_port and iqdb_file. In order to enable IQDB integration, you must compile and run the IQDB server somewhere (preferably on the local server). There are two Danbooru configuration settings that you must then set: iqdb_hostname_and_port and iqdb_file.

View File

@@ -46,7 +46,11 @@
Danbooru.Upload.initialize_info_bookmarklet = function() { Danbooru.Upload.initialize_info_bookmarklet = function() {
$("#source-info ul").hide(); $("#source-info ul").hide();
$("#fetch-data-bookmarklet").click(function(e) { $("#fetch-data-bookmarklet").click(function(e) {
$.get(e.target.href).success(Danbooru.Upload.fill_source_info); var xhr = $.get(e.target.href);
xhr.success(Danbooru.Upload.fill_source_info);
xhr.fail(function(data) {
$("#source-info span#loading-data").html("Error: " + data.responseJSON["message"])
});
e.preventDefault(); e.preventDefault();
}); });
$("#fetch-data-bookmarklet").trigger("click"); $("#fetch-data-bookmarklet").trigger("click");
@@ -63,7 +67,11 @@
Danbooru.error("Error: Source is not a URL"); Danbooru.error("Error: Source is not a URL");
} else { } else {
$("#source-info span#loading-data").show(); $("#source-info span#loading-data").show();
$.get("/source.json?url=" + encodeURIComponent(source)).success(Danbooru.Upload.fill_source_info); var xhr = $.get("/source.json?url=" + encodeURIComponent(source));
xhr.success(Danbooru.Upload.fill_source_info);
xhr.fail(function(data) {
$("#source-info span#loading-data").html("Error: " + data.responseJSON["message"])
});
} }
e.preventDefault(); e.preventDefault();
}); });

View File

@@ -12,4 +12,14 @@ class SourcesController < ApplicationController
end end
end end
end end
private
def rescue_exception(exception)
respond_with do |format|
format.json do
render :json => {:message => exception.to_s}, :status => :error
end
end
end
end end

View File

@@ -20,6 +20,7 @@ class Post < ActiveRecord::Base
before_save :update_tag_post_counts before_save :update_tag_post_counts
before_save :set_tag_counts before_save :set_tag_counts
before_save :set_pool_category_pseudo_tags before_save :set_pool_category_pseudo_tags
before_create :autoban
before_validation :strip_source before_validation :strip_source
before_validation :initialize_uploader, :on => :create before_validation :initialize_uploader, :on => :create
before_validation :parse_pixiv_id before_validation :parse_pixiv_id
@@ -290,6 +291,12 @@ class Post < ActiveRecord::Base
def disapproved_by?(user) def disapproved_by?(user)
PostDisapproval.where(:user_id => user.id, :post_id => id).exists? PostDisapproval.where(:user_id => user.id, :post_id => id).exists?
end end
def autoban
if has_tag?("banned_artist")
self.is_banned = true
end
end
end end
module PresenterMethods module PresenterMethods
@@ -1490,7 +1497,13 @@ class Post < ActiveRecord::Base
def update_iqdb_async def update_iqdb_async
if Danbooru.config.iqdb_hostname_and_port && File.exists?(preview_file_path) if Danbooru.config.iqdb_hostname_and_port && File.exists?(preview_file_path)
Danbooru.config.all_server_hosts.each do |host| Danbooru.config.all_server_hosts.each do |host|
delay(:queue => host).update_iqdb if has_tag?("ugoira")
run_at = 10.seconds.from_now
else
run_at = Time.from_now
end
delay(:queue => host, :run_at => run_at).update_iqdb
end end
end end
end end
@@ -1558,6 +1571,7 @@ class Post < ActiveRecord::Base
def reload(options = nil) def reload(options = nil)
super super
reset_tag_array_cache reset_tag_array_cache
@pools = nil
@tag_categories = nil @tag_categories = nil
@typed_tags = nil @typed_tags = nil
self self

View File

@@ -192,6 +192,11 @@ class Tag < ActiveRecord::Base
if category if category
category_id = categories.value_for(category) category_id = categories.value_for(category)
# in case a category change hasn't propagated to this server yet,
# force an update the local cache. This may get overwritten in the
# next few lines if the category is changed.
tag.update_category_cache
if category_id != tag.category && !tag.is_locked? && (CurrentUser.is_builder? || tag.post_count <= 50) if category_id != tag.category && !tag.is_locked? && (CurrentUser.is_builder? || tag.post_count <= 50)
tag.update_column(:category, category_id) tag.update_column(:category, category_id)
tag.update_category_cache_for_all tag.update_category_cache_for_all

View File

@@ -198,11 +198,15 @@ class TagAlias < ActiveRecord::Base
def rename_wiki_and_artist def rename_wiki_and_artist
antecedent_wiki = WikiPage.titled(antecedent_name).first antecedent_wiki = WikiPage.titled(antecedent_name).first
if antecedent_wiki.present? && WikiPage.titled(consequent_name).blank? if antecedent_wiki.present?
CurrentUser.scoped(creator, creator_ip_addr) do if WikiPage.titled(consequent_name).blank?
antecedent_wiki.update_attributes( CurrentUser.scoped(creator, creator_ip_addr) do
:title => consequent_name antecedent_wiki.update_attributes(
) :title => consequent_name
)
end
else
update_forum_topic_for_wiki_conflict
end end
end end
@@ -249,6 +253,16 @@ class TagAlias < ActiveRecord::Base
end end
end end
def update_forum_topic_for_wiki_conflict
if forum_topic
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
forum_topic.posts.create(
:body => "The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] has conflicting wiki pages. [[#{consequent_name}]] should be updated to include information from [[#{antecedent_name}]] if necessary."
)
end
end
end
def reject! def reject!
update_column(:status, "deleted") update_column(:status, "deleted")
clear_all_cache clear_all_cache

View File

@@ -149,7 +149,7 @@
<meta name="always-resize-images" content="<%= CurrentUser.user.always_resize_images? %>"> <meta name="always-resize-images" content="<%= CurrentUser.user.always_resize_images? %>">
<meta property="og:title" content="<%= @post.presenter.humanized_essential_tag_string %> - <%= Danbooru.config.app_name %>"> <meta property="og:title" content="<%= @post.presenter.humanized_essential_tag_string %> - <%= Danbooru.config.app_name %>">
<meta property="og:description" content="<%= @post.presenter.humanized_tag_string %>"> <meta property="og:description" content="<%= @post.presenter.humanized_tag_string %>">
<meta property="og:image" content="<%= @post.preview_file_url %>"> <meta property="og:image" content="http://<%= Danbooru.config.hostname %><%= @post.large_file_url %>">
<!-- Twitter properties --> <!-- Twitter properties -->
<% if @post.twitter_card_supported? %> <% if @post.twitter_card_supported? %>

View File

@@ -1,6 +1,6 @@
FactoryGirl.define do FactoryGirl.define do
factory(:tag) do factory(:tag) do
name {Faker::Name.first_name.downcase} name {"#{Faker::Name.first_name.downcase}#{rand(1000)}"}
post_count 0 post_count 0
category {Tag.categories.general} category {Tag.categories.general}
related_tags "" related_tags ""

View File

@@ -749,7 +749,7 @@ http_interactions:
recorded_at: Wed, 22 Oct 2014 23:29:57 GMT recorded_at: Wed, 22 Oct 2014 23:29:57 GMT
- request: - request:
method: get method: get
uri: http://i1.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip uri: http://i3.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip
body: body:
encoding: US-ASCII encoding: US-ASCII
string: '' string: ''

View File

@@ -44,9 +44,9 @@ class BulkUpdateRequestsControllerTest < ActionController::TestCase
context "for the creator" do context "for the creator" do
should "succeed" do should "succeed" do
assert_difference("BulkUpdateRequest.count", -1) do delete :destroy, {:id => @bulk_update_request.id}, {:user_id => @user.id}
delete :destroy, {:id => @bulk_update_request.id}, {:user_id => @user.id} @bulk_update_request.reload
end assert_equal("rejected", @bulk_update_request.status)
end end
end end
@@ -64,9 +64,9 @@ class BulkUpdateRequestsControllerTest < ActionController::TestCase
context "for an admin" do context "for an admin" do
should "succeed" do should "succeed" do
assert_difference("BulkUpdateRequest.count", -1) do delete :destroy, {:id => @bulk_update_request.id}, {:user_id => @admin.id}
delete :destroy, {:id => @bulk_update_request.id}, {:user_id => @admin.id} @bulk_update_request.reload
end assert_equal("rejected", @bulk_update_request.status)
end end
end end
end end

View File

@@ -72,14 +72,6 @@ class TagAliasesControllerTest < ActionController::TestCase
end end
end end
context "create action" do
should "create a tag alias" do
assert_difference("TagAlias.count", 1) do
post :create, {:tag_alias => {:antecedent_name => "xxx", :consequent_name => "yyy"}}, {:user_id => @user.id}
end
end
end
context "destroy action" do context "destroy action" do
setup do setup do
@tag_alias = FactoryGirl.create(:tag_alias) @tag_alias = FactoryGirl.create(:tag_alias)

View File

@@ -75,14 +75,6 @@ class TagImplicationsControllerTest < ActionController::TestCase
end end
end end
context "create action" do
should "create a tag implication" do
assert_difference("TagImplication.count", 1) do
post :create, {:tag_implication => {:antecedent_name => "xxx", :consequent_name => "yyy"}}, {:user_id => @user.id}
end
end
end
context "destroy action" do context "destroy action" do
setup do setup do
CurrentUser.scoped(@user, "127.0.0.1") do CurrentUser.scoped(@user, "127.0.0.1") do

View File

@@ -7,13 +7,13 @@ module Downloads
@source = "http://mochikko.deviantart.com/art/RESOLUTION-339610451" @source = "http://mochikko.deviantart.com/art/RESOLUTION-339610451"
@tempfile = Tempfile.new("danbooru-test") @tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path) @download = Downloads::File.new(@source, @tempfile.path)
VCR.use_cassette("download-deviant-art-html", :record => :new_episodes) do VCR.use_cassette("download-deviant-art-html", :record => :none) do
@download.download! @download.download!
end end
end end
should "set the direct image link as the source" do should "set the direct image link as the source" do
assert_equal("http://www.deviantart.com/download/339610451/resolution_by_mochikko-d5m713n.jpg?token=f828643e6e86a658e80f362745a0b20e20880fc6&ts=1414021578", @download.source) assert_equal("http://fc03.deviantart.net/fs71/f/2012/330/e/7/resolution_by_mochikko-d5m713n.jpg", @download.source)
end end
should "work" do should "work" do

View File

@@ -231,8 +231,8 @@ module Downloads
should "download the full size image instead of the thumbnail" do should "download the full size image instead of the thumbnail" do
assert_rewritten(@p0_full_size_image_3, @p0_large_thumbnail, "rewrite-pixiv-new-manga-p0-large-thumbnail") assert_rewritten(@p0_full_size_image_3, @p0_large_thumbnail, "rewrite-pixiv-new-manga-p0-large-thumbnail")
assert_rewritten(@p1_full_size_image_3, @p1_large_thumbnail, "rewrite-pixiv-new-manga-p1-large-thumbnail") assert_rewritten(@p1_full_size_image_3, @p1_large_thumbnail, "rewrite-pixiv-new-manga-p1-large-thumbnail")
assert_downloaded(@p0_file_size, @p0_large_thumbnail, "download-pixiv-new-manga-p0-large-thumbnail", :all) assert_downloaded(@p0_file_size, @p0_large_thumbnail, "download-pixiv-new-manga-p0-large-thumbnail")
assert_downloaded(@p1_file_size, @p1_large_thumbnail, "download-pixiv-new-manga-p1-large-thumbnail", :all) assert_downloaded(@p1_file_size, @p1_large_thumbnail, "download-pixiv-new-manga-p1-large-thumbnail")
end end
end end

View File

@@ -87,7 +87,7 @@ class PoolTest < ActiveSupport::TestCase
should "update any new posts that were added" do should "update any new posts that were added" do
@p1.reload @p1.reload
assert_equal("pool:#{@pool.id}", @p1.pool_string) assert_equal("pool:#{@pool.id} pool:series", @p1.pool_string)
end end
end end

View File

@@ -33,18 +33,23 @@ class PostTest < ActiveSupport::TestCase
end end
end end
should "remove the post from all pools" do context "that belongs to a pool" do
pool = FactoryGirl.create(:pool) setup do
pool.add!(@post) @pool = FactoryGirl.create(:pool)
@post.expunge! @pool.add!(@post)
pool.reload @post.reload
assert_equal("", pool.post_ids) @post.expunge!
end end
should "destroy the record" do should "remove the post from all pools" do
@post.expunge! @pool.reload
assert_equal([], @post.errors.full_messages) assert_equal("", @pool.post_ids)
assert_equal(0, Post.where("id = ?", @post.id).count) end
should "destroy the record" do
assert_equal([], @post.errors.full_messages)
assert_equal(0, Post.where("id = ?", @post.id).count)
end
end end
end end
@@ -425,6 +430,18 @@ class PostTest < ActiveSupport::TestCase
@post = FactoryGirl.create(:post) @post = FactoryGirl.create(:post)
end end
context "with a banned artist" do
setup do
@artist = FactoryGirl.create(:artist)
@artist.ban!
@post = FactoryGirl.create(:post, :tag_string => @artist.name)
end
should "ban the post" do
assert_equal(true, @post.is_banned?)
end
end
context "with an artist tag that is then changed to copyright" do context "with an artist tag that is then changed to copyright" do
setup do setup do
CurrentUser.user = FactoryGirl.create(:builder_user) CurrentUser.user = FactoryGirl.create(:builder_user)

View File

@@ -99,6 +99,19 @@ class TagAliasTest < ActiveSupport::TestCase
@alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic) @alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic)
end end
context "and conflicting wiki pages" do
setup do
@wiki1 = FactoryGirl.create(:wiki_page, :title => "aaa")
@wiki2 = FactoryGirl.create(:wiki_page, :title => "bbb")
end
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@alias.rename_wiki_and_artist
end
end
end
should "update the topic when processed" do should "update the topic when processed" do
assert_difference("ForumPost.count") do assert_difference("ForumPost.count") do
@alias.process! @alias.process!

View File

@@ -255,13 +255,14 @@ class UploadTest < ActiveSupport::TestCase
VCR.use_cassette("ugoira-converter", :record => :none) do VCR.use_cassette("ugoira-converter", :record => :none) do
assert_difference(["Post.count", "PixivUgoiraFrameData.count"]) do assert_difference(["Post.count", "PixivUgoiraFrameData.count"]) do
@upload.process! @upload.process!
assert_equal([], @upload.errors.full_messages)
end end
post = Post.last post = Post.last
assert_not_nil(post.pixiv_ugoira_frame_data) assert_not_nil(post.pixiv_ugoira_frame_data)
assert_equal("0d94800c4b520bf3d8adda08f95d31e2", post.md5) assert_equal("0d94800c4b520bf3d8adda08f95d31e2", post.md5)
assert_equal(60, post.image_width) assert_equal(60, post.image_width)
assert_equal(60, post.image_height) assert_equal(60, post.image_height)
assert_equal("http://i1.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", post.source) assert_equal("http://i3.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", post.source)
assert_operator(File.size(post.large_file_path), :>, 0) assert_operator(File.size(post.large_file_path), :>, 0)
assert_operator(File.size(post.preview_file_path), :>, 0) assert_operator(File.size(post.preview_file_path), :>, 0)
end end