Merge pull request #3779 from r888888888/storage-manager-match
Add matching storage manager
This commit is contained in:
@@ -72,7 +72,8 @@ class StorageManager
|
|||||||
origin
|
origin
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_path(md5, file_ext, type)
|
def file_path(post_or_md5, file_ext, type)
|
||||||
|
md5 = post_or_md5.is_a?(String) ? post_or_md5 : post_or_md5.md5
|
||||||
subdir = subdir_for(md5)
|
subdir = subdir_for(md5)
|
||||||
file = file_name(md5, file_ext, type)
|
file = file_name(md5, file_ext, type)
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,6 @@ syntax. Matches are executed in order of appearance so the first
|
|||||||
matching manager is returned. You should always add at least one
|
matching manager is returned. You should always add at least one
|
||||||
manager with no constraints as a default case.
|
manager with no constraints as a default case.
|
||||||
|
|
||||||
This does not derive from StorageManager so only `open_file`,
|
|
||||||
`delete_file`, `store_file`, `file_url`, and `file_path` are
|
|
||||||
implemented.
|
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
StorageManager::Match.new do |matcher|
|
StorageManager::Match.new do |matcher|
|
||||||
@@ -35,7 +31,7 @@ implemented.
|
|||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
class StorageManager::Match
|
class StorageManager::Match < StorageManager
|
||||||
def initialize
|
def initialize
|
||||||
@managers = []
|
@managers = []
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ require 'mail'
|
|||||||
|
|
||||||
class UploadErrorChecker
|
class UploadErrorChecker
|
||||||
def check!
|
def check!
|
||||||
uploads = Upload.where("status like 'error%' and status not like 'error: Upload::Error - Post with MD5%' and status not like 'error: RuntimeError - duplicate%' and created_at >= ?", 1.hour.ago)
|
uploads = Upload.where("status like 'error%' and status not like 'error: Upload::Error - Post with MD5%' and status not like 'error: RuntimeError - duplicate%' and status not like 'error: ActiveRecord::RecordInvalid - Validation failed: Md5 has already been taken' and created_at >= ?", 1.hour.ago)
|
||||||
if uploads.size > 5
|
if uploads.size > 5
|
||||||
mail = Mail.new do
|
mail = Mail.new do
|
||||||
from Danbooru.config.contact_email
|
from Danbooru.config.contact_email
|
||||||
|
|||||||
@@ -162,15 +162,15 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def file_path
|
def file_path
|
||||||
storage_manager.file_path(md5, file_ext, :original)
|
storage_manager.file_path(self, file_ext, :original)
|
||||||
end
|
end
|
||||||
|
|
||||||
def large_file_path
|
def large_file_path
|
||||||
storage_manager.file_path(md5, file_ext, :large)
|
storage_manager.file_path(self, file_ext, :large)
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview_file_path
|
def preview_file_path
|
||||||
storage_manager.file_path(md5, file_ext, :preview)
|
storage_manager.file_path(self, file_ext, :preview)
|
||||||
end
|
end
|
||||||
|
|
||||||
def crop_file_url
|
def crop_file_url
|
||||||
|
|||||||
Reference in New Issue
Block a user