diff --git a/app/controllers/api/v2/image_proxy_controller.rb b/app/controllers/api/v2/image_proxy_controller.rb new file mode 100644 index 00000000..c6d56bda --- /dev/null +++ b/app/controllers/api/v2/image_proxy_controller.rb @@ -0,0 +1,14 @@ +require 'base64' +require 'net/http' + +class Api::V2::ImageProxyController < EmptyController + def get + if params[:trends_url].nil? + raise GabSocial::NotPermittedError + else + url = URI.parse(params[:trends_url]) + image = Net::HTTP.get_response(url) + send_data image.body, type: image.content_type, disposition: 'inline' + end + end +end \ No newline at end of file diff --git a/app/javascript/gabsocial/reducers/news.js b/app/javascript/gabsocial/reducers/news.js index 184f769b..688ed815 100644 --- a/app/javascript/gabsocial/reducers/news.js +++ b/app/javascript/gabsocial/reducers/news.js @@ -46,7 +46,7 @@ const normalizeTrendsItem = (item) => { title: `${item.pagePreview.title}`.trim(), description: `${item.pagePreview.description}`.trim(), publish_date: item.pubDate, - image: Array.isArray(item.pagePreview.images) ? item.pagePreview.images[0] : null, // : todo : proxy + image: Array.isArray(item.pagePreview.images) ? `/api/v2/image_proxy?trends_url=${item.pagePreview.images[0]}` : null, feed_title: item.feed.title, feed_slug: item.feed.slug, feed_base_url: `${item.feed.url}`.replace('www.', '').replace('https://', '').replace('http://', '').replace('/', ''), diff --git a/config/routes.rb b/config/routes.rb index 94bf6cc9..c9a34830 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -468,6 +468,7 @@ Rails.application.routes.draw do namespace :v2 do get '/search', to: 'search#index', as: :search + get '/image_proxy', to: 'image_proxy#get' end namespace :web do