2022-11-30 03:10:06 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::ActivityLogController < Api::BaseController
|
|
|
|
include ActionController::Live
|
|
|
|
|
2022-12-07 03:37:33 +09:00
|
|
|
# before_action -> { doorkeeper_authorize! :read }, only: [:show]
|
|
|
|
before_action :require_user!
|
2022-11-30 03:10:06 +09:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-12-07 03:37:33 +09:00
|
|
|
# id = current_account.local_username_and_domain
|
|
|
|
id = current_account.username
|
|
|
|
|
2022-11-30 03:10:06 +09:00
|
|
|
begin
|
2022-12-07 03:37:33 +09:00
|
|
|
ActivityLogger.register(id, sse)
|
|
|
|
|
|
|
|
while true
|
2023-01-05 01:29:24 +09:00
|
|
|
event = ActivityLogEvent.new('keep-alive')
|
2022-12-07 03:37:33 +09:00
|
|
|
ActivityLogger.log(id, event)
|
|
|
|
sleep 10
|
|
|
|
end
|
2022-11-30 03:10:06 +09:00
|
|
|
ensure
|
2022-12-07 03:37:33 +09:00
|
|
|
ActivityLogger.unregister(id)
|
2022-11-30 03:10:06 +09:00
|
|
|
sse.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|