1
0

oembed_controller.rb 712 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. class Api::OEmbedController < Api::BaseController
  3. skip_before_action :require_authenticated_user!
  4. before_action :set_status
  5. before_action :require_public_status!
  6. def show
  7. render json: @status, serializer: OEmbedSerializer, width: maxwidth_or_default, height: maxheight_or_default
  8. end
  9. private
  10. def set_status
  11. @status = status_finder.status
  12. end
  13. def require_public_status!
  14. not_found if @status.hidden?
  15. end
  16. def status_finder
  17. StatusFinder.new(params[:url])
  18. end
  19. def maxwidth_or_default
  20. (params[:maxwidth].presence || 400).to_i
  21. end
  22. def maxheight_or_default
  23. params[:maxheight].present? ? params[:maxheight].to_i : nil
  24. end
  25. end