Sync Mastodon IDs/profiles to local accounts

Add a new service to import some data from Mastodon accounts:

* Find users by username, store Mastodon account ID in local db when
  found
* Import display name (don't overwrite existing)
* Import avatar (don't overwrite existing)
This commit is contained in:
2025-05-17 16:44:28 +04:00
parent c291765777
commit 37c59b7b0c
9 changed files with 197 additions and 60 deletions

View File

@@ -193,7 +193,11 @@ class SettingsController < ApplicationController
def store_user_avatar
io = @user.avatar_new.tempfile
img_data = process_avatar(io)
img_data = UserManager::ProcessAvatar.call(io: io)
if img_data.blank?
@user.errors.add(:avatar, "failed to process file")
false
end
tempfile = Tempfile.create
tempfile.binmode
tempfile.write(img_data)
@@ -212,18 +216,4 @@ class SettingsController < ApplicationController
@user.save
end
end
def process_avatar(io)
processed = ImageProcessing::Vips
.source(io)
.resize_to_fill(400, 400)
.saver(strip: true)
.call
io.rewind
processed.read
rescue Vips::Error => e
Sentry.capture_exception(e) if Setting.sentry_enabled?
Rails.logger.error { "Image processing failed for avatar: #{e.message}" }
nil
end
end