diff options
author | Claire <claire.github-309c@sitedethib.com> | 2023-03-16 23:12:59 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2023-03-16 23:12:59 +0100 |
commit | 193250556cb4e6b1b3e2f9bd1ac023b290176fd4 (patch) | |
tree | 3bd6148ff028b8fe089cae9d805a7e587eaeec11 /lib | |
parent | f5daa20f2a90098c9d689c5ec9d95ce9887b3a33 (diff) | |
parent | 681dcd3fa35e886a21853ca829ff1be7f220e83a (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `README.md`: Upstream changed their README, we have our own. Kept ours. - `app/helpers/application_helper.rb`: Minor code style fix upstream, on a line that is different in glitch-soc due to the different theming system. Applied the code style fix to our own code. - `app/views/settings/preferences/appearance/show.html.haml`: Code style fix on a line next to lines exclusive to glitch-soc. Applied upstream changes. - `yarn.lock`: Upstream updated a dependency textually close to a glitch-soc-only dependency. Updated the dependency like upstream did.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mastodon/media_cli.rb | 2 | ||||
-rw-r--r-- | lib/public_file_server_middleware.rb | 43 | ||||
-rw-r--r-- | lib/tasks/emojis.rake | 4 |
3 files changed, 45 insertions, 4 deletions
diff --git a/lib/mastodon/media_cli.rb b/lib/mastodon/media_cli.rb index fc70c8785..b2dfe58d5 100644 --- a/lib/mastodon/media_cli.rb +++ b/lib/mastodon/media_cli.rb @@ -35,7 +35,6 @@ module Mastodon follow status. By default, only accounts that are not followed by or following anyone locally are pruned. DESC - # rubocop:disable Metrics/PerceivedComplexity def remove if options[:prune_profiles] && options[:remove_headers] say('--prune-profiles and --remove-headers should not be specified simultaneously', :red, true) @@ -224,7 +223,6 @@ module Mastodon say("Removed #{removed} orphans (approx. #{number_to_human_size(reclaimed_bytes)})#{dry_run}", :green, true) end - # rubocop:enable Metrics/PerceivedComplexity option :account, type: :string option :domain, type: :string diff --git a/lib/public_file_server_middleware.rb b/lib/public_file_server_middleware.rb new file mode 100644 index 000000000..3799230a2 --- /dev/null +++ b/lib/public_file_server_middleware.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'action_dispatch/middleware/static' + +class PublicFileServerMiddleware + SERVICE_WORKER_TTL = 7.days.to_i + CACHE_TTL = 28.days.to_i + + def initialize(app) + @app = app + @file_handler = ActionDispatch::FileHandler.new(Rails.application.paths['public'].first) + end + + def call(env) + file = @file_handler.attempt(env) + + # If the request is not a static file, move on! + return @app.call(env) if file.nil? + + status, headers, response = file + + # Set cache headers on static files. Some paths require different cache headers + headers['Cache-Control'] = begin + request_path = env['REQUEST_PATH'] + + if request_path.start_with?('/sw.js') + "public, max-age=#{SERVICE_WORKER_TTL}, must-revalidate" + elsif request_path.start_with?(paperclip_root_url) + "public, max-age=#{CACHE_TTL}, immutable" + else + "public, max-age=#{CACHE_TTL}, must-revalidate" + end + end + + [status, headers, response] + end + + private + + def paperclip_root_url + ENV.fetch('PAPERCLIP_ROOT_URL', '/system') + end +end diff --git a/lib/tasks/emojis.rake b/lib/tasks/emojis.rake index c743f8a55..fbb2e8d4f 100644 --- a/lib/tasks/emojis.rake +++ b/lib/tasks/emojis.rake @@ -6,7 +6,7 @@ def gen_border(codepoint, color) doc = File.open(input) { |f| Nokogiri::XML(f) } svg = doc.at_css('svg') if svg.key?('viewBox') - view_box = svg['viewBox'].split(' ').map(&:to_i) + view_box = svg['viewBox'].split.map(&:to_i) view_box[0] -= 2 view_box[1] -= 2 view_box[2] += 4 @@ -36,7 +36,7 @@ end def codepoints_to_unicode(codepoints) if codepoints.include?(' ') - codepoints.split(' ').map(&:hex).pack('U*') + codepoints.split.map(&:hex).pack('U*') else [codepoints.hex].pack('U') end |