2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:15:08 +08:00
discourse/app/controllers/inline_onebox_controller.rb
Jarek Radosz 71834c898f
DEV: Update rubocop-discourse to 3.13 and autofix issues (#35073)
Co-authored-by: Loïc Guitaut <loic@discourse.org>
2025-10-06 16:11:01 +02:00

41 lines
1 KiB
Ruby

# frozen_string_literal: true
class InlineOneboxController < ApplicationController
MAX_URLS_LIMIT = 10
requires_login
def show
urls = params[:urls] || []
if urls.size > MAX_URLS_LIMIT
render json: failed_json.merge(errors: [I18n.t("inline_oneboxer.too_many_urls")]),
status: :payload_too_large
return
end
current_user_id = current_user.id
if InlineOneboxer.is_previewing?(current_user_id)
response.headers["Retry-After"] = "60"
render json: failed_json.merge(errors: [I18n.t("inline_oneboxer.concurrency_not_allowed")]),
status: :too_many_requests
return
end
hijack do
InlineOneboxer.preview!(current_user_id)
oneboxes =
InlineOneboxer.new(
params[:urls] || [],
user_id: current_user.id,
category_id: params[:category_id].to_i,
topic_id: params[:topic_id].to_i,
).process
InlineOneboxer.finish_preview!(current_user_id)
render json: { "inline-oneboxes" => oneboxes }
end
end
end