discourse/lib/file_store/base_store.rb

80 lines
1.6 KiB
Ruby
Raw Normal View History

2013-11-05 12:04:47 -06:00
module FileStore
class BaseStore
2014-04-15 06:04:14 -05:00
def store_upload(file, upload, content_type = nil)
2015-05-29 11:39:47 -05:00
path = get_path_for_upload(upload)
store_file(file, path)
2013-11-05 12:04:47 -06:00
end
def store_optimized_image(file, optimized_image)
2015-05-29 11:39:47 -05:00
path = get_path_for_optimized_image(optimized_image)
store_file(file, path)
end
def store_file(file, path, opts = {})
2013-11-05 12:04:47 -06:00
end
def remove_upload(upload)
2015-05-29 11:39:47 -05:00
remove_file(upload.url)
2013-11-05 12:04:47 -06:00
end
def remove_optimized_image(optimized_image)
2015-05-29 11:39:47 -05:00
remove_file(optimized_image.url)
end
def remove_file(url)
2013-11-05 12:04:47 -06:00
end
def has_been_uploaded?(url)
end
2015-05-29 11:39:47 -05:00
def download_url(upload)
2013-11-05 12:04:47 -06:00
end
2015-05-29 11:39:47 -05:00
def cdn_url(url)
url
2013-11-05 12:04:47 -06:00
end
2015-05-29 11:39:47 -05:00
def absolute_base_url
end
def relative_base_url
end
2013-11-05 12:04:47 -06:00
def external?
end
def internal?
2015-05-29 11:39:47 -05:00
!external?
2013-11-05 12:04:47 -06:00
end
def path_for(upload)
end
def download(upload)
end
2013-11-27 15:01:41 -06:00
def purge_tombstone(grace_period)
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
2013-11-05 12:04:47 -06:00
end
end