Class: WebSandboxConsole::HomeController

Inherits:
ApplicationController show all
Defined in:
app/controllers/web_sandbox_console/home_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#restrict_ip

Instance Method Details

#do_view_fileObject

查看文件



24
25
26
27
# File 'app/controllers/web_sandbox_console/home_controller.rb', line 24

def do_view_file
  @result_hash = ViewFile.new(params).view
  @tip_hash    = WebSandboxConsole::ViewFile::PageTips
end

#downloadObject

下载文件



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/web_sandbox_console/home_controller.rb', line 34

def download
  if params[:file_name].blank?
    flash[:notice] = "文件名不能为空"
    return redirect_to download_page_path
  end

  file_full_path = "#{Rails.root}/log/#{params[:file_name]}"
  unless File.exists?(file_full_path)
    flash[:notice] = '文件不存在,请检查文件名;或在其它服务器请多次尝试'
    return redirect_to download_page_path
  end

  # 打包
  `tar czf #{file_full_path}.tar.gz #{file_full_path}`
  # 如果是csv文件,需删除
  File.delete(file_full_path) if file_full_path.split(".").last == 'csv'

  send_file "#{file_full_path}.tar.gz"
end

#download_pageObject

下载文件页面



30
31
# File 'app/controllers/web_sandbox_console/home_controller.rb', line 30

def download_page
end

#eval_codeObject

执行代码



10
11
12
13
14
15
16
17
18
# File 'app/controllers/web_sandbox_console/home_controller.rb', line 10

def eval_code
  sandbox = Sandbox.new(params[:code], session[:pass_auth])

  @results = if params[:commit] == '异步执行'
    sandbox.asyn_evalotor
  else
    sandbox.evalotor
  end
end

#indexObject



6
7
# File 'app/controllers/web_sandbox_console/home_controller.rb', line 6

def index
end

#view_fileObject



20
21
# File 'app/controllers/web_sandbox_console/home_controller.rb', line 20

def view_file
end