mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 19:03:13 +08:00
41986cdb2f
This also corrects the positioning in the chain of the check and removes misuse of prepend_before_action
37 lines
872 B
Ruby
37 lines
872 B
Ruby
require_dependency 'oneboxer'
|
|
|
|
class OneboxController < ApplicationController
|
|
requires_login
|
|
|
|
def show
|
|
unless params[:refresh] == 'true'
|
|
preview = Oneboxer.cached_preview(params[:url])
|
|
preview.strip! if preview.present?
|
|
return render(plain: preview) if preview.present?
|
|
end
|
|
|
|
# only 1 outgoing preview per user
|
|
return render(body: nil, status: 429) if Oneboxer.is_previewing?(current_user.id)
|
|
|
|
user_id = current_user.id
|
|
invalidate = params[:refresh] == 'true'
|
|
url = params[:url]
|
|
|
|
hijack do
|
|
Oneboxer.preview_onebox!(user_id)
|
|
|
|
preview = Oneboxer.preview(url, invalidate_oneboxes: invalidate)
|
|
preview.strip! if preview.present?
|
|
|
|
Oneboxer.onebox_previewed!(user_id)
|
|
|
|
if preview.blank?
|
|
render body: nil, status: 404
|
|
else
|
|
render plain: preview
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|