scripts: refactor mocked services.

Replace the mocked services in scripts/mocked_services with Rails-level
mocked services.

The scripts in scripts/mocked_services were a set of stub Sinatra
servers used to mock the Reportbooru, Recommender, and IQDBs services
during development. They return fake data so you can test pages that use
these services.

Implementing these services in Rails makes it easier to run them. It
also lets us drop a dependency on Sinatra and drop a use of HTTParty.

To use these services, set the following configuration in danbooru_local_config.rb
or .env.local:

* reportbooru_server: http://localhost:3000/mock/reportbooru
* recommender_server: http://localhost:3000/mock/recommender
* iqdbs_server: http://localhost:3000/mock/iqdb

where `http://localhost:300` is the url for your local Danbooru server
(may need to be changed depending on your configuration).
This commit is contained in:
evazion
2020-06-21 15:02:14 -05:00
parent 29a5f7dfc8
commit 5c7843bd3d
9 changed files with 96 additions and 86 deletions

View File

@@ -376,14 +376,20 @@ module Danbooru
false
end
# reportbooru options - see https://github.com/r888888888/reportbooru
# The URL for the Reportbooru server (https://github.com/evazion/reportbooru).
# Optional. Used for tracking post views, popular searches, and missed searches.
# Set to http://localhost/mock/reportbooru to enable a fake reportbooru
# server for development purposes.
def reportbooru_server
end
def reportbooru_key
end
# iqdbs options - see https://github.com/r888888888/iqdbs
# The URL for the IQDBs server (https://github.com/evazion/iqdbs).
# Optional. Used for dupe detection and reverse image searches.
# Set to http://localhost/mock/iqdbs to enable a fake iqdb server for
# development purposes.
def iqdbs_server
end
@@ -461,6 +467,10 @@ module Danbooru
def cloudflare_zone
end
# The URL for the recommender server (https://github.com/evazion/recommender).
# Optional. Used to generate post recommendations.
# Set to http://localhost/mock/recommender to enable a fake recommender
# server for development purposes.
def recommender_server
end

View File

@@ -372,6 +372,14 @@ Rails.application.routes.draw do
get "/static/contact" => "static#contact", :as => "contact"
get "/static/dtext_help" => "static#dtext_help", :as => "dtext_help"
get "/mock/recommender/recommend/:user_id" => "mock_services#recommender_recommend", as: "mock_recommender_recommend"
get "/mock/recommender/similiar/:post_id" => "mock_services#recommender_similar", as: "mock_recommender_similar"
get "/mock/reportbooru/missed_searches" => "mock_services#reportbooru_missed_searches", as: "mock_reportbooru_missed_searches"
get "/mock/reportbooru/post_searches/rank" => "mock_services#reportbooru_post_searches", as: "mock_reportbooru_post_searches"
get "/mock/reportbooru/post_views/rank" => "mock_services#reportbooru_post_views", as: "mock_reportbooru_post_views"
get "/mock/iqdbs/similar" => "mock_services#iqdbs_similar", as: "mock_iqdbs_similar"
post "/mock/iqdbs/similar" => "mock_services#iqdbs_similar"
root :to => "posts#index"
get "*other", :to => "static#not_found"