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.

44 lines
1.2 KiB

  1. class ApiController < ApplicationController
  2. protect_from_forgery with: :null_session
  3. skip_before_action :verify_authenticity_token
  4. rescue_from ActiveRecord::RecordInvalid do |e|
  5. render json: { error: e.to_s }, status: 422
  6. end
  7. rescue_from ActiveRecord::RecordNotFound do
  8. render json: { error: 'Record not found' }, status: 404
  9. end
  10. rescue_from Goldfinger::Error do
  11. render json: { error: 'Remote account could not be resolved' }, status: 422
  12. end
  13. rescue_from HTTP::Error do
  14. render json: { error: 'Remote data could not be fetched' }, status: 503
  15. end
  16. rescue_from OpenSSL::SSL::SSLError do
  17. render json: { error: 'Remote SSL certificate could not be verified' }, status: 503
  18. end
  19. protected
  20. def current_resource_owner
  21. User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
  22. end
  23. def current_user
  24. super || current_resource_owner
  25. end
  26. def render_empty
  27. render json: {}, status: 200
  28. end
  29. def set_maps(statuses)
  30. status_ids = statuses.flat_map { |s| [s.id, s.reblog_of_id] }.compact.uniq
  31. @reblogs_map = Status.reblogs_map(status_ids, current_user.account)
  32. @favourites_map = Status.favourites_map(status_ids, current_user.account)
  33. end
  34. end