activitypub-academy/app/controllers/api/v1/activity_log_controller.rb
2023-01-09 14:48:03 +01:00

40 lines
949 B
Ruby

# frozen_string_literal: true
class Api::V1::ActivityLogController < Api::BaseController
include ActionController::Live
# before_action -> { doorkeeper_authorize! :read }, only: [:show]
before_action :require_user!
rescue_from ArgumentError do |e|
render json: { error: e.to_s }, status: 422
end
def index
render :text => "hello world"
end
def show
response.headers['Content-Type'] = 'text/event-stream'
# hack to avoid computing Etag, which delays sending of data
response.headers['Last-Modified'] = Time.now.httpdate
sse = SSE.new(response.stream)
# id = current_account.local_username_and_domain
id = current_account.username
begin
ActivityLogger.register(id, sse)
while true
event = ActivityLogEvent.new('keep-alive')
ActivityLogger.log(id, event)
sleep 10
end
ensure
ActivityLogger.unregister(id)
sse.close
end
end
end