diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index 0ab9b00a7..73ee876e9 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -51,7 +51,7 @@ module PostsHelper msg = "#{params[:id]},#{session.id}" verifier = ActiveSupport::MessageVerifier.new(Danbooru.config.reportbooru_key, digest: "SHA256").generate(msg) - return render("posts/partials/index/view_count", msg: msg) + return render("posts/partials/show/view_count", msg: msg) end def common_searches_html(user) diff --git a/app/logical/post_view_count_service.rb b/app/logical/post_view_count_service.rb new file mode 100644 index 000000000..4dd4137f3 --- /dev/null +++ b/app/logical/post_view_count_service.rb @@ -0,0 +1,31 @@ +class PostViewCountService + def self.enabled? + Danbooru.config.reportbooru_server.present? + end + + def initialize + if !MissedSearchService.enabled? + raise NotImplementedError.new("the Reportbooru service isn't configured. Missed searches are not available.") + end + end + + def fetch_count(post_id) + url = URI.parse("#{Danbooru.config.reportbooru_server}/post_views/#{post_id}?date=#{date}") + response = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 6)) + if response.success? + return JSON.parse(response.body) + else + return nil + end + end + + def fetch_rank(date = Date.today) + url = URI.parse("#{Danbooru.config.reportbooru_server}/post_views/rank?date=#{date}") + response = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 6)) + if response.success? + return JSON.parse(response.body) + else + return nil + end + end +end