support dedicated image servers
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
# donmai.us specific
|
||||||
|
|
||||||
class ApiCacheGenerator
|
class ApiCacheGenerator
|
||||||
def generate_tag_cache
|
def generate_tag_cache
|
||||||
path = Danbooru.config.shared_dir_path
|
path = Danbooru.config.shared_dir_path
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# donmai.us specific
|
||||||
|
|
||||||
class CloudflareService
|
class CloudflareService
|
||||||
def key
|
def key
|
||||||
Danbooru.config.cloudflare_key
|
Danbooru.config.cloudflare_key
|
||||||
@@ -23,7 +25,7 @@ class CloudflareService
|
|||||||
def delete(md5, ext)
|
def delete(md5, ext)
|
||||||
url = "https://api.cloudflare.com/client/v4/zones/#{zone}/purge_cache"
|
url = "https://api.cloudflare.com/client/v4/zones/#{zone}/purge_cache"
|
||||||
files = ["#{md5}.#{ext}", "preview/#{md5}.jpg", "sample/sample-#{md5}.jpg"].map do |name|
|
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}"
|
"http://#{subdomain}.donmai.us/data/#{name}"
|
||||||
end
|
end
|
||||||
end.flatten
|
end.flatten
|
||||||
|
|||||||
@@ -16,7 +16,21 @@ class CurrentUser
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.as_admin(&block)
|
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
|
end
|
||||||
|
|
||||||
def self.user=(user)
|
def self.user=(user)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# donmai.us specific
|
||||||
|
|
||||||
require 'base64'
|
require 'base64'
|
||||||
require 'digest/md5'
|
require 'digest/md5'
|
||||||
|
|
||||||
|
|||||||
@@ -145,29 +145,16 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def file_url
|
def file_url
|
||||||
if Danbooru.config.use_s3_proxy?(self)
|
"#{Danbooru.config.image_server_host(self)}/data/#{seo_tag_string}#{file_path_prefix}#{md5}.#{file_ext}"
|
||||||
"/cached/data/#{seo_tag_string}#{file_path_prefix}#{md5}.#{file_ext}"
|
|
||||||
else
|
|
||||||
"/data/#{seo_tag_string}#{file_path_prefix}#{md5}.#{file_ext}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# this is for the 640x320 version
|
# this is for the 640x320 version
|
||||||
def cropped_file_url
|
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
|
end
|
||||||
|
|
||||||
def large_file_url
|
def large_file_url
|
||||||
if has_large?
|
if has_large?
|
||||||
if Danbooru.config.use_s3_proxy?(self)
|
"#{Danbooru.config.image_server_host(self)}/data/sample/#{seo_tag_string}#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.#{large_file_ext}"
|
||||||
"/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
|
|
||||||
else
|
else
|
||||||
file_url
|
file_url
|
||||||
end
|
end
|
||||||
@@ -190,11 +177,7 @@ class Post < ApplicationRecord
|
|||||||
return "/images/download-preview.png"
|
return "/images/download-preview.png"
|
||||||
end
|
end
|
||||||
|
|
||||||
# if has_cropped? && !CurrentUser.disable_cropped_thumbnails?
|
"/data/preview/#{file_path_prefix}#{md5}.jpg"
|
||||||
# "/cached/data/cropped/small/#{md5}.jpg"
|
|
||||||
# else
|
|
||||||
"/data/preview/#{file_path_prefix}#{md5}.jpg"
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def complete_preview_file_url
|
def complete_preview_file_url
|
||||||
@@ -204,9 +187,17 @@ class Post < ApplicationRecord
|
|||||||
def open_graph_image_url
|
def open_graph_image_url
|
||||||
if is_image?
|
if is_image?
|
||||||
if has_large?
|
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
|
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
|
end
|
||||||
else
|
else
|
||||||
complete_preview_file_url
|
complete_preview_file_url
|
||||||
|
|||||||
@@ -217,6 +217,10 @@ module Danbooru
|
|||||||
"albert"
|
"albert"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def image_server_host(post)
|
||||||
|
""
|
||||||
|
end
|
||||||
|
|
||||||
#TAG CONFIGURATION
|
#TAG CONFIGURATION
|
||||||
|
|
||||||
#Full tag configuration info for all tags
|
#Full tag configuration info for all tags
|
||||||
|
|||||||
Reference in New Issue
Block a user