mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: More safety when displaying link counts on blogs
This commit is contained in:
@ -29,14 +29,18 @@ class EmbedController < ApplicationController
|
||||
|
||||
def count
|
||||
|
||||
urls = params[:embed_url].map {|u| u.sub(/#discourse-comments$/, '').sub(/\/$/, '') }
|
||||
topic_embeds = TopicEmbed.where(embed_url: urls).includes(:topic).references(:topic)
|
||||
|
||||
embed_urls = params[:embed_url]
|
||||
by_url = {}
|
||||
topic_embeds.each do |te|
|
||||
url = te.embed_url
|
||||
url = "#{url}#discourse-comments" unless params[:embed_url].include?(url)
|
||||
by_url[url] = I18n.t('embed.replies', count: te.topic.posts_count - 1)
|
||||
|
||||
if embed_urls.present?
|
||||
urls = embed_urls.map {|u| u.sub(/#discourse-comments$/, '').sub(/\/$/, '') }
|
||||
topic_embeds = TopicEmbed.where(embed_url: urls).includes(:topic).references(:topic)
|
||||
|
||||
topic_embeds.each do |te|
|
||||
url = te.embed_url
|
||||
url = "#{url}#discourse-comments" unless params[:embed_url].include?(url)
|
||||
by_url[url] = I18n.t('embed.replies', count: te.topic.posts_count - 1)
|
||||
end
|
||||
end
|
||||
|
||||
render json: {counts: by_url}, callback: params[:callback]
|
||||
|
Reference in New Issue
Block a user