2013-02-05 14:16:51 -05:00
|
|
|
require_dependency 'oneboxer'
|
|
|
|
|
|
|
|
class OneboxController < ApplicationController
|
2016-12-19 18:31:10 -05:00
|
|
|
before_filter :ensure_logged_in
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
def show
|
2016-12-19 18:31:10 -05:00
|
|
|
params.require(:user_id)
|
2013-03-05 14:03:50 -05:00
|
|
|
|
2016-12-19 18:31:10 -05:00
|
|
|
preview = Oneboxer.cached_preview(params[:url])
|
|
|
|
preview.strip! if preview.present?
|
|
|
|
|
2017-04-10 08:01:25 -04:00
|
|
|
return render(plain: preview) if preview.present?
|
2016-12-19 18:31:10 -05:00
|
|
|
|
|
|
|
# only 1 outgoing preview per user
|
|
|
|
return render(nothing: true, status: 429) if Oneboxer.is_previewing?(params[:user_id])
|
|
|
|
|
|
|
|
Oneboxer.preview_onebox!(params[:user_id])
|
|
|
|
|
|
|
|
preview = Oneboxer.preview(params[:url], invalidate_oneboxes: params[:refresh] == 'true')
|
|
|
|
preview.strip! if preview.present?
|
|
|
|
|
|
|
|
Scheduler::Defer.later("Onebox previewed") {
|
|
|
|
Oneboxer.onebox_previewed!(params[:user_id])
|
|
|
|
}
|
|
|
|
|
|
|
|
if preview.blank?
|
2013-03-05 14:03:50 -05:00
|
|
|
render nothing: true, status: 404
|
|
|
|
else
|
2017-04-10 08:01:25 -04:00
|
|
|
render plain: preview
|
2013-03-05 14:03:50 -05:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|