diff --git a/app/controllers/discourse_rewind/rewinds_assets_controller.rb b/app/controllers/discourse_rewind/rewinds_assets_controller.rb new file mode 100644 index 0000000..d6ddbba --- /dev/null +++ b/app/controllers/discourse_rewind/rewinds_assets_controller.rb @@ -0,0 +1,32 @@ +# 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 new file mode 100644 index 0000000..e6d4cb6 --- /dev/null +++ b/app/controllers/discourse_rewind/rewinds_controller.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +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: true + response.headers["X-Robots-Tag"] = "noindex" + + render "show", layout: false + end + end +end diff --git a/app/controllers/my_plugin_module/examples_controller.rb b/app/controllers/my_plugin_module/examples_controller.rb deleted file mode 100644 index 9ca421b..0000000 --- a/app/controllers/my_plugin_module/examples_controller.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module ::MyPluginModule - class ExamplesController < ::ApplicationController - requires_plugin PLUGIN_NAME - - def index - render json: { hello: "world" } - end - end -end diff --git a/app/helpers/discourse_rewind/rewinds_helper.rb b/app/helpers/discourse_rewind/rewinds_helper.rb new file mode 100644 index 0000000..ce399a8 --- /dev/null +++ b/app/helpers/discourse_rewind/rewinds_helper.rb @@ -0,0 +1,30 @@ +# 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] + p "-------------" + # return url if url + + content = File.read(DiscourseRewind.public_asset_path("css/#{asset_name}")) + + p content + sha1 = Digest::SHA1.hexdigest(content) + + url = "/rewinds/assets/#{sha1}/#{asset_name}" + + p @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/views/discourse_rewind/rewinds/show.html.erb b/app/views/discourse_rewind/rewinds/show.html.erb new file mode 100644 index 0000000..590d2de --- /dev/null +++ b/app/views/discourse_rewind/rewinds/show.html.erb @@ -0,0 +1,18 @@ + + +
+