mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: automatically growing uploads tree
This commit is contained in:
@ -48,6 +48,22 @@ module FileStore
|
||||
url
|
||||
end
|
||||
|
||||
def get_path_for(type, id, sha, extension)
|
||||
depth = [0, Math.log(id / 1_000.0, 16).ceil].max
|
||||
tree = File.join(*sha[0, depth].split(""), "")
|
||||
"#{type}/#{depth + 1}X/#{tree}#{sha}#{extension}"
|
||||
end
|
||||
|
||||
def get_path_for_upload(upload)
|
||||
get_path_for("original".freeze, upload.id, upload.sha1, upload.extension)
|
||||
end
|
||||
|
||||
def get_path_for_optimized_image(optimized_image)
|
||||
upload = optimized_image.upload
|
||||
extension = "_#{OptimizedImage::VERSION}_#{optimized_image.width}x#{optimized_image.height}#{optimized_image.extension}"
|
||||
get_path_for("optimized".freeze, upload.id, upload.sha1, extension)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -5,12 +5,12 @@ module FileStore
|
||||
class LocalStore < BaseStore
|
||||
|
||||
def store_upload(file, upload, content_type = nil)
|
||||
path = get_path_for_upload(file, upload)
|
||||
path = get_path_for_upload(upload)
|
||||
store_file(file, path)
|
||||
end
|
||||
|
||||
def store_optimized_image(file, optimized_image)
|
||||
path = get_path_for_optimized_image(file, optimized_image)
|
||||
path = get_path_for_optimized_image(optimized_image)
|
||||
store_file(file, path)
|
||||
end
|
||||
|
||||
@ -57,17 +57,8 @@ module FileStore
|
||||
|
||||
private
|
||||
|
||||
def get_path_for_upload(file, upload)
|
||||
get_path_for("original".freeze, upload.sha1, upload.extension)
|
||||
end
|
||||
|
||||
def get_path_for_optimized_image(file, optimized_image)
|
||||
extension = "_#{optimized_image.width}x#{optimized_image.height}#{optimized_image.extension}"
|
||||
get_path_for("optimized".freeze, optimized_image.sha1, extension)
|
||||
end
|
||||
|
||||
def get_path_for(type, sha, extension)
|
||||
"#{relative_base_url}/#{type}/#{sha[0]}/#{sha[1]}/#{sha}#{extension}"
|
||||
def get_path_for(type, upload_id, sha, extension)
|
||||
"#{relative_base_url}/#{super(type, upload_id, sha, extension)}"
|
||||
end
|
||||
|
||||
def store_file(file, path)
|
||||
|
@ -14,12 +14,12 @@ module FileStore
|
||||
end
|
||||
|
||||
def store_upload(file, upload, content_type=nil)
|
||||
path = get_path_for_upload(file, upload)
|
||||
path = get_path_for_upload(upload)
|
||||
store_file(file, path, filename: upload.original_filename, content_type: content_type, cache_locally: true)
|
||||
end
|
||||
|
||||
def store_optimized_image(file, optimized_image)
|
||||
path = get_path_for_optimized_image(file, optimized_image)
|
||||
path = get_path_for_optimized_image(optimized_image)
|
||||
store_file(file, path)
|
||||
end
|
||||
|
||||
@ -94,19 +94,6 @@ module FileStore
|
||||
|
||||
private
|
||||
|
||||
def get_path_for_upload(file, upload)
|
||||
get_path_for("original".freeze, upload.sha1, upload.extension)
|
||||
end
|
||||
|
||||
def get_path_for_optimized_image(file, optimized_image)
|
||||
extension = "_#{optimized_image.width}x#{optimized_image.height}#{optimized_image.extension}"
|
||||
get_path_for("optimized".freeze, optimized_image.sha1, extension)
|
||||
end
|
||||
|
||||
def get_path_for(type, sha, extension)
|
||||
"#{type}/#{sha[0]}/#{sha[1]}/#{sha}#{extension}"
|
||||
end
|
||||
|
||||
# options
|
||||
# - filename
|
||||
# - content_type
|
||||
|
Reference in New Issue
Block a user