fix fa api endpoint

This commit is contained in:
Dylan Knutson
2023-09-13 08:45:47 -07:00
parent ca22face6c
commit 4a31bd99e8
3 changed files with 56 additions and 41 deletions

View File

@@ -198,40 +198,7 @@ class Domain::Fa::ApiController < ApplicationController
return
end
all_similar_users = all_similar_users.limit(limit).map do |user|
profile_thumb_url = user.avatar&.file_uri&.to_s
profile_thumb_url || begin
profile_page_response = get_best_user_page_http_log_entry_for(user)
if profile_page_response
parser = Domain::Fa::Parser::Page.new(profile_page_response.contents, require_logged_in: false)
profile_thumb_url = parser.user_page.profile_thumb_url
else
if user.due_for_follows_scan?
Domain::Fa::Job::UserFollowsJob.set({
priority: -20,
}).perform_later({
user: user,
})
end
if user.due_for_page_scan?
Domain::Fa::Job::UserPageJob.set({
priority: -20,
}).perform_later({
user: user,
})
end
end
rescue
logger.error("error getting profile_thumb_url: #{$!.message}")
end
{
name: user.name,
url_name: user.url_name,
profile_thumb_url: profile_thumb_url,
url: "https://www.furaffinity.net/user/#{user.url_name}/",
}
end
all_similar_users = users_list_to_similar_list(all_similar_users)
not_followed_similar_users = nil
if exclude_url_name
@@ -249,7 +216,9 @@ class Domain::Fa::ApiController < ApplicationController
error_type: "exclude_user_not_scanned",
}
else
helpers.similar_users_list(user.similar_users_by_followed(
users_list_to_similar_list(helpers.similar_users_by_followed(
user,
limit: 10,
exclude_followed_by: exclude_folowed_by_user,
))
end
@@ -362,4 +331,41 @@ class Domain::Fa::ApiController < ApplicationController
}
end
end
def users_list_to_similar_list(user_list)
users_list.map do |user|
profile_thumb_url = user.avatar&.file_uri&.to_s
profile_thumb_url || begin
profile_page_response = get_best_user_page_http_log_entry_for(user)
if profile_page_response
parser = Domain::Fa::Parser::Page.new(profile_page_response.contents, require_logged_in: false)
profile_thumb_url = parser.user_page.profile_thumb_url
else
if user.due_for_follows_scan?
Domain::Fa::Job::UserFollowsJob.set({
priority: -20,
}).perform_later({
user: user,
})
end
if user.due_for_page_scan?
Domain::Fa::Job::UserPageJob.set({
priority: -20,
}).perform_later({
user: user,
})
end
end
rescue
logger.error("error getting profile_thumb_url: #{$!.message}")
end
{
name: user.name,
url_name: user.url_name,
profile_thumb_url: profile_thumb_url,
url: "https://www.furaffinity.net/user/#{user.url_name}/",
}
end
end
end

View File

@@ -79,12 +79,18 @@ module Domain::Fa::UsersHelper
)
end
def similar_users_by_followed(user, limit: 10)
def similar_users_by_followed(
user,
limit: 10,
exclude_followed_by: nil
)
if user.disco.nil?
nil
else
ReduxApplicationRecord.connection.execute("SET ivfflat.probes = 32")
user.similar_users_by_followed.limit(limit)
user.similar_users_by_followed(
exclude_followed_by: exclude_followed_by,
).limit(limit)
end
end

View File

@@ -9,9 +9,12 @@
// @icon https://www.google.com/s2/favicons?sz=64&domain=furaffinity.net
// @grant GM_xmlhttpRequest
// @grant unsafeWindow
// @connect scraper.local
// @connect scraper
// @connect localhost
// ==/UserScript==
"use strict";
const HOST = "scraper:3000";
// const HOST = "localhost:3000";
function fa() {
function setupNavbar() {
@@ -520,7 +523,7 @@ function fa() {
let completedEnqueue = false;
GM_xmlhttpRequest({
url: "http://scraper.local:3000/api/fa/enqueue_objects",
url: `http://${HOST}/api/fa/enqueue_objects`,
method: "POST",
headers: {
Accept: "application/json",
@@ -562,7 +565,7 @@ function fa() {
function pollLiveStats() {
GM_xmlhttpRequest({
url: "http://scraper.local:3000/api/fa/object_statuses",
url: `http://${HOST}/api/fa/object_statuses`,
method: "POST",
headers: {
Accept: "application/json",
@@ -828,7 +831,7 @@ function twitter(mainNode) {
console.log("enqueue tweets: ", tweets);
GM_xmlhttpRequest({
url: "http://scraper.local:3000/api/twitter/enqueue_objects",
url: `http://${HOST}/api/twitter/enqueue_objects`,
method: "POST",
headers: {
Accept: "application/json",