support dedicated image servers

This commit is contained in:
r888888888
2018-01-03 11:42:08 -08:00
parent 3a5eaad685
commit af6ab74f8d
6 changed files with 39 additions and 24 deletions

View File

@@ -1,3 +1,5 @@
# donmai.us specific
class ApiCacheGenerator
def generate_tag_cache
path = Danbooru.config.shared_dir_path

View File

@@ -1,3 +1,5 @@
# donmai.us specific
class CloudflareService
def key
Danbooru.config.cloudflare_key
@@ -23,7 +25,7 @@ class CloudflareService
def delete(md5, ext)
url = "https://api.cloudflare.com/client/v4/zones/#{zone}/purge_cache"
files = ["#{md5}.#{ext}", "preview/#{md5}.jpg", "sample/sample-#{md5}.jpg"].map do |name|
["danbooru", "safebooru"].map do |subdomain|
["danbooru", "safebooru", "raikou1"].map do |subdomain|
"http://#{subdomain}.donmai.us/data/#{name}"
end
end.flatten

View File

@@ -16,7 +16,21 @@ class CurrentUser
end
def self.as_admin(&block)
scoped(User.admins.first, "127.0.0.1", &block)
if block_given?
scoped(User.admins.first, "127.0.0.1", &block)
else
self.user = User.admins.first
self.ip_addr = "127.0.0.1"
end
end
def self.as_system(&block)
if block_given?
scoped(User.system, "127.0.0.1", &block)
else
self.user = User.system
self.ip_addr = "127.0.0.1"
end
end
def self.user=(user)

View File

@@ -1,3 +1,5 @@
# donmai.us specific
require 'base64'
require 'digest/md5'

View File

@@ -145,29 +145,16 @@ class Post < ApplicationRecord
end
def file_url
if Danbooru.config.use_s3_proxy?(self)
"/cached/data/#{seo_tag_string}#{file_path_prefix}#{md5}.#{file_ext}"
else
"/data/#{seo_tag_string}#{file_path_prefix}#{md5}.#{file_ext}"
end
"#{Danbooru.config.image_server_host(self)}/data/#{seo_tag_string}#{file_path_prefix}#{md5}.#{file_ext}"
end
# this is for the 640x320 version
def cropped_file_url
if Danbooru.config.use_s3_proxy?(self)
"/cached/data/cropped/large/#{md5}.jpg"
else
"/data/cropped/large/#{md5}.jpg"
end
end
def large_file_url
if has_large?
if Danbooru.config.use_s3_proxy?(self)
"/cached/data/sample/#{seo_tag_string}#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.#{large_file_ext}"
else
"/data/sample/#{seo_tag_string}#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.#{large_file_ext}"
end
"#{Danbooru.config.image_server_host(self)}/data/sample/#{seo_tag_string}#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.#{large_file_ext}"
else
file_url
end
@@ -190,11 +177,7 @@ class Post < ApplicationRecord
return "/images/download-preview.png"
end
# if has_cropped? && !CurrentUser.disable_cropped_thumbnails?
# "/cached/data/cropped/small/#{md5}.jpg"
# else
"/data/preview/#{file_path_prefix}#{md5}.jpg"
# end
"/data/preview/#{file_path_prefix}#{md5}.jpg"
end
def complete_preview_file_url
@@ -204,9 +187,17 @@ class Post < ApplicationRecord
def open_graph_image_url
if is_image?
if has_large?
"http://#{Danbooru.config.hostname}#{large_file_url}"
if Danbooru.config.image_server_host(self) =~ /http/
large_file_url
else
"http://#{Danbooru.config.hostname}#{large_file_url}"
end
else
"http://#{Danbooru.config.hostname}#{file_url}"
if Danbooru.config.image_server_host(self) =~ /http/
file_url
else
"http://#{Danbooru.config.hostname}#{file_url}"
end
end
else
complete_preview_file_url

View File

@@ -217,6 +217,10 @@ module Danbooru
"albert"
end
def image_server_host(post)
""
end
#TAG CONFIGURATION
#Full tag configuration info for all tags