logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

activity_controller.rb (860B)


  1. # frozen_string_literal: true
  2. class Api::V1::Instances::ActivityController < Api::BaseController
  3. before_action :require_enabled_api!
  4. respond_to :json
  5. def show
  6. render_cached_json('api:v1:instances:activity:show', expires_in: 1.day) { activity }
  7. end
  8. private
  9. def activity
  10. weeks = []
  11. 12.times do |i|
  12. day = i.weeks.ago.to_date
  13. week_id = day.cweek
  14. week = Date.commercial(day.cwyear, week_id)
  15. weeks << {
  16. week: week.to_time.to_i.to_s,
  17. statuses: Redis.current.get("activity:statuses:local:#{week_id}") || '0',
  18. logins: Redis.current.pfcount("activity:logins:#{week_id}").to_s,
  19. registrations: Redis.current.get("activity:accounts:local:#{week_id}") || '0',
  20. }
  21. end
  22. weeks
  23. end
  24. def require_enabled_api!
  25. head 404 unless Setting.activity_api_enabled
  26. end
  27. end