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:
@@ -1,7 +0,0 @@
|
||||
These are mocked services to be used for development purposes.
|
||||
|
||||
- danbooru: port 3000
|
||||
- recommender: port 3001
|
||||
- iqdbs: port 3002
|
||||
- reportbooru: port 3003
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
require 'sinatra'
|
||||
require 'json'
|
||||
require_relative './mock_service_helper'
|
||||
|
||||
set :port, 3002
|
||||
|
||||
configure do
|
||||
POST_IDS = MockServiceHelper.fetch_post_ids
|
||||
end
|
||||
|
||||
get '/similar' do
|
||||
content_type :json
|
||||
POST_IDS[0..10].map {|x| {post_id: x}}.to_json
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
require 'socket'
|
||||
require 'timeout'
|
||||
require 'httparty'
|
||||
|
||||
module MockServiceHelper
|
||||
module_function
|
||||
|
||||
DANBOORU_PORT = 3000
|
||||
|
||||
def fetch_post_ids
|
||||
begin
|
||||
s = TCPSocket.new("localhost", DANBOORU_PORT)
|
||||
s.close
|
||||
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
||||
sleep 1
|
||||
retry
|
||||
end
|
||||
|
||||
json = HTTParty.get("http://localhost:#{DANBOORU_PORT}/posts.json?random=true&limit=10").body
|
||||
return JSON.parse(json).map {|x| x["id"]}
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
require 'sinatra'
|
||||
require 'json'
|
||||
require_relative './mock_service_helper'
|
||||
|
||||
set :port, 3001
|
||||
|
||||
configure do
|
||||
POST_IDS = MockServiceHelper.fetch_post_ids
|
||||
end
|
||||
|
||||
get '/recommend/:user_id' do
|
||||
content_type :json
|
||||
POST_IDS[0..10].map {|x| [x, "1.000"]}.to_json
|
||||
end
|
||||
|
||||
get '/similar/:post_id' do
|
||||
content_type :json
|
||||
POST_IDS[0..6].map {|x| [x, "1.000"]}.to_json
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
require 'sinatra'
|
||||
require 'json'
|
||||
|
||||
set :port, 3003
|
||||
|
||||
get '/missed_searches' do
|
||||
content_type :text
|
||||
return "abcdefg 10.0\nblahblahblah 20.0\n"
|
||||
end
|
||||
|
||||
get '/post_searches/rank' do
|
||||
content_type :json
|
||||
return [["abc", 100], ["def", 200]].to_json
|
||||
end
|
||||
|
||||
get '/reports/user_similarity' do
|
||||
# todo
|
||||
end
|
||||
|
||||
post '/post_views' do
|
||||
# todo
|
||||
end
|
||||
Reference in New Issue
Block a user