diff --git a/app/assets/javascripts/related_tag.js.erb b/app/assets/javascripts/related_tag.js.erb index 352eda78c..88ea5ed71 100644 --- a/app/assets/javascripts/related_tag.js.erb +++ b/app/assets/javascripts/related_tag.js.erb @@ -7,6 +7,7 @@ $("#related-tags-container").hide(); $("#artist-tags-container").hide(); $("#upload_tag_string,#post_tag_string").keyup(Danbooru.RelatedTag.update_selected); + $("body").on("click", "#artist-related-tags-column a.del", Danbooru.RelatedTag.disable_artist_url) } } @@ -236,19 +237,26 @@ if (desc.length > 30) { desc = desc.substring(0, 30) + "..."; } - var $del = $("").text(desc); - $ul.append($("
  • ").html($del)); + $ul.append( + $("
  • ").append( + $("").text(desc) + ) + ); } else if (text.match(/^ http/)) { text = text.substring(1, 1000); - var $url = $(""); var desc = text.replace(/^https?:\/\//, ""); if (desc.length > 30) { desc = desc.substring(0, 30) + "..."; } - $url.text(desc); - $url.attr("href", text); - $url.attr("target", "_blank"); - $ul.append($("
  • ").html($url)); + $ul.append( + $("
  • ").append([ + $("").text(desc).attr("href", text).attr("target", "_blank"), + " ", + $("").attr("href", text).addClass("del").append( + $("").addClass("fas fa-minus-circle") + ) + ]) + ); } else { $ul.append($("
  • ").text(text)); } @@ -286,7 +294,9 @@ var url = $("#upload_source,#post_source"); var referer_url = $("#upload_referer_url"); $.get("/artists/finder.json", {"url": url.val(), "referer_url": referer_url.val()}, Danbooru.RelatedTag.process_artist); - e.preventDefault(); + if (e) { + e.preventDefault(); + } } Danbooru.RelatedTag.process_artist = function(data) { @@ -314,6 +324,27 @@ $("#related-tags").hide(); $("#toggle-related-tags-link").text("ยป"); } + + Danbooru.RelatedTag.disable_artist_url = function(e) { + var url = e.currentTarget.href; + $.each(Danbooru.RelatedTag.recent_artists[0].sorted_urls, function(k, v) { + if (v["normalized_url"] === url || v["url"] === url) { + if (!confirm("This will mark the URL as inactive. Continue?")) { + return; + } + + $.ajax("/artist_urls/" + v["id"], { + method: "PUT", + data: { + artist_url: { + is_active: false + } + } + }).done(Danbooru.RelatedTag.find_artist); + } + }); + return false; + } })(); $(function() { diff --git a/app/assets/stylesheets/specific/related_tags.scss b/app/assets/stylesheets/specific/related_tags.scss index 141995254..ff5fe72ee 100644 --- a/app/assets/stylesheets/specific/related_tags.scss +++ b/app/assets/stylesheets/specific/related_tags.scss @@ -28,6 +28,11 @@ div.related-tags { font-weight: bold; } + svg { + margin-top: 2px; + cursor: pointer; + } + a { min-width: 3em; } diff --git a/app/controllers/artist_urls_controller.rb b/app/controllers/artist_urls_controller.rb new file mode 100644 index 000000000..1c75ece3b --- /dev/null +++ b/app/controllers/artist_urls_controller.rb @@ -0,0 +1,18 @@ +class ArtistUrlsController < ApplicationController + respond_to :json + before_action :member_only + + def update + @artist_url = ArtistUrl.find(params[:id]) + @artist_url.update(artist_url_params) + respond_with(@artist_url) + end + +private + + def artist_url_params + permitted_params = %i[is_active] + + params.fetch(:artist_url, {}).permit(permitted_params) + end +end diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index 102e941f1..1c83352fd 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -1,5 +1,5 @@ class ArtistsController < ApplicationController - respond_to :html, :xml, :json + respond_to :html, :xml, :json, :js before_action :member_only, :except => [:index, :show, :show_or_new, :banned] before_action :builder_only, :only => [:destroy] before_action :admin_only, :only => [:ban, :unban] diff --git a/app/logical/popular_search_service.rb b/app/logical/popular_search_service.rb index a70b11d58..77a5280b4 100644 --- a/app/logical/popular_search_service.rb +++ b/app/logical/popular_search_service.rb @@ -23,6 +23,8 @@ class PopularSearchService end def fetch_data + return [] unless self.class.enabled? + dates = date.strftime("%Y-%m-%d") Cache.get("ps-day-#{dates}", 1.minute) do diff --git a/app/views/artists/_secondary_links.html.erb b/app/views/artists/_secondary_links.html.erb index 2d8c20c39..496fb339d 100644 --- a/app/views/artists/_secondary_links.html.erb +++ b/app/views/artists/_secondary_links.html.erb @@ -17,7 +17,7 @@ <% if @artist.is_active? %>
  • <%= link_to "Delete", artist_path(@artist), method: :delete, data: {confirm: "Are you sure you want to delete this artist?"} %>
  • <% else %> -
  • <%= link_to "Undelete", artist_path(@artist), method: :put, data: {confirm: "Are you sure you want to undelete this artist?", params: {"artist[is_active]" => true}} %>
  • +
  • <%= link_to "Undelete", artist_path(@artist, format: "js"), method: :put, data: {confirm: "Are you sure you want to undelete this artist?", params: "artist[is_active]=true"}, remote: true %>
  • <% end %> <% end %> <% if CurrentUser.is_admin? %> diff --git a/app/views/artists/update.js.erb b/app/views/artists/update.js.erb new file mode 100644 index 000000000..bcebe9d37 --- /dev/null +++ b/app/views/artists/update.js.erb @@ -0,0 +1 @@ +location.reload(); \ No newline at end of file diff --git a/config/docker/danbooru-base b/config/docker/danbooru-base index 56592b915..60d05be15 100644 --- a/config/docker/danbooru-base +++ b/config/docker/danbooru-base @@ -6,7 +6,8 @@ RUN apt-get -y install wget RUN wget -q https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz -RUN apt-get -y install -qq apt-utils build-essential automake libssl-dev libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel memcached libmemcached-dev git curl libcurl4-openssl-dev imagemagick libmagickcore-dev libmagickwand-dev sendmail-bin sendmail postgresql-client libpq-dev nginx ssh coreutils ffmpeg mkvtoolnix emacs24-nox telnet libvips42 libvips-tools libvips-dev > /dev/null +RUN apt-get -y install -qq apt-utils build-essential automake libssl-dev libxml2-dev libxslt-dev ncurses-dev sudo libreadline-dev flex bison ragel memcached libmemcached-dev git curl libcurl4-openssl-dev imagemagick libmagickcore-dev libmagickwand-dev sendmail-bin sendmail postgresql-client libpq-dev nginx ssh coreutils ffmpeg mkvtoolnix emacs24-nox telnet libvips42 libvips-tools libvips-dev && \ + apt-get clean RUN useradd -ms /bin/bash danbooru -u 1000 RUN mkdir /app RUN mkdir -p /var/www/danbooru/shared/data @@ -22,7 +23,7 @@ USER danbooru RUN echo 'gem: --no-document' > ~/.gemrc RUN gem install bundler --quiet WORKDIR /app -RUN bundle install > /dev/null +RUN bundle install COPY script/install/database.yml.templ /app/config/database.yml COPY script/install/danbooru_local_config.rb.templ /app/config/danbooru_local_config.rb EXPOSE 3000 diff --git a/config/routes.rb b/config/routes.rb index 3fca106f3..b6d9c5584 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -81,6 +81,7 @@ Rails.application.routes.draw do get :finder end end + resources :artist_urls, only: [:update] resources :artist_versions, :only => [:index] do collection do get :search diff --git a/test/functional/artists_controller_test.rb b/test/functional/artists_controller_test.rb index f1203b8ac..ad3ba74e7 100644 --- a/test/functional/artists_controller_test.rb +++ b/test/functional/artists_controller_test.rb @@ -199,7 +199,7 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest should "undelete an artist" do @builder = create(:builder_user) - post_auth undelete_artist_path(@artist.id), @builder + put_auth artist_path(@artist.id), @builder, params: {artist: {is_active: true}} assert_redirected_to(artist_path(@artist.id)) assert_equal(true, @artist.reload.is_active) end diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index 15ea331a8..a1298709e 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -3,6 +3,8 @@ require "test_helper" class PostsControllerTest < ActionDispatch::IntegrationTest context "The posts controller" do setup do + PopularSearchService.stubs(:enabled?).returns(false) + @user = travel_to(1.month.ago) {create(:user)} as_user do @post = create(:post, :tag_string => "aaaa") diff --git a/test/unit/post_replacement_test.rb b/test/unit/post_replacement_test.rb index 03173cbd4..7d96a07c4 100644 --- a/test/unit/post_replacement_test.rb +++ b/test/unit/post_replacement_test.rb @@ -194,7 +194,7 @@ class PostReplacementTest < ActiveSupport::TestCase assert_equal("cad1da177ef309bf40a117c17b8eecf5", Digest::MD5.file(@post.file).hexdigest) assert_equal("https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip", @post.source) - assert_equal([{"delay_msec"=>125}, {"delay_msec"=>125}], @post.pixiv_ugoira_frame_data.data) + assert_equal([{"delay"=>125, "file"=>"000001.jpg"}, {"delay"=>125,"file"=>"000002.jpg"}], @post.pixiv_ugoira_frame_data.data) rescue Net::OpenTimeout skip "Remote connection to Pixiv failed" end