Skip to content

Commit 23ed930

Browse files
Nathaniel SuchyGargron
authored andcommitted
Add tootctl media lookup command (mastodon#12283)
* Add a lookup tool to the media cli * Improved lookup logic * Clarified wording in the output * Code style changes * Code style changes * Code style changes * Code style changes * Add error handling code incase an attachment isn't found * Code style changes * Code style changes * Make requested changes * Fix styling issues * Handle other media types * Remove an inadvertently added log * Make requested changes * Make the code safe no matter what the path, S3 or not * Code style changes * Code style changes * Replace select method with Ruby Enumerable grep method
1 parent 71cd41a commit 23ed930

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

lib/mastodon/media_cli.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,27 @@ def usage
113113
say("Imports:\t#{number_to_human_size(Import.sum(:data_file_size))}")
114114
say("Settings:\t#{number_to_human_size(SiteUpload.sum(:file_file_size))}")
115115
end
116+
117+
desc 'lookup', 'Lookup where media is displayed by passing a media URL'
118+
def lookup
119+
prompt = TTY::Prompt.new
120+
121+
url = prompt.ask('Please enter a URL to the media to lookup:', required: true)
122+
123+
attachment_id = url
124+
.split('/')[0..-2]
125+
.grep(/\A\d+\z/)
126+
.join('')
127+
128+
if url.split('/')[0..-2].include? 'media_attachments'
129+
model = MediaAttachment.find(attachment_id).status
130+
prompt.say(ActivityPub::TagManager.instance.url_for(model))
131+
elsif url.split('/')[0..-2].include? 'accounts'
132+
model = Account.find(attachment_id)
133+
prompt.say(ActivityPub::TagManager.instance.url_for(model))
134+
else
135+
prompt.say('Not found')
136+
end
137+
end
116138
end
117139
end

0 commit comments

Comments
 (0)