Class: FileExplorer::IndexController

Inherits:
ApplicationController show all
Includes:
ActionView::Helpers::NumberHelper
Defined in:
app/controllers/file_explorer/index_controller.rb

Constant Summary collapse

BASE_DIRECTORY =
ENV['BASE_DIRECTORY'] || '.'

Instance Method Summary collapse

Instance Method Details

#deleteObject



32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/file_explorer/index_controller.rb', line 32

def delete
		absolute_path = check_path(params[:path])
		if File.directory?(absolute_path)
 FileUtils.rm_rf(absolute_path)
		else
 FileUtils.rm(absolute_path)
		end
		redirect_to request.referrer, notice: "DELETED!!  DELETED!!!"	
		head 204
end

#folder_createObject



43
44
45
46
47
48
49
50
# File 'app/controllers/file_explorer/index_controller.rb', line 43

def folder_create
  if Gem.win_platform?
       `mkdir #{params[:index].fetch(:name)}`
		else
 `sudo mkdir #{params[:index].fetch(:name)}`
		end
		redirect_to request.referrer, notice: "#{params[:index].fetch(:name)} FOLDER CREATED!"		
end

#indexObject



9
10
11
12
# File 'app/controllers/file_explorer/index_controller.rb', line 9

def index
		populate_directory(BASE_DIRECTORY, '')
		@absolute_path = BASE_DIRECTORY
end

#pathObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/file_explorer/index_controller.rb', line 14

def path
		absolute_path = check_path(params[:path])

		if File.directory?(absolute_path)
 populate_directory(absolute_path, "#{params[:path]}/")
 render :index
		elsif File.file?(absolute_path)
 if File.size(absolute_path) > 2500_000
#send_file absolute_path
redirect_to request.referrer, notice: "Not Loadable. . . Way to big!"
 else
@file = File.read(absolute_path)
render :file, formats: :html
 end
		end
end