Add thumbnails and related adjustments
This commit is contained in:
parent
c3588b347e
commit
66b8f22a1e
|
|
@ -274,7 +274,13 @@ class Admin::FileManagersController < OrbitAdminController
|
|||
parent = new_path.split('/')[0..-2].join('/')
|
||||
FileUtils.mkdir_p(parent)
|
||||
upload_records = get_uploads(relative_path)
|
||||
old_basename = File.basename(absolute_path)
|
||||
new_basename = File.basename(new_path)
|
||||
FileUtils.mv(absolute_path, new_path)
|
||||
Dir.glob(File.join(@root_path, "*_#{old_basename}")).each do |version_file|
|
||||
prefix = File.basename(version_file).sub(/_#{Regexp.escape(old_basename)}$/, '')
|
||||
FileUtils.mv(version_file, File.join(@root_path, "#{prefix}_#{new_basename}"))
|
||||
end
|
||||
upload_records.each{|r| r.update_path(new_relative_path)}
|
||||
render :body => nil, :status => 204
|
||||
end
|
||||
|
|
@ -442,6 +448,21 @@ class Admin::FileManagersController < OrbitAdminController
|
|||
entry = "#{file}#{is_file ? '': '/'}"
|
||||
file_relative_path = upload_item.path
|
||||
is_editable = @default_editable || check_editable(file_relative_path, @current_user_id)
|
||||
is_img = is_file && !(file.match(/\.(jpg|jpeg|gif|png|webp)$/i).nil?)
|
||||
thumb_url = nil
|
||||
if is_img
|
||||
thumb_absolute = File.join(File.dirname(real_path_absolute), "thumb_#{file}")
|
||||
unless File.exist?(thumb_absolute)
|
||||
begin
|
||||
image = MiniMagick::Image.open(real_path_absolute)
|
||||
image.resize "100x100"
|
||||
image.write(thumb_absolute)
|
||||
rescue => e
|
||||
Rails.logger.error("[file_manager] 產生縮圖失敗 #{real_path_absolute}: #{e.message}")
|
||||
end
|
||||
end
|
||||
thumb_url = thumb_absolute.sub('public', '') if File.exist?(thumb_absolute)
|
||||
end
|
||||
{
|
||||
module: upload_item.module,
|
||||
is_file: is_file,
|
||||
|
|
@ -452,7 +473,9 @@ class Admin::FileManagersController < OrbitAdminController
|
|||
entry: entry,
|
||||
absolute: real_path_absolute,
|
||||
is_editable: is_editable,
|
||||
id: (upload_item ? upload_item.id.to_s : nil)
|
||||
id: (upload_item ? upload_item.id.to_s : nil),
|
||||
is_img: is_img,
|
||||
thumb_url: thumb_url
|
||||
}
|
||||
end.compact
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,12 @@ class FileManagerTrash
|
|||
FileUtils.mkdir_p(trash_dir)
|
||||
upload = self.file_manager_upload
|
||||
if File.exist?(upload.get_real_path)
|
||||
original_dir = File.dirname(upload.get_real_path)
|
||||
original_basename = File.basename(upload.get_real_path)
|
||||
FileUtils.mv(upload.get_real_path, self.trash_path)
|
||||
Dir.glob(File.join(original_dir, "*_#{original_basename}")).each do |version_file|
|
||||
FileUtils.mv(version_file, File.join(trash_dir, File.basename(version_file)))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -72,7 +77,12 @@ class FileManagerTrash
|
|||
if File.exist?(self.trash_path)
|
||||
dir = File.dirname(self.path)
|
||||
FileUtils.mkdir_p(dir)
|
||||
own_trash_dir = File.dirname(self.trash_path)
|
||||
basename = File.basename(self.trash_path)
|
||||
FileUtils.mv(self.trash_path, self.path)
|
||||
Dir.glob(File.join(own_trash_dir, "*_#{basename}")).each do |version_file|
|
||||
FileUtils.mv(version_file, File.join(dir, File.basename(version_file)))
|
||||
end
|
||||
end
|
||||
self.file_manager_upload.update(:is_trash=>false) if self.file_manager_upload
|
||||
unless self.is_file
|
||||
|
|
@ -80,4 +90,4 @@ class FileManagerTrash
|
|||
end
|
||||
self.delete
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -169,4 +169,4 @@ class FileManagerUpload
|
|||
m.where(:id=>self.related_id).update_all(self.related_field => nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -44,7 +44,11 @@
|
|||
<% end %>
|
||||
<td class="name">
|
||||
<%= link_to "javascript:void(0)", class: entry[:type].to_s, data: {'entry'=>entry[:entry], 'id'=> entry[:id]} do %>
|
||||
<%= fa_icon (entry[:type] == :file ? 'file' : 'folder') %>
|
||||
<% if entry[:is_img] && entry[:thumb_url].present? %>
|
||||
<img src="<%= entry[:thumb_url] %>" class="file-thumb" style="width:30px;height:30px;object-fit:cover;" />
|
||||
<% else %>
|
||||
<%= fa_icon (entry[:type] == :file ? 'file' : 'folder') %>
|
||||
<% end %>
|
||||
<span class="filename"><%= entry[:entry] %></span>
|
||||
<% end %>
|
||||
</td>
|
||||
|
|
@ -149,4 +153,4 @@
|
|||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue