diff --git a/app/logical/e621_status_updater.rb b/app/logical/e621_status_updater.rb index e8c9e16..fac2b89 100644 --- a/app/logical/e621_status_updater.rb +++ b/app/logical/e621_status_updater.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true module E621StatusUpdater - def self.run + def self.run(force: E621Status.count == 0) return if Rails.env.development? status = Requests::E621.status previous_status = Cache.redis.get("e621_status:current").to_i last_change_time = Cache.redis.get("e621_status:last_change_time") last_change_time = Time.parse(last_change_time) if last_change_time.present? - if previous_status == status + if previous_status == status && !force Cache.redis.set("e621_status:last_change_time", (Time.now - 2.seconds).to_s) - elsif last_change_time.nil? || (Time.now - last_change_time) >= 3.minutes + elsif last_change_time.nil? || (Time.now - last_change_time) >= 3.minutes || force Rails.logger.debug { "Updating status: #{previous_status} -> #{status}" } Cache.redis.set("e621_status:current", status.to_s) Cache.redis.set("e621_status:last_change_time", (Time.now - 2.seconds).to_s) diff --git a/config/default_config.rb b/config/default_config.rb index 7d23161..1ebd1a3 100644 --- a/config/default_config.rb +++ b/config/default_config.rb @@ -136,7 +136,7 @@ module Websites def common_headers(domain) { - "Report-To": { + "Report-To": { group: "default", max_age: 31_536_000, endpoints: [ @@ -144,23 +144,23 @@ module Websites ], include_subdomains: true, }.to_json, - "NEL": { + "NEL": { report_to: "default", max_age: 31_536_000, include_subdomains: true, }.to_json, - "Strict-Transport-Security": "max-age=63072000; includeSubDomains; preload", - "Expect-CT": "max-age=63072000, enforce, report-uri=\"https://yiff.report-uri.com/r/d/ct/enforce\"", - "Upgrade-Insecure-Requests": "1", - "Referrer-Policy": "strict-origin-when-cross-origin", - "X-XSS-Protection": "0", + "Strict-Transport-Security": "max-age=63072000; includeSubDomains; preload", + "Expect-CT": "max-age=63072000, enforce, report-uri=\"https://yiff.report-uri.com/r/d/ct/enforce\"", + "Upgrade-Insecure-Requests": "1", + "Referrer-Policy": "strict-origin-when-cross-origin", + "X-XSS-Protection": "0", "X-Permitted-Cross-Domain-Policies": "none", - "Access-Control-Allow-Headers": "Content-Type, Authorization", - "Access-Control-Allow-Origin": "*", - "Access-Control-Allow-Methods": "GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS", - "X-Frame-Options": "DENY", - "X-Content-Type-Options": "nosniff", - "X-Feature-Policy": [ + "Access-Control-Allow-Headers": "Content-Type, Authorization", + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS", + "X-Frame-Options": "DENY", + "X-Content-Type-Options": "nosniff", + "X-Feature-Policy": [ "accelerometer 'none'", "ambient-light-sensor 'none'", "autoplay 'none'", @@ -195,7 +195,7 @@ module Websites "screen-wake-lock 'none'", "xr-spatial-tracking 'none'", ].join("; "), - "Content-Security-Policy": [ + "Content-Security-Policy": [ "default-src 'self' #{domain} *.#{domain}", "script-src 'self' 'unsafe-inline' #{domain} *.#{domain} https://cdnjs.cloudflare.com https://static.cloudflareinsights.com", "style-src 'self' 'unsafe-inline' #{domain} *.#{domain} https://cdnjs.cloudflare.com https://fonts.googleapis.com", diff --git a/config/initializers/log_tags.rb b/config/initializers/log_tags.rb index f308e93..d097a15 100644 --- a/config/initializers/log_tags.rb +++ b/config/initializers/log_tags.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module RequestExtension def forwarded_host headers["X-Forwarded-Host"] || host diff --git a/config/routes/e621_ws_routes.rb b/config/routes/e621_ws_routes.rb index 70daf68..52086a4 100644 --- a/config/routes/e621_ws_routes.rb +++ b/config/routes/e621_ws_routes.rb @@ -37,7 +37,6 @@ module E621WsRoutes get(:browserconfig, constraints: { format: "xml" }) root(action: :index) end - end end end diff --git a/lib/custom_static_middleware.rb b/lib/custom_static_middleware.rb index 1438f8a..5c31db6 100644 --- a/lib/custom_static_middleware.rb +++ b/lib/custom_static_middleware.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CustomStaticMiddleware def initialize(app, domain_map) @app = app diff --git a/lib/tasks/e621.rake b/lib/tasks/e621.rake index 220b76c..d09be58 100644 --- a/lib/tasks/e621.rake +++ b/lib/tasks/e621.rake @@ -7,7 +7,7 @@ namespace :e621 do end task remove_timeouts: :environment do - E621Thumbnail.where(status: "timeout", created_at: ..10.minutes.ago).find_each do |entry| + E621Thumbnail.where(status: "timeout", created_at: ..5.minutes.ago).find_each do |entry| puts "Removing timed out generation for post #{entry.post_id} (#{entry.stripped_md5}" entry.destroy end