workaround for bsky avatar incorret url
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
# typed: strict
|
# typed: strict
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Domain::UserAvatarJob < Scraper::JobBase
|
class Domain::UserAvatarJob < Scraper::JobBase
|
||||||
queue_as :static_file
|
queue_as :static_file
|
||||||
discard_on ActiveJob::DeserializationError
|
discard_on ActiveJob::DeserializationError
|
||||||
@@ -24,6 +26,8 @@ class Domain::UserAvatarJob < Scraper::JobBase
|
|||||||
self.first_log_entry ||= response.log_entry
|
self.first_log_entry ||= response.log_entry
|
||||||
avatar.last_log_entry = response.log_entry
|
avatar.last_log_entry = response.log_entry
|
||||||
|
|
||||||
|
return if check_bluesky_force_rescan?(response, avatar)
|
||||||
|
|
||||||
case response.status_code
|
case response.status_code
|
||||||
when 200
|
when 200
|
||||||
avatar.state = "ok"
|
avatar.state = "ok"
|
||||||
@@ -50,4 +54,37 @@ class Domain::UserAvatarJob < Scraper::JobBase
|
|||||||
user.touch if user
|
user.touch if user
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user