uploads_controller.rb 890 B

1234567891011121314151617181920212223242526272829
  1. # frozen_string_literal: true
  2. class Api::V1::Crypto::Keys::UploadsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :crypto }
  4. before_action :require_user!
  5. def create
  6. device = Device.find_or_initialize_by(access_token: doorkeeper_token)
  7. device.transaction do
  8. device.account = current_account
  9. device.update!(resource_params[:device])
  10. if resource_params[:one_time_keys].present? && resource_params[:one_time_keys].is_a?(Enumerable)
  11. resource_params[:one_time_keys].each do |one_time_key_params|
  12. device.one_time_keys.create!(one_time_key_params)
  13. end
  14. end
  15. end
  16. render json: device, serializer: REST::Keys::DeviceSerializer
  17. end
  18. private
  19. def resource_params
  20. params.permit(device: [:device_id, :name, :fingerprint_key, :identity_key], one_time_keys: [:key_id, :key, :signature])
  21. end
  22. end