fixes #3560
This commit is contained in:
@@ -7,6 +7,24 @@ class RemoteFileManager
|
|||||||
@path = path
|
@path = path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def distribute_to_archive(dest_url)
|
||||||
|
uri = URI.parse(dest_url)
|
||||||
|
dir_name = uri.host.split(".").first
|
||||||
|
uuid = SecureRandom.uuid
|
||||||
|
dest_path = "/var/www/#{dir_name}#{uri.path}"
|
||||||
|
temp_path = "/tmp/rfm-#{Danbooru.config.server_host}-#{uuid}"
|
||||||
|
|
||||||
|
Net::SFTP.start(uri.host, Danbooru.config.archive_server_login) do |ftp|
|
||||||
|
ftp.upload!(path, temp_path)
|
||||||
|
begin
|
||||||
|
ftp.rename!(temp_path, dest_path)
|
||||||
|
rescue Net::SFTP::StatusException
|
||||||
|
ftp.remove!(dest_path)
|
||||||
|
ftp.rename!(temp_apth, dest_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def distribute
|
def distribute
|
||||||
uuid = SecureRandom.uuid
|
uuid = SecureRandom.uuid
|
||||||
temp_path = "/tmp/rfm-#{Danbooru.config.server_host}-#{uuid}"
|
temp_path = "/tmp/rfm-#{Danbooru.config.server_host}-#{uuid}"
|
||||||
|
|||||||
@@ -107,9 +107,16 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def distribute_files
|
def distribute_files
|
||||||
RemoteFileManager.new(file_path).distribute
|
if Danbooru.config.build_file_url(self) =~ /^http/
|
||||||
RemoteFileManager.new(preview_file_path).distribute if has_preview?
|
# this post is archived
|
||||||
RemoteFileManager.new(large_file_path).distribute if has_large?
|
RemoteFileManager.new(file_path).distribute_to_archive(Danbooru.config.build_file_url(self))
|
||||||
|
RemoteFileManager.new(preview_file_path).distribute if has_preview?
|
||||||
|
RemoteFileManager.new(large_file_path).distribute_to_archive(Danbooru.config.build_large_file_url(self)) if has_large?
|
||||||
|
else
|
||||||
|
RemoteFileManager.new(file_path).distribute
|
||||||
|
RemoteFileManager.new(preview_file_path).distribute if has_preview?
|
||||||
|
RemoteFileManager.new(large_file_path).distribute if has_large?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_path_prefix
|
def file_path_prefix
|
||||||
|
|||||||
@@ -217,6 +217,10 @@ module Danbooru
|
|||||||
"albert"
|
"albert"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def archive_server_login
|
||||||
|
"danbooru"
|
||||||
|
end
|
||||||
|
|
||||||
def build_file_url(post)
|
def build_file_url(post)
|
||||||
"/data/#{post.file_path_prefix}/#{post.md5}.#{post.file_ext}"
|
"/data/#{post.file_path_prefix}/#{post.md5}.#{post.file_ext}"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user