diff options
author | Nathaniel Suchy <me@lunorian.is> | 2019-11-04 06:55:20 -0500 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2019-11-04 12:55:20 +0100 |
commit | 23ed9303b890f07715b7afaf0e1a18c13e40ea15 (patch) | |
tree | 96cfd1c0880d93cb589dd3af2907b7c053131eee | |
parent | 71cd41aebf4fcb988d847dcd7eae6fae2ce495a6 (diff) |
Add `tootctl media lookup` command (#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
-rw-r--r-- | lib/mastodon/media_cli.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/mastodon/media_cli.rb b/lib/mastodon/media_cli.rb index e48175134..3b702f155 100644 --- a/lib/mastodon/media_cli.rb +++ b/lib/mastodon/media_cli.rb @@ -113,5 +113,27 @@ module Mastodon say("Imports:\t#{number_to_human_size(Import.sum(:data_file_size))}") say("Settings:\t#{number_to_human_size(SiteUpload.sum(:file_file_size))}") end + + desc 'lookup', 'Lookup where media is displayed by passing a media URL' + def lookup + prompt = TTY::Prompt.new + + url = prompt.ask('Please enter a URL to the media to lookup:', required: true) + + attachment_id = url + .split('/')[0..-2] + .grep(/\A\d+\z/) + .join('') + + if url.split('/')[0..-2].include? 'media_attachments' + model = MediaAttachment.find(attachment_id).status + prompt.say(ActivityPub::TagManager.instance.url_for(model)) + elsif url.split('/')[0..-2].include? 'accounts' + model = Account.find(attachment_id) + prompt.say(ActivityPub::TagManager.instance.url_for(model)) + else + prompt.say('Not found') + end + end end end |