workaround for bsky avatar incorret url

This commit is contained in:
Dylan Knutson
2025-08-16 05:17:26 +00:00
parent a1fab9e645
commit 64a65d1490

View File

@@ -1,4 +1,6 @@
# typed: strict
# frozen_string_literal: true
class Domain::UserAvatarJob < Scraper::JobBase
queue_as :static_file
discard_on ActiveJob::DeserializationError
@@ -24,6 +26,8 @@ class Domain::UserAvatarJob < Scraper::JobBase
self.first_log_entry ||= response.log_entry
avatar.last_log_entry = response.log_entry
return if check_bluesky_force_rescan?(response, avatar)
case response.status_code
when 200
avatar.state = "ok"
@@ -50,4 +54,37 @@ class Domain::UserAvatarJob < Scraper::JobBase
user.touch if user
end
end
sig do
params(
response: Scraper::HttpClient::Response,
avatar: Domain::UserAvatar,
).returns(T::Boolean)
end
def check_bluesky_force_rescan?(response, avatar)
return false unless response.status_code == 400
unless avatar.url_str&.starts_with?(
"https://bsky.social/xrpc/com.atproto.sync.getBlob",
)
return false
end
data = JSON.parse(response.body)
# not the right error from bsky
return false unless data["error"] == "RepoDeactivated"
# already enqueued force rescan of user
return false if avatar.error_message == "RepoDeactivated"
logger.warn(format_tags("bsky blob 400, force rescan user"))
avatar.state = "http_error"
avatar.error_message = "RepoDeactivated"
avatar.save!
Domain::Bluesky::Job::ScanUserJob.perform_later(
user: avatar.user,
force_scan: true,
)
true
end
end