-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OEmbed support for PreviewCard #2337
Conversation
Great! Does it Oembed linked toots? |
Code Climate is not happy - do we care? |
app/lib/provider_discovery.rb
Outdated
format ||= :json | ||
end | ||
|
||
if format.nil? || format == :xml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first conditional here will never be true, since if format is nil, we always set it to :json on line 17.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this series of conditionals is doing what you expect it to do. Are you trying to do something like this?
def provider_endpoint(format)
case format
when :json
html.at_xpath('//link[@type="application/json+oembed"]')['href']
when :xml
html.at_xpath('//link[@type="application/xml+oembed"]')['href']
else
provider_endpoint(:json) || provider_endpoint(:xml)
end
end
the current implementation uses JSON, or XML, or always json+oembed if no format is specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
For the time being, "rich" OEmbed types get ignored, because stuff like tweets tries to include |
don't display a link card anyway
CodeClimate is not happy on this one but the formatting it wants me to do is unreadable so I say, ignore it. |
@@ -14,8 +14,9 @@ def show | |||
def stream_entry_from_url(url) | |||
params = Rails.application.routes.recognize_path(url) | |||
|
|||
raise ActiveRecord::RecordNotFound unless params[:controller] == 'stream_entries' && params[:action] == 'show' | |||
raise ActiveRecord::RecordNotFound unless %w(stream_entries statuses).include?(params[:controller]) && params[:action] == 'show' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe extract that conditional into a method?
|
||
StreamEntry.find(params[:id]) | ||
return StreamEntry.find(params[:id]) if params[:controller] == 'stream_entries' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines could also be a separate method...
def stream_entry
if params[:controller] == 'stream_entries'
StreamEntry.find(params[:id])
else
Status.find(params[:id]).stream_entry
end
end
app/lib/provider_discovery.rb
Outdated
# frozen_string_literal: true | ||
|
||
class ProviderDiscovery < OEmbed::ProviderDiscovery | ||
USER_AGENT = "#{HTTP::Request::USER_AGENT} (Mastodon/#{Mastodon::VERSION}; +http://#{Rails.configuration.x.local_domain}/)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this string already assembled somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if we could have some sort of HTTP
factory because headers and timeout settings have to be set from quite a few places, but I'm not sure how to do that idiomatically. HttpFactory
doesn't sound like Ruby...
Fix #1681 - return existing access token when applicable instead of creating new
@@ -14,8 +14,20 @@ def show | |||
def stream_entry_from_url(url) | |||
params = Rails.application.routes.recognize_path(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this change needs to hold back merging this ... but it might be good to use a better local variable name here, since this is happening inside of a controller, and params
is already a method (and used up in the show
action...)
Is there a list of currently working websites? I tried e.g. Soundcloud and Twitter, but that didn't yet work. Just a normal link preview. |
* OEmbed support for PreviewCard * Improve ProviderDiscovery code failure treatment * Do not crawl links if there is a content warning, since those don't display a link card anyway * Reset db schema * Fresh migrate * Fix rubocop style issues Fix mastodon#1681 - return existing access token when applicable instead of creating new * Fix test * Extract http client to helper * Improve oembed controller
Apparently, nokogumbo (pulled in by sanitize, added with `OEmbed Support for PreviewCard` (mastodon#2337) - 88725d6) tries to install before nokogiri, despite needing nokogiri available to build properly. Instruct it to use the same settings as nokogiri does when building nokogiri directly, instead of via bundler.
* Nanobox Support - Added support for running Mastodon using Nanobox, both for local development, and for deployment to production - Dev mode tested and is working properly - Deployment is undergoing test as of this writing. If it works, this line will be amended to state success; if not, one or more subsequent commits will provide fixes. * [nanobox] Resolve Deploy Issues Everything seems to work except routing to the streaming API. Will investigate with the Nanobox staff and make fix commits if needed. Changes made: - Also need `NODE_ENV` in production - Node runs on `:4000` - Use `envsubst` to commit `.env.production` values, since `dotEnv` packages don't always support referencing other variables - Can't precompile assets after `transform` hook, but do this locally so it only has to be done once. - Rails won't create `production.log` on its own, so we do this ourselves. - Some `start` commands run from `/data/` for some reason, so use absolute paths in command arguments * [nanobox] Update Ruby version * [nanobox] Fix db.rake Ruby code style issues * [nanobox] Minor Fixes Some minor adjustments to improve functionality: - Fixed routing to `web.stream` instances - Adjust `.env.nanobox` to properly generate a default `SMTP_FROM_ADDRESS` via `envsubst` - Update Nginx configs to properly support the needed HTTP version and headers for proper functionality (the streaming API doesn't work without some of these settings in place) * [nanobox] Move usage info to docs repo * [nanobox] Updates for 1.2.x - Need to leave out `pkg-config` since Nanobox deploys without Ruby's headers - create a gem group to exclude the gem during Nanobox installs, but allow it to remain part of the default set otherwise - Update cron jobs to cover new/updated Rake tasks - Update `.env.nanobox` to include latest defaults and additions * [nanobox] Fix for nokogumbo, added in 1.3.x Apparently, nokogumbo (pulled in by sanitize, added with `OEmbed Support for PreviewCard` (#2337) - 88725d6) tries to install before nokogiri, despite needing nokogiri available to build properly. Instruct it to use the same settings as nokogiri does when building nokogiri directly, instead of via bundler. * [nanobox] Set NODE_ENV during asset compile The switch to WebPack will rely on the local value of the NODE_ENV evar, so set it to production during asset compilation. * [nanobox] Rebase on master; update Nginx configs - `pkg-config` Gem no longer causes issues in Nanobox, so revert the Gemfile change which allowed excluding it - Update Nginx configuration files with latest recommendations from production documentation - Rebase on master to Get This Merged™ Everything should be golden!
Oh boy, this is quite a whammy!
OEmbed::ProviderDiscovery
because the original was using regex to get link tags from HTML and it broke if they were in the wrong order or there was a, say,rel="alternate"
in the wrong placePreviewCard
schema to save the variety of attributes you can get from OpenGraph and OEmbed<Card />
component can now display links, photos and videos: