32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/controllers/xmt_froala/assets_controller.rb', line 32
def list
root_url = File.join('/', XmtFroala.upload_store_dir)
root_url = File.join(root_url, params[:dir]) unless params[:dir].blank?
root_url.split('/').each do |dir|
path ||= Rails.public_path
path = File.join(path, dir)
Dir.mkdir(path) unless Dir.exist?(path)
end
root_url = File.join(root_url, params[:path]) unless params[:path].blank?
root_path = File.join( Rails.public_path, root_url)
file_list = []
Dir.foreach(root_path) do |entry|
next if (entry == '..' || entry == '.')
full_path = File.join(root_path, entry)
file_ext = File.extname(full_path).gsub(/\./,"")
info = {
filename: entry,
datetime: File.mtime(full_path).to_s(:db)
}
if File.directory?(full_path)
info[:is_dir] = true
info[:has_file] = Dir.entries(full_path).size > 0
info[:filesize] = 0
info[:is_photo] = false
info[:filetype] = ""
else
info[:is_dir] = false
info[:has_file] = false
info[:filesize] = File.size(full_path)
info[:dir_path] = ""
info[:is_photo] = XmtFroala::AssetUploader.is_image?(file_ext)
info[:filetype] = file_ext
end
file_list << info
end
order = "filename"
unless params[:order].blank?
order = params[:order].downcase if %w(filename filesize filetype datetime).include?(params[:order].downcase)
end
if order=='datetime'
file_list.sort! {|a, b| b["#{order}".to_sym] <=> a["#{order}".to_sym]}
else
file_list.sort! {|a, b| a["#{order}".to_sym] <=> b["#{order}".to_sym]}
end
result = {
moveup_dir_path: params[:path].gsub(/(.*?)[^\/]+\/$/, ""),
current_dir_path: params[:path],
current_url: root_url,
total_count: file_list.count,
file_list: file_list
}
render json: result
end
|