You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
module Util::FileManage
|
|
module_function
|
|
|
|
# 不同的类型扩展不同的目录
|
|
def relative_path
|
|
"avatars"
|
|
end
|
|
|
|
def storage_path
|
|
File.join(Rails.root, "public", "images", relative_path)
|
|
end
|
|
|
|
def disk_filename(source_type, source_id,image_file=nil)
|
|
File.join(storage_path, "#{source_type}", "#{source_id}")
|
|
end
|
|
|
|
def exist?(source_type, source_id)
|
|
File.exist?(disk_filename(source_type, source_id))
|
|
end
|
|
|
|
def disk_file_url(source_type, source_id)
|
|
File.join('/images', relative_path, "#{source_type}", "#{source_id}")
|
|
end
|
|
|
|
def disk_auth_filename(source_type, source_id, type)
|
|
File.join(storage_path, "#{source_type}", "#{source_id}#{type}")
|
|
end
|
|
|
|
def disk_real_name_auth_filename(source_id)
|
|
disk_auth_filename('UserAuthentication', source_id, 'ID')
|
|
end
|
|
|
|
def auth_file_url(source_type, source_id, type)
|
|
File.join('/images', relative_path, source_type, "#{source_id}#{type}")
|
|
end
|
|
|
|
def real_name_auth_file_url(source_id)
|
|
auth_file_url('UserAuthentication', source_id, 'ID')
|
|
end
|
|
|
|
def disk_professional_auth_filename(source_id)
|
|
disk_auth_filename('UserAuthentication', source_id, 'PRO')
|
|
end
|
|
|
|
def professional_auth_file_url(source_id)
|
|
auth_file_url('UserAuthentication', source_id, 'PRO')
|
|
end
|
|
end |