allow forcing the creation of an e621 status change

This commit is contained in:
Donovan Daniels 2024-05-03 00:54:36 -05:00
parent e7518a5c0f
commit 107acfb155
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
6 changed files with 21 additions and 19 deletions

View File

@ -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)

View File

@ -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",

View File

@ -1,4 +1,5 @@
# frozen_string_literal: true
module RequestExtension
def forwarded_host
headers["X-Forwarded-Host"] || host

View File

@ -37,7 +37,6 @@ module E621WsRoutes
get(:browserconfig, constraints: { format: "xml" })
root(action: :index)
end
end
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CustomStaticMiddleware
def initialize(app, domain_map)
@app = app

View File

@ -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