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