# frozen_string_literal: true module Websites class Configuration def version GitHelper.short_hash end def full_version GitHelper.full_hash end def version_link GitHelper.commit_url(GitHelper.short_hash) end def readonly? false end def source_code_url "https://git.furry.cool/Donovan_DMC/Websites" end def e621_status_check_discord_id end def e621_status_check_discord_secret end def e621_status_check_discord_redirect return "http://websites4.containers.local:3000/webhook/discord/cb?domain=status.e621.ws" if Rails.env.development? "https://status.e621.ws/webhook/discord/cb" end def e621_status_check_discord_scopes { min: %w[webhook.incoming], all: %w[identify webhook.incoming], } end def e621_status_check_discord_icon Base64.encode64(Rails.root.join("app/assets/images/e621.ws/icon.png").read) end def e621_status_check_logs_webhook # Requests::DiscordWebhook.new(id: "", token: "") end def redis_url "redis://redis.websites4.containers.local/0" end def opensearch_host "opensearch.websites4.containers.local" end def iqdb_server "http://iqdb.websites4.containers.local:5588" end def github_webhook_secret end def blocked_ip_addresses [] end def yiffyapi_usage_webhook # Requests::DiscordWebhook.new(id: "", token: "") end def yiffyapi_ratelimit_webhook # Requests::DiscordWebhook.new(id: "", token: "") end def yiffyapi_discord_redirect(type) return "http://websites4.containers.local:3000/#{type}?domain=discord.yiff.rest" if Rails.env.development? "https://discord.yiff.rest/#{type}" end def yiffyapi_discord_scopes(type) case type when "count_servers" %w[identify guilds] else %w[identify] end end def yiffyapi_apikey_logs_webhook # Requests::DiscordWebhook.new(id: "", token: "") end def yiffyapi_image_logs_webhook # Requests::DiscordWebhook.new(id: "", token: "") end def yiffyapi_apikey_shortener_webhook # Requests::DiscordWebhook.new(id: "", token: "") end def yiffyapi_administrators %w[242843345402069002] end def yiffyapi_public_key end def yiffyapi_discord_id end def yiffyapi_discord_secret end def yiffyapi_discord_guild end def e621_thumbnails_access_key end def e621_thumbnails_storage_zone_name end def e621_thumbnails_webhook # Requests::DiscordWebhook.new(id: "", token: "") end # gifs are unpredictable, prone to timing out and HUGE file sizes -for instance, https://e621.net/posts/4693107 took ~300 seconds # to fully generate and be optimized, and produced a 270MB file which is completely unusable def e621_thumbnails_disable_gif true end def pastebin_dev_key end def pastebin_user_key end def pastebin_folder end def common_headers(domain) # We don't want to set headers like HSTS in development return {} if Rails.env.development? { "Report-To": { group: "default", max_age: 31_536_000, endpoints: [ { url: "https://yiff.report-uri.com/a/d/g" }, ], include_subdomains: true, }.to_json, "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", "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": [ "accelerometer 'none'", "ambient-light-sensor 'none'", "autoplay 'none'", "battery 'none'", "camera 'none'", "display-capture 'none'", "document-domain 'none'", "encrypted-media 'none'", "execution-while-not-rendered 'none'", "execution-while-out-of-viewport 'none'", "fullscreen 'none'", "gamepad 'none'", "geolocation 'none'", "gyroscope 'none'", "layout-animations 'none'", "legacy-image-formats 'none'", "magnetometer 'none'", "microphone 'none'", "midi 'none'", "navigation-override 'none'", "oversied-images 'none'", "payment 'none'", "picture-in-picture 'none'", "publickey-credentials-get 'none'", "speaker-selection 'none'", "sync-xhr 'none'", "unoptimized-images 'none'", "unsized-media 'none'", "usb 'none'", "vr 'none'", "vibrate 'none'", "screen-wake-lock 'none'", "xr-spatial-tracking 'none'", ].join("; "), "Content-Security-Policy": [ "default-src 'self' #{domain} *.#{domain}", "script-src 'self' 'unsafe-inline' #{domain} *.#{domain} https://cdnjs.cloudflare.com https://static.cloudflareinsights.com https://plausible.furry.computer", "connect-src 'self' https://plausible.furry.computer", "style-src 'self' 'unsafe-inline' #{domain} *.#{domain} https://cdnjs.cloudflare.com https://fonts.googleapis.com", "img-src 'self' https: data:", "font-src 'self' https: data:", "report-uri https://yiff.report-uri.com/r/d/csp/enforce", "report-to default", "upgrade-insecure-requests", "block-all-mixed-content", "require-sri-for script style", ].join("; "), } end def http_headers { "User-Agent" => "Websites/4.0.0 (https://github.com/DonovanDMC/Websites; \"donovan_dmc\")", } end def httparty_options { timeout: 10, open_timout: 5, headers: http_headers, } end # https://lostisland.github.io/faraday/#/customization/connection-options def faraday_options { request: { timeout: 10, open_timeout: 5, }, headers: http_headers, } end def yiffy2_cdn_url return "http://yiffy2.local" if Rails.env.development? "https://v2.yiff.media" end def yiffy2_bucket_name end def yiffy2_access_key_id end def yiffy2_secret_access_key end def yiffy2_s3_endpoint end def e621_thumbnails_storage StorageManager::Local.new(base_url: "https://thumbs.yiff.media", base_path: "/data/e621-thumbnails") end def e621_thumbnails_backup_storage StorageManager::Null.new end def yiffy2_storage StorageManager::Local.new(base_url: yiffy2_cdn_url, base_path: "/data/yiffy2") end def yiffy2_backup_storage StorageManager::Null.new end def yiffy2_discord_invite "https://discord.gg/3CRwffZySz" end def personal_discord_invite "https://discord.gg/naPv33pBmh" end def e621_username end def e621_apikey end def admin_domain end def enable_analytics Rails.env.production? end def plausible_script(domain) %() end end class EnvironmentConfiguration def custom_configuration @custom_configuration ||= CustomConfiguration.new end def env_to_boolean(method, var) is_boolean = method.to_s.end_with?("?") return true if is_boolean && var.truthy? return false if is_boolean && var.falsy? var end def method_missing(method, *) var = ENV.fetch("WEBSITES_#{method.to_s.upcase.chomp('?')}", nil) if var.present? env_to_boolean(method, var) else custom_configuration.send(method, *) end end end def config @config ||= EnvironmentConfiguration.new end module_function :config end