The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

41 lines
1000 B

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