forked from e621ng/e621ng
add cdn hosted flag to posts
This commit is contained in:
parent
c01f48f18c
commit
b57b54113f
@ -21,7 +21,8 @@ class AmazonBackup < ActiveRecord::Base
|
|||||||
region: "us-east-1",
|
region: "us-east-1",
|
||||||
credentials: credentials
|
credentials: credentials
|
||||||
})
|
})
|
||||||
client = Aws::S3::Client.new
|
logger = Logger.new(STDOUT)
|
||||||
|
client = Aws::S3::Client.new(logger: logger)
|
||||||
bucket = Danbooru.config.aws_s3_bucket_name
|
bucket = Danbooru.config.aws_s3_bucket_name
|
||||||
|
|
||||||
Post.where("id > ?", last_id).limit(1000).order("id").each do |post|
|
Post.where("id > ?", last_id).limit(1000).order("id").each do |post|
|
||||||
|
@ -105,7 +105,11 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def file_url
|
def file_url
|
||||||
"/data/#{seo_tag_string}#{file_path_prefix}#{md5}.#{file_ext}"
|
if cdn_hosted?
|
||||||
|
Danbooru.config.danbooru_s3_base_url + "/#{file_path_prefix}#{md5}.#{file_ext}"
|
||||||
|
else
|
||||||
|
"/data/#{seo_tag_string}#{file_path_prefix}#{md5}.#{file_ext}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def large_file_url
|
def large_file_url
|
||||||
@ -1709,6 +1713,7 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
BOOLEAN_ATTRIBUTES = %w(
|
BOOLEAN_ATTRIBUTES = %w(
|
||||||
has_embedded_notes
|
has_embedded_notes
|
||||||
|
cdn_hosted
|
||||||
)
|
)
|
||||||
has_bit_flags BOOLEAN_ATTRIBUTES
|
has_bit_flags BOOLEAN_ATTRIBUTES
|
||||||
|
|
||||||
|
@ -1,6 +1,27 @@
|
|||||||
require 'danbooru_image_resizer/danbooru_image_resizer'
|
require 'danbooru_image_resizer/danbooru_image_resizer'
|
||||||
|
|
||||||
namespace :images do
|
namespace :images do
|
||||||
|
desc "Enable CDN"
|
||||||
|
task :enable_cdn, [:min_id, :max_id] => :environment do |t, args|
|
||||||
|
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
|
||||||
|
credentials = Aws::Credentials.new(Danbooru.config.aws_access_key_id, Danbooru.config.aws_secret_access_key)
|
||||||
|
Aws.config.update({
|
||||||
|
region: "us-east-1",
|
||||||
|
credentials: credentials
|
||||||
|
})
|
||||||
|
client = Aws::S3::Client.new
|
||||||
|
bucket = Danbooru.config.aws_s3_bucket_name
|
||||||
|
|
||||||
|
Post.where("id >= ? and id <= ?", args[:min_id], args[:max_id]).find_each do |post|
|
||||||
|
post.cdn_hosted = true
|
||||||
|
post.save
|
||||||
|
key = File.basename(post.file_path)
|
||||||
|
client.copy_object(bucket: bucket, key: key, acl: "public-read", storage_class: "STANDARD", copy_source: "/#{bucket}/#{key}", metadata_directive: "COPY")
|
||||||
|
# client.put_object(bucket: bucket, key: key, body: body, content_md5: base64_md5, acl: "public-read", storage_class: "STANDARD")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
desc "Redownload an image from Pixiv"
|
desc "Redownload an image from Pixiv"
|
||||||
task :download_pixiv => :environment do
|
task :download_pixiv => :environment do
|
||||||
post_id = ENV["id"]
|
post_id = ENV["id"]
|
||||||
|
Loading…
Reference in New Issue
Block a user