You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
712 B

  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