diff --git a/README.md b/README.md index 7144774..7632898 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,4 @@ Display stats on your last year of Discourse usage. ## Usage -- add `http://127.0.0.1:4200/rewinds?` in `SiteSetting.allowed_iframes` -- example embed of a rewind in a post: - -``` - -``` +Navigate to `/my/activity/rewind` diff --git a/app/controllers/discourse_rewind/rewinds_assets_controller.rb b/app/controllers/discourse_rewind/rewinds_assets_controller.rb deleted file mode 100644 index d6ddbba..0000000 --- a/app/controllers/discourse_rewind/rewinds_assets_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -module ::DiscourseRewind - class RewindsAssetsController < ::ApplicationController - requires_plugin PLUGIN_NAME - - skip_before_action :preload_json, :check_xhr, only: %i[show] - skip_before_action :verify_authenticity_token, only: %i[show] - - def show - no_cookies - - name = params[:name] - path, content_type = - if name == "rewind" - %w[rewind.css text/css] - else - raise Discourse::NotFound - end - - content = File.read(DiscourseRewind.public_asset_path("css/#{path}")) - - # note, path contains a ":version" which automatically busts the cache - # based on file content, so this is safe - response.headers["Last-Modified"] = 10.years.ago.httpdate - response.headers["Content-Length"] = content.bytesize.to_s - immutable_for 1.year - - render plain: content, disposition: :nil, content_type: content_type - end - end -end diff --git a/app/controllers/discourse_rewind/rewinds_controller.rb b/app/controllers/discourse_rewind/rewinds_controller.rb index 9b57adf..f1a9cf7 100644 --- a/app/controllers/discourse_rewind/rewinds_controller.rb +++ b/app/controllers/discourse_rewind/rewinds_controller.rb @@ -4,16 +4,11 @@ module ::DiscourseRewind class RewindsController < ::ApplicationController requires_plugin PLUGIN_NAME - skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required, only: %i[show] - def show - # expires_in 1.minute, public: false - response.headers["X-Robots-Tag"] = "noindex" - DiscourseRewind::Rewind::Fetch.call(service_params) do on_success do |reports:| @reports = reports - render "show", layout: false + render json: MultiJson.dump(reports), status: 200 end end end diff --git a/app/helpers/discourse_rewind/rewinds_helper.rb b/app/helpers/discourse_rewind/rewinds_helper.rb deleted file mode 100644 index 9d2c9a6..0000000 --- a/app/helpers/discourse_rewind/rewinds_helper.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -module DiscourseRewind - module RewindsHelper - # keeping it here for caching - def self.rewind_asset_url(asset_name) - if !%w[rewind.css].include?(asset_name) - raise StandardError, "unknown asset type #{asset_name}" - end - - @urls ||= {} - url = @urls[asset_name] - return url if url - - content = File.read(DiscourseRewind.public_asset_path("css/#{asset_name}")) - sha1 = Digest::SHA1.hexdigest(content) - url = "/rewinds/assets/#{sha1}/#{asset_name}" - @urls[asset_name] = GlobalPath.cdn_path(url) - end - - def rewind_asset_url(asset_name) - DiscourseRewind::RewindsHelper.rewind_asset_url(asset_name) - end - end -end diff --git a/app/services/discourse_rewind/rewind/fetch.rb b/app/services/discourse_rewind/rewind/fetch.rb index 0011f89..7181c63 100644 --- a/app/services/discourse_rewind/rewind/fetch.rb +++ b/app/services/discourse_rewind/rewind/fetch.rb @@ -5,11 +5,7 @@ module DiscourseRewind # # @example # ::DiscourseRewind::Rewind::Fetch.call( - # guardian: guardian, - # params: { - # username: "falco", - # year: 2024, - # } + # guardian: guardian # ) # class Rewind::Fetch @@ -30,34 +26,26 @@ module DiscourseRewind CACHE_DURATION = 5.minutes - params do - attribute :year, :integer - attribute :username, :string - - validates :year, presence: true - validates :username, presence: true - end - model :user model :date model :reports private - def fetch_user(params:) - User.find_by_username(params.username) + def fetch_user(guardian:) + User.find_by_username(guardian.user.username) end def fetch_date(params:) - Date.new(params.year).all_year + Date.new(2024).all_year end - def fetch_reports(params:, date:, user:, guardian:) - key = "rewind:#{params.username}:#{params.year}" + def fetch_reports(date:, user:, guardian:) + key = "rewind:#{guardian.user.username}:#{2024}" reports = Discourse.redis.get(key) if Rails.env.development? || !reports - reports = REPORTS.map { |report| report.call(params:, date:, user:, guardian:) } + reports = REPORTS.map { |report| report.call(date:, user:, guardian:) } Discourse.redis.setex(key, CACHE_DURATION, MultiJson.dump(reports)) else reports = MultiJson.load(reports, symbolize_keys: true) diff --git a/app/views/discourse_rewind/rewinds/_posting-calendar.html.erb b/app/views/discourse_rewind/rewinds/_posting-calendar.html.erb deleted file mode 100644 index de0ffec..0000000 --- a/app/views/discourse_rewind/rewinds/_posting-calendar.html.erb +++ /dev/null @@ -1 +0,0 @@ -POSTING CALENDAR diff --git a/app/views/discourse_rewind/rewinds/_reading-time.html.erb b/app/views/discourse_rewind/rewinds/_reading-time.html.erb deleted file mode 100644 index fb26637..0000000 --- a/app/views/discourse_rewind/rewinds/_reading-time.html.erb +++ /dev/null @@ -1 +0,0 @@ -READING TIME diff --git a/app/views/discourse_rewind/rewinds/show.html.erb b/app/views/discourse_rewind/rewinds/show.html.erb deleted file mode 100644 index 1bd5823..0000000 --- a/app/views/discourse_rewind/rewinds/show.html.erb +++ /dev/null @@ -1,24 +0,0 @@ - - -
-{{report.identifier}}
+ {{/each}} +